The current implementation of fixMantissaOverflow seems to always round up (when the first non-significant digit is 5), as noted on
|
expect(notation.format(34.5, 0)).toBe("35₀"); // Is the rounding right?? |
|
expect(notation.format(33.5, 0)).toBe("34₀"); // Is the rounding right?? |
I think it'd be better to implement the "round half to even" algorithm (see also the IEEE754 stuff about rounding).
In a nutshell:
A tie-breaking rule without positive/negative bias and without bias toward/away from zero is round half to even. By this convention, if the fractional part of x is 0.5, then y is the even integer nearest to x. Thus, for example, +23.5 becomes +24, as does +24.5; while −23.5 becomes −24, as does −24.5. This function minimizes the expected error when summing over rounded figures, even when the inputs are mostly positive or mostly negative.
The current implementation of
fixMantissaOverflowseems to always round up (when the first non-significant digit is 5), as noted onnotations/spec/infix/infix-eng.spec.js
Lines 14 to 15 in 3799032
I think it'd be better to implement the "round half to even" algorithm (see also the IEEE754 stuff about rounding).
In a nutshell: