3 ms·
Choosing a tolerance is hard enough when you know the floating point model you're using, but it seems like an impossible task to try to support all possible flo
by slavik81 7y ago
Choosing a tolerance is hard enough when you know the floating point model you're using, but it seems like an impossible task to try to support all possible floating point hardware. I couldn't tell you what guarantees you have when __STDC_IEC_559__ remains undefined.
These days I write my floating point code assuming float is a 32-bit IEEE 754 floating point number, and double is 64-bit. You can get those guarantees on any desktop hardware with the right flags, and the same semantics are commonly available on other platforms too.
Picking a well-defined implementation makes it much easier to reason about conversions between integer and floating point types. In fact, it allows you to reason about a lot of operations, e.g. 1.0 + 2.0 == 3.0 is true; (float)183 == 183.0 is true; 0.1 == (double)0.1f is false; etc.