Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed denormalized to normalized in the compliant solution because the values in this example are in normalized form.

...

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
bgColor#ccccff
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

...