Test this with code:
[Fact] public void IsFloatRoundTrippableToDouble() { var bits = default(FloatUnion); bits.FloatData = float.MinValue; var testBits = default(FloatUnion);
This code checks each float value between MinValue and MaxValue (except NaN , infinity, etc.). The representation of bytes in memory is compared to ensure that no other conversions occur.
Although it might seem crazy to test the number of possible ~ 4 billion floating point numbers, it actually works for about 11 seconds on my machine.
And yes, the conversion is safe. Converting from float, double, and then back will not lose any information.
source share