dotnet / dotnet/dotnet-api-docs
BitConverter: ToDouble, ToSingle, Int64BitsToDouble, Int32BitsToDouble
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
**Link to article:**
https://docs.microsoft.com/en-us/dotnet/api/system.bitconverter.todouble?view=netstandard-2.0
**Problem:**
Mention that it might not be possible to use these methods to produce what are so-called _signaling NaNs_ in x86, x64, and certain other instruction set architectures. A _signaling NaN_ is an NaN with the most significant bit of the mantissa area clear (as opposed to a _quiet NaN_ where that bit is set). An example of a signaling NaN is as follows (with little-endian byte ordering):
new byte[]{ 1, 0, 0, 0, 0, 0, 0xf0, 0x7f };
At least in x86, using ToDouble and converting the resulting `double` back will convert the signaling NaN to a quiet NaN as follows:
new byte[]{ 1, 0, 0, 0, 0, 0, 0xf8, 0x7f };
This can be an issue if the application works with binary serialization formats that store `double` or `float` values in the form of the bits that make them up, because converting those bits to `double` or `float` with these BitConverter methods may make round-tripping that `double` or `float` not always possible.
Contributor guide
Assessment
This issue has not been assessed yet.