I am wondering if Java uses the IEEE 754 standard to implement floating point arithmetic.
IEEE-754 defines standards for several floating point types. For many years they were all binary floating point; that Java float and double : float is a 32-bit IEEE-754 floating point binary value (which is a standard binary32 call). double is 64-bit (which is a standard binary64 call). These binary floating-point numbers are very effective for computing computers, but since they work in binary mode and we work in decimal, there are some inconsistencies in expectations; for example, 0.1 cannot be stored exactly in double , and you get oddities like 0.1 + 0.2 , turn out to be 0.30000000000000004 . See Is floating point math considered? . For example, they are not a good choice for financial settlements.
BigDecimal is a Java class that implements a decimal floating point. This is much slower than using double , but the results are in line with our ten millionth expectations (for example, 0.1 + 0.2 will be 0.3 ).
The 2008 release of IEEE-754 added important new formats, in particular decimal32 , decimal64 and decimal128 . This is a decimal floating point, and therefore they work the same way as we do. 0.1 can be precisely stored in decimal64 . 0.1 + 0.2 is 0.3 in decimal64 . However, as far as I can tell, they are not relevant to your question.
Since BigDecimal precedes IEEE-754 2008 (individually), it defines its own semantics.
And if not, what's the point of using the IEEE 754 standard in the Math class?
JDK9 adds new operations to Math that do things defined by the IEEE-754 2008 specification (e.g. fma , which makes fused multiply-add ), so for clarity, it defines these operations with reference to the IEEE-754 2008 specification.
Additional Information:
Tj crowder
source share