Skip to content

fixMantissaOverflow should not round up #123

Description

@IvanSanchez

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions