Skip to content

math: consider adding IEEE TiesToEven rounding to math package #21748

@mpx

Description

@mpx

IEEE 754-2008 specifies 5 rounding-direction attributes with 4 implemented by the math package:

  • roundTiesToEven: RoundTiesToEven (proposed) (was Rint)
  • roundTiesToAway: Round
  • roundTowardPositive: Ceil
  • roundTowardNegative: Floor
  • roundTowardZero: Trunc

No other rounding-attributes are specified by IEEE 754. There have been various proposals in the past requesting highly configurable esoteric rounding modes beyond IEEE. I don't believe they should be considered for the math package.

I'd suggest using the following signature: func RoundTiesToEven(float64) float64

Most people generally prefer TiesToAway for common usage (hence #20100). However TiesToEven has statistical properties that are preferable for some applications. Implementations of IEEE 754 are required to provide TiesToEven.

For comparison, other languages provide support for TiesToEven:

  • C99: rint
  • Java: Math.rint
  • Python v3 (not v2): round

Pro:

  • Statistically useful for some applications.
  • Easy to implement incorrectly with many subtle edge-cases. A reliable stdlib implementation prevents bugs.
  • Required for IEEE 754. It's the only mode not supported by the math package and would complete IEEE rounding support.
  • math package is the most appropriate location for TiesToEven support since all the other modes are in math.

Con:

  • +1 function to math package API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions