Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
class WideSample {
  public static void main(String[] args) {
    int big = 1234567890;
                
    float approx = big;
    
    // The significand can store at most 23 bits
    if(Integer.highestOneBit(big) > Math.pow(2, 23)) { 
      throw new ArithmeticException("Insufficient precision");	
    }

    float approx = big;
    System.out.println(big - (int)approx);  //always prints zero now
  }
}

...