Calculator % disagrees with // on negative operands
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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.
- Vorherrschende Sprache
- Rust
- Sterne
- 223
- Forks
- 148
- Ø Merge
- 1 T. 4 Std.
- Gemergte PRs (30 T.)
- 223
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus sysprog21/codetrial
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
Show recorded scores in past attempt rowsEvtl. vergeben @liehcheng hat das vor 1 Tag übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
sysprog21/codetrial#604 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Remind the candidate when they speak while the microphone is mutedEvtl. vergeben @gino1203 hat das heute übernommen. Offen
sysprog21/codetrial#627 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
The peer lobby stays on "Checking account..." when an invite link is opened with site data blockedEvtl. vergeben @dges5202 hat das heute übernommen. Offen
sysprog21/codetrial#626 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add basic shape tools to the example drawing areaEvtl. vergeben @Chuyutseng hat das heute übernommen. Offen
sysprog21/codetrial#625 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in sysprog21/codetrial
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
madesroches/fontaine#513 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area:ui needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
bherbruck/solvecraft#13497 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
needs-triage tooling
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
neilsh/stunt-reel#317 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
storytold/craft-fonts#65 ·
Maintainer antworten meist innerhalb von 2 Tagen