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 小时
- 30 天内合并 PR
- 227
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 于 1 天前认领。 未关闭
sysprog21/codetrial#606 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Start does nothing visible in the lobby when site data is blocked可能已有人在做 @sidney-Hung 于 1 天前认领。 未关闭
sysprog21/codetrial#600 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Add a Copy results action to the coding test panel可能已有人在做 @seallllllllll 于 1 天前认领。 未关闭
sysprog21/codetrial#598 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Review history drops older reports that still fit可能已有人在做 @HellHBBD 于 1 天前认领。 未关闭
sysprog21/codetrial#596 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 sysprog21/codetrial 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
pop-os/cosmic-applets#1619 ·
维护者通常 3 天内回复
-
binding:python bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
coollabsio/orbit#72 ·
维护者通常 1 天内回复
-
swc_common: Mark::least_ancestor never returns when the answer is the root mark (ANT-2026-JYDQGGRT)未关闭
难度 2/5 1-3 小时 新手友好度 72/100
swc-project/swc-ai-issues#137 ·
-
Synth suite fails unless run from the repo root: signal_flow's default machine path is cwd-relative未关闭bug
难度 2/5 1-3 小时 新手友好度 80/100
Nimblesite/osprey#370 ·
维护者通常 1 天内回复