...
The Java language provides two primitive floating-point types, float
and double
, which are associated with the single-precision 32-bit and double-precision 64-bit format values and operations specified by IEEE 754 [IEEE 754]. Each of the floating-point types has a fixed, limited number of mantissa bits. Consequently, it is impossible to precisely represent any irrational number (for example, pi). Further, because these types use a binary mantissa, they cannot precisely represent many finite decimal numbers, such as 0.1, because these numbers have repeating binary representations.
...
When precise computation is unnecessary, floating-point representations may be used. In these cases, you must carefully and methodically estimate the maximum cumulative error of the computations to ensure that the resulting error is within acceptable tolerances. Consider using numerical analysis to properly understand the problem. See Goldberg's work for an introduction to this topic [Goldberg 1991].
Noncompliant Code Example
...
The use of floating-point is not recommended for performance reasons on Android.
Bibliography
Item 48. Avoid | |
Puzzle 2. Time for a change | |
| |
[IEEE 754] |
|
[JLS 2005] |
...
Rule 03: Numeric Types and Operations (NUM) NUM05-J. Do not use denormalized numbers