IEEE 754‐1985, Binary 64, Floating‐Point Examiner

Chris W. Johnson
2022‐10‐02

Imprecision is inevitable in numeric data types, because none can represent every possible number. It is especially common in floating‐point types, like IEEE 754, which are designed to preserve magnitude by sacrificing precision. (Conversely, integer data types preserve precision by sacrificing magnitude.) Loss of precision, for whatever reason, can have important and surprising effects, especially when people are unaware of the issue. Lack of that awareness is a common problem (even among computer programmers) in part because decimal representations of these numbers are pervasively created with the intent of hiding inaccuracies.

It is hoped this tool will aid understanding of the causes and effects of those issues.

The “IEEE 754‐1985, binary 64” format is a very common floating‐point format used by Java¹ to represent numbers in its double primitives and Double objects, and for all floating‐point calculations. By extension, any other languages executed in the Java Virtual Machine (JVM) will use it. It is also used by languages unrelated to Java and the JVM. Notably, C and C++ use it wherever it is the host CPU’s native representation (prime examples are Intel’s CPUs, so it is a very common case), JavaScript uses it for essentially all numbers, C# float and double types use it, Python uses it on most platforms, and so on.

TL;DR

Examine values 0.1 (⅒) and 0.125 (⅛). Observe the former is approximated, while the latter is exact. Why? 0.1 is not a power of two, while 0.125 is 2⁻³, and this numeric format’s values are quotients from divisions by 2⁵², multiplied by powers of two. (Hence the format’s “binary” designation.) Didn’t know all that? Don’t feel bad; most computer programmers don’t. Now, be one of the exceptions. (It’s important.)

ℹ️

Browser Compatibility

Portions of this page require MathML support. As of May, 2013, Firefox and Safari had MathML support, but Chrome did not (it was in version 24, but no other versions).

Footnotes

  1. Java Virtual Machine versions prior to 15 use IEEE 754‐1985. Versions 15 and above use IEEE 754‐2019, which changes neither the binary format, nor its interpretation, as examined here.
  2. In Java, for example, such values are obtained using “System.out.printf("0x%x", Double.doubleToLongBits(double));”.
Valid XHTML 1.0 Strict Valid CSS!