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

Multiplying of float numbers produces inaccurate result, event when accurate result is possible

    XMLWordPrintable

Details

    • x86_64
    • windows_7

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_111"
      Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      float x = 2.1f * 2.55f;

      Expected result x = 5.355, precise number, clearly far away from any limit (min/max of float)
      Actual result x = 5.3549995 (?)

      if compared:
      2.1f * 2.55f > 5.3549995 => result: true (correct)
      2.1f * 2.55f > 5.3549996 => result: false (incorrect. 2.1*2.55=5.355 > 5.3549996)

      The same problem is also with double;


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      float x = 2.1f * 2.55f;

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected result x = 5.355, precise number, clearly far away from any limit (min/max of float)
      ACTUAL -
      Actual result x = 5.3549995 (?)
      if compared:
      2.1f * 2.55f > 5.3549995 => result: true (correct)
      2.1f * 2.55f > 5.3549996 => result: false (incorrect. 2.1*2.55=5.355 > 5.3549996)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      Attachments

        Activity

          People

            aroy Abhijit Roy (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: