Skip to content

specify rounding rule for JSON-encoded floats #376

@d-v-b

Description

@d-v-b

the JSON encoding for floats states that rounding must be used for imprecisely declared values:

- A JSON number, that will be rounded to the nearest representable value.

However, this rounding scheme ("round to the nearest representable value") doesn't define how ties should be handled, i.e. when there are 2 nearest representable values. Therefore this part of the spec is incomplete.

It seems that the IEEE 754 default rounding mode is "round ties to even", which picks the candidate value with the nearest even digit. I don't have access to the IEEE 754 spec but every resource I could find online seems to agree that this rounding mode is the default.

I propose adding a statement to the spec clarifying that ties should be handled according to the "round ties to even" rounding mode. In practice I don't think this change would affect implementations -- I assume everyone is already using the same default rounding mode. But it would make the interpretation of imprecise fill values completely specified, which would be helpful for other parts of the ecosystem that refer to the fill value encoding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions