...
Because this operation is imprecise, this code produces the following output when run in FP-strict mode:
Code Block |
---|
Original : 0.33333334 Denormalized : 2.8E-45 Restored : 0.4 |
Compliant Solution
Do not use code that could use denormalized numbers. When calculations using float
produce denormalized numbers, use of double
can provide sufficient precision.
Code Block | ||
---|---|---|
| ||
double x = 1/3.0; System.out.println("Original : " + x); x = x * 7e-45; System.out.println("DenormalizedNormalized: " + x); x = x / 7e-45; System.out.println("Restored : " + x); |
This code produces the following output in FP-strict mode:
Code Block |
---|
Original : 0.3333333333333333 Denormalized Normalized: 2.333333333333333E-45 Restored : 0.3333333333333333 |
Exceptions
...