I was looking at std::numeric_limits<float>::min/max()
but it appears 'min()' returns the smallest absolute value, not the lowest value. Is it safe to use
-std::numeric_limits<float>::max()
, i.e is float symmetric in min/max limits?
Floating point numbers can be positive or negative.
Wiki says this about float : The minimum positive normal value is 2^−126 ≈ 1.18 × 10^−38 and the minimum positive (denormal) value is 2^−149 ≈ 1.4 × 10^−45.
The range of float values is 3.4e-38 to 3.4e+38. So the float variables should not store negative values.
IEEE 754 floating point numbers use a sign bit for signed-ness (rather than something like twos complement), so if you're sure that your compiler/platform uses that representation (very common) then you can use -std::numeric_limits<float>::max()
as you suspected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With