Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pomodoro-timer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class GradientProgressBar extends Widget {

const attrs = styleToCellAttrs(this._style);

const label = this._showLabel ? ` ${Math.round(this._value * 100)}%` : '';
const label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate files =="
fd -a 'index.tsx|devtools.ts' . | sed 's#^\./##'

echo "== relevant lines =="
sed -n '170,190p' examples/pomodoro-timer/src/index.tsx 2>/dev/null || true
sed -n '70,90p' packages/dev-server/src/devtools.ts 2>/dev/null || true

echo "== surrounding declarations/usages =="
rg -n "_showLabel|_value|fps:|Number\.EPSILON|0\.145|toFixed|Math\.round" examples/pomodoro-timer/src/index.tsx packages/dev-server/src/devtools.ts packages -g '*.{ts,tsx}' 2>/dev/null | head -200

echo "== JS numeric behavior probe =="
node - <<'JS'
const cases = [
  {name:'progress 0.145', value:0.145, scale:100},
  {name:'fps 14.5', value:14.5, scale:10},
  {name:'boundary around .5', value:0.5, scale:1},
  {name:'negative scaled .5', value:-0.5, scale:10},
];
for (const c of cases) {
  const scaled = c.value * c.scale;
  const current = Math.round(c.value * c.scale * 100 + Number.EPSILON) / 100;
  const naive = Math.round(scaled + Number.EPSILON);
  const magnitudeAware = Math.round(scaled + Number.EPSILON * Math.max(1, Math.abs(scaled)));
  const epsilonBefore = Math.round((c.value + Number.EPSILON) * c.scale);
  console.log(JSON.stringify({
    name:c.name, scaled, current, naive, magnitudeAware, epsilonBefore,
  }));
}

console.log({
  exact0145Scaled: 0.145*100,
  eps: Number.EPSILON,
  roundScalesEps: Math.round(0.145*100 + Number.EPSILON),
  roundScalesEpsTimes100: Math.round(0.145*100 + Number.EPSILON) / 100,
});
JS

Repository: Karanjot786/TermUI

Length of output: 22481


Use a magnitude-aware epsilon in both rounding paths.

Add epsilon relative to the scaled operand so the fix covers floating-point rounding errors across the full numeric range.

  • examples/pomodoro-timer/src/index.tsx#L185: Round this._value * 100 with a scaled epsilon before rendering the percent label.
  • packages/dev-server/src/devtools.ts#L81: Round fps * 10 with the same scaled epsilon pattern.
📍 Affects 2 files
  • examples/pomodoro-timer/src/index.tsx#L185-L185 (this comment)
  • packages/dev-server/src/devtools.ts#L81-L81
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/pomodoro-timer/src/index.tsx` at line 185, Update the percent-label
rounding in examples/pomodoro-timer/src/index.tsx at lines 185-185 to add
Number.EPSILON scaled relative to this._value * 100 before Math.round; apply the
same magnitude-aware epsilon pattern to the fps * 10 rounding in
packages/dev-server/src/devtools.ts at lines 81-81.

const barWidth = Math.max(0, width - label.length);
const filled = this._value <= 0 ? 0 : Math.round(barWidth * this._value);
const empty = barWidth - filled;
Expand Down
2 changes: 1 addition & 1 deletion examples/weather/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function fetchWeather() {
}
}

setInterval(fetchWeather, 5000);
clearInterval(window.__interval); window.__interval = setInterval(fetchWeather, 5000);
fetchWeather();

// Gauge does not expose a public setColor() method, so dynamic color
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-server/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DevTools {
renderTimeMs: timeMs,
widgetCount,
lastRenderAt: now,
fps: Math.round(fps * 10) / 10,
fps: Math.round(fps * 10 + Number.EPSILON) / 10,
memoryMB: Math.round((process.memoryUsage?.().heapUsed ?? 0) / 1024 / 1024 * 10) / 10,
};
}
Expand Down
Loading