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/calculator/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class CalculatorApp extends Widget {
}

private evaluate() {
if (this.expression.trim() === "") return;
if (this.expression.trim().length === 0) return;
const oldExpr = this.expression;
this.result = safeEval(this.expression);
if (this.result !== null && !this.result.startsWith("Error")) {
Expand Down
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

printf 'Relevant file locations and lines:\n'
fd -a 'index.tsx|devtools.ts' . | sed 's#^\./##' | while read -r f; do
  case "$f" in
    examples/pomodoro-timer/src/index.tsx|packages/dev-server/src/devtools.ts)
      echo "== $f =="
      nl -ba "$f" | sed -n '75,90p;175,192p'
      ;;
  esac
done

printf '\nSearch for Number.EPSILON usage:\n'
rg -n "Number\.EPSILON|FPS|_value|fps" examples/pomodoro-timer/src/index.tsx packages/dev-server/src/devtools.ts || true

printf '\nBehavioral probe for edge/floating cases:\n'
node - <<'JS'
const inputs = {
  percentage: [0.2929999999999997, 0.293, 0.9940000000000002],
  fps: [14.144999999999997, 14.145, 14.144000000000002],
};
for (const [name, values] of Object.entries(inputs)) {
  console.log(name);
  for (const v of values) {
    let out;
    if (name === 'percentage') {
      out = {current: Math.round(v * 100 + Number.EPSILON), proposed: Math.round((v + Number.EPSILON) * 100)};
    } else {
      out = {current: Math.round(v * 10 + Number.EPSILON) / 10, proposed: Math.round((v + Number.EPSILON) * 10) / 10};
    }
    console.log(`${v} -> current ${out.current}, proposed ${out.proposed}`);
  }
}
JS

Repository: Karanjot786/TermUI

Length of output: 1818


Use a deterministic rounding helper instead of adding Number.EPSILON after scaling.

Both expressions multiply the value, add one unscaled epsilon, then round. That works at the tested boundary values, but unscaled Number.EPSILON is too small to correct errors after scaling is applied. A deterministic 2 decimal-places formatter/rounding helper is clearer and avoids similar edge-case rounding mistakes.

📍 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, Replace the
scaled-value-plus-Number.EPSILON rounding at
examples/pomodoro-timer/src/index.tsx:185 and
packages/dev-server/src/devtools.ts:81 with a shared deterministic
two-decimal-place rounding/formatting helper; update the label calculation in
the visible label expression and the corresponding sibling expression,
preserving percentage output while avoiding unscaled epsilon arithmetic.

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 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