Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8225646

Float and Double Division by Zero throws no Exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 12.0.1
    • core-libs
    • x86_64
    • linux

      A DESCRIPTION OF THE PROBLEM :
      The major Problem is, that "double" and "float" knows infinity and act in every time. So the handling does not recognize the concept in Math of a division by zero. This is not expected for developer and an expected Exception isn't thrown. -Infinity and Infinity means counts over an casting limitation of possible numbers. But a division by zero is not infinite and means an infinity stepcount of calculations.


              //hidden for the compiler
              System.out.println(Float.valueOf("100") / Float.valueOf("0") * 1);

              //Several IDE's yells , but returns infinity
              System.out.println((float) 100 / (float) 0 * 10);
              System.out.println((double) 100 / (double) 0 * 10);

              //drop an java.lang.ArithmeticException: / by zero
              System.out.println((int) 100 / (int) 0 * 10);


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: