<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">This reference: <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types" class="">https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types</a><div class="">details that in the Microsoft .NET C# environment, the numeric double type is an 8-byte representation, and offers about 16 digits of precision.</div><div class=""><br class=""></div><div class="">In my experience, in those specific cases where numeric precision needs to be carefully dealt with, the solution is not to round the results of a calculation; rather the solution is to look at where two double values are being compared for equality, and replacing the comparison</div><div class=""><br class=""></div><div class="">if ( a==b) { .... }</div><div class=""><br class=""></div><div class="">with </div><div class="">if ( abs(a-b) < tolerance ) { ... }</div><div class=""><br class=""></div><div class="">and choosing a value of tolerance is can be something like</div><div class=""><br class=""></div><div class="">double tolerance = 1.0e-15 * Math.Max( abs(a), abs(b))</div><div class=""><br class=""></div><div class="">Vince Marchetti</div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 21, 2021, at 1:04 AM, Konstantin Smirnov <<a href="mailto:konstantin.e.smirnov@gmail.com" class="">konstantin.e.smirnov@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">Hi<div dir="auto" class="">When adding double numbers in .cs script, must we think about every digit accuracy, or it's approximate numbers, so we can treat them as approximate with e-7, or so? 15? </div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Can we do calc and round afterwards? </div></div>
_______________________________________________<br class="">x3d-public mailing list<br class=""><a href="mailto:x3d-public@web3d.org" class="">x3d-public@web3d.org</a><br class="">http://web3d.org/mailman/listinfo/x3d-public_web3d.org<br class=""></div></blockquote></div><br class=""></div></body></html>