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

Possibly invisible loss of precision can cause endless loops

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: sgC58550 Date: 03/17/97


      I do think the compiler should warn when int (long) ist
      implicitely converted to float (double). I got an endless
      loop which was not so easy to find. Basically the following
      code shows what happens:

      class Test {
          public static void main(String argv[]) {
              int i;
              float j=1;
              for(i=0;i<33554432;i+=j)
                  if (i % 1000000 == 0) System.out.print(i);
          }
      }

      With today's computation power and memory sizes a loop of
      this proportion is not so unlikely. The ultra I use arrives
      at the problematic point in less than a minute.
      Considering that the only "error" in the above is the
      declaration of j as int, I consider this "feature" to be
      dangerous. If someone wants to conserve memory such an use
      of a float is not so unlikely. As this problem is possibly
      not found in a test-run (small values) but will cause trouble
      when it counts (large values), I belive an appropriate warning
      or even a required cast should be added.

      Best Regards
      Arno Wagner
      (Dipl. Inform.)


      company - Univesity of Karlsruhe, Dept. of Informatics , email - ###@###.###
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                sgoodsunw Sheri Good (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: