Calculator % disagrees with // on negative operands
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
Observed behavior
The task workspace calculator floors // but truncates %, so the two operators contradict each other when an operand is negative. No error is shown: the result is a wrong number. docs/task-mode.md tells learners to use this calculator rather than another app or tab during a timed attempt, so they have no other tool to catch it.
term() in web/calculator.js uses Math.floor(value / unary()) for // at line 129 and the JavaScript remainder value %= unary() at line 131. JavaScript's % takes the sign of the dividend, so it pairs with truncating division, not floored division. The identity a == (a // b) * b + a % b therefore fails whenever the operands have opposite signs. tests/browser/calculator.test.js covers only 17 // 5 and 17 % 5, so nothing exercises this case. docs/task-mode.md lists both operators without saying what they do with a negative operand.
Expected behavior
// and % should agree, so that a == (a // b) * b + a % b holds for every sign combination.
Approaches:
- Make
%floored, so the result takes the sign of the divisor.//keeps its behavior, and the pair matches Python, whose syntax//and**already follow. - Make
//truncate instead. This matches JavaScript's%, but changes an operator whose floor is deliberate and makes//differ fromfloor(a / b). - Keep both and document the difference. This changes no code, but leaves the identity broken.
I propose approach 1, and I will send the pull request once the scope is agreed here.
Acceptance criteria:
a == (a // b) * b + a % bholds for every sign combination, and the table under Reproduction gives its expected column.- Results for non-negative operands do not change.
- A zero divisor is still refused with the existing error.
tests/browser/calculator.test.jscovers both operators with negative operands, and fails without the fix.docs/task-mode.mdstates what%does with a negative operand.
Reproduction
- Open the calculator in the task workspace (
web/task.html). - Enter an expression from the table below.
- Press
=and compare the result.
| Expression | Actual | Expected from floored division |
|---|---|---|
-7 // 3 |
-3 | -3 |
-7 % 3 |
-1 | 2 |
(-7 // 3) * 3 + (-7 % 3) |
-10 | -7 |
7 // -3 |
-3 | -3 |
7 % -3 |
1 | -2 |
CodeTrial version
codetrial 0.1.0 (4de45b1)
Environment
OS: Ubuntu 24.04.5 LTS on WSL2 (Windows 11)
Browser: Chrome
Sanitized evidence
Captured at 4de45b1 by driving the calculator form in web/task.html with Playwright. The task section was unhidden by script, since starting a session needs Gemini and LiveKit. The form, its submit handler, and the evaluator were not changed. The files named in this report are unchanged through af66541.
Public data confirmation
- I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.
- 主要言語
- Rust
- スター
- 223
- フォーク
- 148
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 227
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sysprog21/codetrial のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sysprog21/codetrial#604 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Compare code semantically across a force push in review bundles対応中かも @Alan52254 が今日担当しました。 オープン
sysprog21/codetrial#606 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Start does nothing visible in the lobby when site data is blocked対応中かも @sidney-Hung が今日担当しました。 オープン
sysprog21/codetrial#600 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Add a Copy results action to the coding test panel対応中かも @seallllllllll が今日担当しました。 オープン
sysprog21/codetrial#598 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Review history drops older reports that still fit対応中かも @HellHBBD が今日担当しました。 オープン
sysprog21/codetrial#596 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
sysprog21/codetrial の issue をすべて見る
似ている issue
-
multiple issues priority: low
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
storytold/pdfcraft#6469 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
parity priority: low ui
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
storytold/photocraft#11680 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
triage/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
praxis-proxy/grid#564 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
ScoopInstaller/Extras#19275 ·
メンテナーはふだん 1 日以内に返信