Skip to content

Commit

Permalink
Update data-rep-float
Browse files Browse the repository at this point in the history
  • Loading branch information
Huxpro committed Oct 4, 2020
1 parent 40a490e commit b1d823b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion _posts/data_rep/2020-06-21-data-rep-float.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,41 @@ instead of the sign bit for NaN quiteness/signalness:
I guess it might be something related to the CPU pipeline? I don't know yet.


### Equality of NaNs and Zeros.

The spec defined a comparison with NaNs to return an **unordered result**, that
means any comparison operation except `!=`, i.e. `>=, <=, >, <, =` between a
NaN and any other floating-point number would return `false`.

No surprised that most (if not every) language implemented such behaviours, e.g.
in JavaScript:

```js
NaN !== NaN // true
NaN === NaN // false
NaN > 1 // false
NaN < 1 // false
```

Position and negative zeros, however, are defined to be equal!

```js
+0 === -0 // true, using the traditional JS equality
Object.is(+0, -0) // false, using the "SameValue" equality
```

In Cpp, we can tell them apart by looking at its sign bit:

```cpp
#include <cmath> // signbit

cout << (+0.0f == -0.0f); // 1
cout << std::signbit(-0.0f); // 1
cout << std::signbit(+0.0f); // 0
```




IEEE-754 64-bits Double-Precision Floats
----------------------------------------
Expand Down Expand Up @@ -292,4 +327,4 @@ References
----------

- <https://en.wikipedia.org/wiki/Floating-point_arithmetic>
- <https://www3.ntu.edu.sg/home/ehchua/programming/java/datarepresentation.html>
- <https://www3.ntu.edu.sg/home/ehchua/programming/java/datarepresentation.html>

0 comments on commit b1d823b

Please sign in to comment.