4 ms·
Why do you return x-x for inf or nan? I can't test now, but I imagine they both return nan? I run a high performance math library in C#, and I'm always looking
by kolbe 4y ago
Why do you return x-x for inf or nan? I can't test now, but I imagine they both return nan?
I run a high performance math library in C#, and I'm always looking to improve.
https://github.com/matthewkolbe/LitMath https://github.com/matthewkolbe/LitMath
- jcranmer 4y agoUsing the expression ensures that the FP exceptions are properly set. It also does quieting of sNaN or NaN payload propagation as appropriate.
- hurrrrrrrr 4y agoIt's an easy way to return nan and set FE_INVALID. If you're not worried about floating point exceptions you can just return NaN directly. Idk how much C# even guarantees about the floating point operations and if it's applicable there. https://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions https://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions