Measuring only the mapping boundary and the rounding, nothing else
The template's <script> block was loaded into Node exactly as written (node:vm plus a minimal DOM stub) and its own conversion functions were called; no browser was opened. What gets measured here is narrow: which band a score lands in when it sits right on a boundary, whether that boundary is closed or open, whether the mapping is a lookup table or a formula, how far round-then-add drifts from add-then-round, and how the credit fields and invalid scores are tolerated. Every course name and grade below is fictional, and each conclusion only reports what this page's functions return for this exact set of inputs.
Boundary sweep: four probe points against every band floor k
The sweep calls gpOf one point at a time: for each threshold k, feed k−0.5, k−0.01, k, k+0.5 in turn and watch from which point the band flips. Across the scales the conclusion is identical: the switch happens exactly on the threshold integer, the lower bound is closed and the upper bound open.
| Scale | Threshold k | Low-side samples → gpOf return | Threshold sample → return |
|---|---|---|---|
| Segmented 4.0 scale | 90 | 89.5→3, 89.99→3 | 90→4 |
| Segmented 4.0 scale | 80, 70 | 79.99→2, 69.99→1 | 80→3, 70→2 |
| Segmented 4.0 scale | 60 | 59.99→0 | 60→1 |
| US 4.0 scale (ten bands) | 93, 63 | 92.99→3.7, 62.99→0 | 93→4, 63→1 |
| 4.3 scale | 97 | 96.99→4 | 97→4.3 |
| Custom 95/85/75/65 | 95, 65 | 94.5→3, 64.5→0 | 95→4, 65→1 |
| Linear 5.0 and curve 4.0 scales | 60 | 59.99→0 | 60→1 |
That 89.99 and 90 fall a whole band apart (3 versus 4) is not a defect; it is the closed-lower-bound definition itself. Both continuous scales jump vertically at 60: 59.99 is zeroed to 0 while 60 returns 1, and 60.01 comes back as 1.001 and 1.0014998125, which shows that past 60 the page runs a formula rather than a band. The entire ledger can be reproduced as is on the GPA calculator page.
Figure 1: the left column is the score fed into gpOf, the right column is what it returns; the band flips only on the threshold integer, never in between.
Implementation shape of the mapping: half lookup table, half formula
Reading the function bodies back as written: each segmented scale is a descending bands table scanned top-down for the first row whose lower bound x reaches or passes, with no interpolation branch anywhere — when 88.5 falls between bands it first fails against 90, then matches 80 and returns 3. The linear 5.0 scale is the formula (score−50)÷10 with an x<60 zero-out and a min(5) cap; the curve 4.0 scale is 4−3×(100−x)²÷1600 carrying the same zero-out at 60. Custom thresholds are re-sorted on the spot by gpCustomBands in descending score order, and an out-of-range or non-numeric threshold hits continue and vanishes in silence: type abc into threshold slot one and the maximum drops from 4 to 3 while the interface never says a single word.
Decimal places and rounding direction: two columns at two places, .5 carries toward positive infinity
The whole rounding body is one line, Math.round(x×m)/m, after which toFixed pads the places: round half up, .5 carries toward positive infinity, and trailing zeros are always kept. Places per column:
- per-course grade-point column and the credit-point column: two places;
- weighted average grade point: three places;
- credit-point total: two places;
- total credits and the maximum: one place;
- used percentage: one place.
Samples that sit on the fourth decimal expose the direction best: input 2.9995 at three places gives 3.000 (because 2.9995×1000 is exactly 2999.5, so it carries up), input 3.4995 at three places gives 3.500, input 2.675 at two places gives 2.68, and input 3.578125 at two places gives 3.58. Trailing-zero samples: input 4 displays 4.00 and input 0 displays 0.000, never trimmed away. On the negative side, -2.5 at zero places returns -2, so the carry is asymmetric, but the grade domain never reaches that region. The places fork is a separate ledger on the decimal format page.
Round-then-add versus add-then-round: 3.476 and 3.477, 0.001 apart
Internally the page accumulates totPoint from unrounded raw values, so the page adds first and rounds last. One constructed input: the curve 4.0 scale, three courses at 1 credit each, grades 85 / 82 / 83; the raw grade points are 3.578125, 3.3925 and 3.458125, and the page's weighted average shows 3.476. Take the displayed 3.58, 3.39 and 3.46 instead, round first and then add, and you get 10.43÷3=3.477. One input, two paths, 0.001 apart — the difference is created entirely by the order of the two operations.
Figure 2: two addition orders for the same three courses; add-then-round lands on 3.476 while round-then-add lands on 3.477.
The auto-search sample forks the same way: under the linear 5.0 scale, grades 60 and 62.22 at 1 credit each print 1.111 on the page, while doing round-then-add by hand gives 1.110. A segmented scale can never fork at all, because a single-course grade point carries at most one decimal there. The weighted-average convention gap can be checked against another input set on the weighted average calculator page.
The credit side and invalid scores: which branches warn, which stay silent
Take one fictional baseline record (a made-up course 礦巖採集實務, 2 credits at 80 on the segmented 4.0 scale) and edit only the credit field:
- 0 or blank: both hit the same not-counted-as-credit branch, no warning at all, and the row's grade point still prints — v1=3.000 with total credits 2.0, so the row feeds no weighted denominator yet still enters the simple average;
- -3 or a non-numeric character such as 兩: the whole row is removed, the notice reads, word for word, "the following did not take part in the calculation: the credits of Instrument Drafting are negative or not a number", and its grade is kicked out of every average as well;
- 1,5 (a full-width comma between the digits): gpNum silently reads 15 credits, total credits become 17.0 and v1=3.882, with no warning;
- every credit field at 0: the counted total is 0, and the result box hides itself entirely.
The score side forks further. An unrecognized grade gets the notice "the grade abc of Test Course cannot be recognized" — both the string 8.5.5 and a full-width 3 land in this same branch. An out-of-range grade gets "the grade -5.00 of Test Course is not within 0–100", and -5, 105 and 100.5 are all rejected outright rather than clamped. But 99.999 and 59.999, being inside 0–100, are silently used at their full value — and for the latter gpOf records 0.00 while the row label rounds to two places and displays 60.00, which manufactures an illusion number you then chase. 1e2 is read by Number as 100; a lowercase b+, an "A +" with a stray space, 85分, 優秀 and 掛科 are all silently normalized into the calculation; an empty or spaces-only row gets no warning and simply prints "—".
Three reconciliation questions
Q: Will extreme values crash the calculation?
They do not. Three courses at 1 credit each, all graded 100: v1=4.000 and used 100.0%. All zeros: 0.000, the stats bar reports "0-grade-point courses: 3 courses (occupying 3.0 credits)", and the per-course range prints 0.00 ~ 0.00. One course alone (3 credits at 87): 3.000, counted as one course, and no division by zero anywhere on the way.
Q: If I switch the scale halfway, must I retype the table?
No retyping, but the entire table is recomputed with no cache kept. The same sheet of 10 courses at 2 credits each with every grade 87: the segmented 4.0 scale outputs 3.000 (60.00÷20.0, used 75.0%); switching to the linear 5.0 scale outputs 3.700 (74.00÷20.0, maximum 5.0, used 74.0%). Same rows, two different answers, because the mapping itself changed.
Q: Why is my hand-computed average off by 0.001?
Because the page adds first and rounds last while you round first and add last — that is exactly the 3.476 versus 3.477 ledger above. Integer bands on a segmented scale cannot hit the fork; only the continuous scales expose it.