JDK-6378503 : In java.math.BigDecimal, division by one returns zero
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2006-01-30
  • Updated: 2013-09-09
  • Resolved: 2013-08-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b106Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.11-6mdk #1 Tue Mar 22 16:04:32 CET 2005 i686 Intel(R) Pentium(R) 4 CPU 2.26GHz unknown GNU/Linux


A DESCRIPTION OF THE PROBLEM :
Dividing ONE with a very high negative scale, by ONE return ZERO

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
(new BigDecimal(BigInteger.ONE, Integer.MIN_VALUE)).divideToIntegralValue(BigDecimal.ONE)


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1E+2147483648
ACTUAL -
0E+2147483648

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.math.*;
public class BugDivide{
    public static void main(String[] args){

        System.out.println((new BigDecimal(BigInteger.ONE, Integer.MIN_VALUE)).divideToIntegralValue(BigDecimal.ONE));
    }
}
---------- END SOURCE ----------

Comments
This test reproduces the same problem but is less computationally expensive to evaluate. It obtains the result 0E+65536 whereas 1E+65536 is expected. public class JDK6378503 { public static void main(String[] args) { int unscaledValue = 1; int numeratorScale = Integer.MIN_VALUE; int denominatorScale = -(Integer.MAX_VALUE & 0x7fff0000); BigDecimal big = BigDecimal.valueOf(unscaledValue, numeratorScale); BigDecimal small = BigDecimal.valueOf(unscaledValue, denominatorScale); System.out.println(String.format("Integral value of %s / %s? Expecting 1E%d", big, small, denominatorScale - numeratorScale)); BigDecimal result = big.divideToIntegralValue(small); System.out.println("Obtained: " + result); } }
25-07-2013

EVALUATION Should be fixed.
30-01-2006