[x3d-public] Using c# with graphics

vmarchetti at kshell.com vmarchetti at kshell.com
Tue Sep 21 03:39:46 PDT 2021


This reference: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types <https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types>
details that in the Microsoft .NET C# environment, the numeric double type is an 8-byte representation, and offers about 16 digits of precision.

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

if ( a==b) { .... }

with 
if ( abs(a-b) < tolerance ) { ... }

and choosing a value of tolerance is can be something like

double tolerance = 1.0e-15 * Math.Max( abs(a), abs(b))

Vince Marchetti


> On Sep 21, 2021, at 1:04 AM, Konstantin Smirnov <konstantin.e.smirnov at gmail.com> wrote:
> 
> Hi
> 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? 
> 
> Can we do calc and round afterwards? 
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20210921/0cc0f44d/attachment.html>


More information about the x3d-public mailing list