If I have a C# float
, can I convert it to double
without losing any precision?
If that double
were converted back to float
, would it have exactly the same value?
Yes. IEEE754 floating point (which is what C# must use) guarantees this:
Converting a float
to a double
preserves exactly the same value
Converting that double
back to a float
recovers exactly that original float
.
The set of double
s is a superset of float
s.
Note that this also applies to NaN
, +Infinity
, and -Infinity
. The signedness of zero is also preserved.