dotnet/runtime

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

Open

#1.643 aberto em 18 de abr. de 2019

Ver no GitHub
 (13 comments) (8 reactions) (1 assignee)C# (5.445 forks)batch import
Cost:Marea-System.Numericsbreaking-changebughelp wanted

Métricas do repositório

Stars
 (17.886 stars)
Métricas de merge de PR
 (Mesclagem média 12d 11h) (661 fundiu PRs em 30d)

Description

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.

Guia do colaborador