When casting double infinity to float and vice versa, will it still be infinity? Is it the same with NaN?
Converting any float to a double is guaranteed to preserve the value. Converting a double to float is guaranteed to preserve the value if the original value is representable as float.
If your system conforms to IEEE-754, then float is able to represent infinity and NaN. Otherwise, you can use <numeric_limits>
to check whether that is the case. The payload of a double NaN is not necessarily representable by a float NaN.
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