Skip to content

Instantly share code, notes, and snippets.

@IgnoredAmbience
Last active May 24, 2016 08:49
Show Gist options
  • Save IgnoredAmbience/a7b53c4592f023b17b7e1be4955a249f to your computer and use it in GitHub Desktop.
Save IgnoredAmbience/a7b53c4592f023b17b7e1be4955a249f to your computer and use it in GitHub Desktop.
NaN or A-Different-NaN, that is the question?

6.1.6 The Number Type

...

The Number type has exactly 18437736874454810627 (that is, 264−253+3) values, representing the double-precision 64-bit format IEEE 754-2008 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic, except that the 9007199254740990 (that is, 253−2) distinct “Not-a-Number” values of the IEEE Standard are represented in ECMAScript as a single special NaN value. (Note that the NaN value is produced by the program expression NaN.) In some implementations, external code might be able to detect a difference between various Not-a-Number values, but such behaviour is implementation-dependent; to ECMAScript code, all NaN values are indistinguishable from each other.

NOTE The bit pattern that might be observed in an ArrayBuffer (see 24.1) after a Number value has been stored into it is not necessarily the same as the internal representation of that Number value used by the ECMAScript implementation.

...

24.1 ArrayBuffer Objects

24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian )

  1. If type is "Float32", then

  2. Let value be the byte elements of rawValue concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2008 binary32 value.

  3. If value is an IEEE 754-2008 binary32 NaN value, return the NaN Number value.

  4. Return the Number value that corresponds to value.

  5. If type is "Float64", then

  6. Let value be the byte elements of rawValue concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2008 binary64 value.

  7. If value is an IEEE 754-2008 binary64 NaN value, return the NaN Number value.

  8. Return the Number value that corresponds to value.

24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isLittleEndian )

  1. If type is "Float32", then

  2. Set rawBytes to a List containing the 4 bytes that are the result of converting value to IEEE 754-2008 binary32 format using “Round to nearest, ties to even” rounding mode. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.

  3. Else, if type is "Float64", then

  4. Set rawBytes to a List containing the 8 bytes that are the IEEE 754-2008 binary64 format encoding of value. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment