dotnet / dotnet/dotnet-api-docs

BitConverter: ToDouble, ToSingle, Int64BitsToDouble, Int32BitsToDouble

Open
#2,977 3 comments 0 reactions 0 assignees View on GitHub
area-System.Runtime Pri3 untriaged
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.