dotnet/runtime

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

已關閉

#1,643 建立於 2019年4月18日

 (13 則留言) (8 個反應) (1 位負責人)C# (5,445 個分叉)batch import
Cost:Marea-System.Numericsbreaking-changebughelp wanted

倉庫指標

星標
 (17,886 顆星)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

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.

貢獻者指南