Skip to content

Math.Round(value, digits, mode) does not return the correct result #1643

Description

@tannergooding

The Math.Round(value, digits, mode) code returns a close, but not correct result most of the time.

The root problem is that the algorithm tries to follow normal mathematical rules to produce the result. However, due to the variable precision in IEEE floating-point numbers, this ultimately causes it to produce a close, but generally incorrect result most of the time and causes it to not accept inputs above a certain range. For example, you can't round double.MaxValue and the larger the input is, the more inaccurate the rounding will be.

These functions should be rewritten to be IEEE compliant and to accept any valid finite floating-point input.

Metadata

Metadata

Assignees

Labels

Cost:MWork that requires one engineer up to 2 weeksarea-System.Numericsbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.bughelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions