I am new to Rust and loving it. I recently hit a bug in c++ using acos where rounding errors made a calculation slightly larger than 1 which would return NaN from acos causing failures later on. It took a while to track down and fix, and I thought “I bet Rust would have prevented that error by having acos return a Result”. When I looked however the std acos in rust returns NaN instead of a Result.
I am curious what the reasoning was for Rust to return NaN instead of Result for cases such as this or getting the sqrt of a negative number. Is it for performance reasons? Or just a result of directly wrapping the standard C library? I was also hoping there might be a crate that safely wraps them, but couldn’t find one. Does a crate exist that returns Results for standard math functions?