Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: gave exact math answer to NCCE

...

In this noncompliant code example, a value of type int is converted to the type float. Because type float has only 23 mantissa bits, the result of subtracting the original from this value is non -46, not zero.

Code Block
bgColor#FFcccc
class WideSample {
  public static void main(String[] args) {
    int big = 1234567890;
    float approx = big;

    // This is expected to be zero but it prints -46
    System.out.println(big - (int)approx);  
  }
}

...