Using the expression ensures that the FP exceptions are properly set. It also does quieting of sNaN or NaN payload propagation as appropriate.
Re:Cosine Implementation in C
by hurrrrrrrr on Friday March 31, 2023 @10:55AM
(#35388051)
It'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
I run a high performance math library in C#, and I'm always looking to improve.
https://github.com/matthewkolbe/LitMath