Topic
  • 9 replies
  • Latest Post - ‏2019-01-24T15:28:29Z by WSmith
Hai_Quach
Hai_Quach
3 Posts

Pinned topic IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

‏2018-08-16T17:48:56Z | bigdecimal java8 mathcontext

Hi,

Recently, I just upgrade from WAS8.5.5-java6 to WAS9.0-java8. I've experienced an issue of BigDecimal.add method. Below is my unit test code

MathContext context = MathContext.DECIMAL64;
BigDecimal p = BigDecimal.valueOf(0.05);
BigDecimal result = p.divide(BigDecimal.valueOf(12), context);
System.out.println(BigDecimal.ONE.add(result, context));

It will print out as 1.000000000000000 instead of 1.004166666666666667. It worked just fine with WAS8.5.5 and java 6. Why does it cause the issue in java8? 

 

Thanks,

Updated on 2018-08-16T18:36:25Z at 2018-08-16T18:36:25Z by Hai_Quach
  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-05T09:39:54Z  

    could you give the java -version for the environment where you see this problem?

  • Hai_Quach
    Hai_Quach
    3 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-05T13:52:02Z  
    • WSmith
    • ‏2018-09-05T09:39:54Z

    could you give the java -version for the environment where you see this problem?

    Here is an example of java version.

    java version "1.8.0"
    Java(TM) SE Runtime Environment (build pwa6480sr3-20160428_01(SR3))
    IBM J9 VM (build 2.8, JRE 1.8.0 Windows 7 amd64-64 Compressed References 20160427_301573 (JIT enabled, AOT enabled)
    J9VM - R28_Java8_SR3_20160427_1620_B301573
    JIT  - tr.r14.java.green_20160329_114288
    GC   - R28_Java8_SR3_20160427_1620_B301573_CMPRSS
    J9CL - 20160427_301573)
    JCL - 20160421_01 based on Oracle jdk8u91-b14

  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-10T14:25:03Z  

    Issue recreated on IBM SDK for Java 8.0.5.7. The unexpected result is only seen when running with JIT on; with -Xint the expected result is seen. Still looking at this.

  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-10T15:10:07Z  
    • WSmith
    • ‏2018-09-10T14:25:03Z

    Issue recreated on IBM SDK for Java 8.0.5.7. The unexpected result is only seen when running with JIT on; with -Xint the expected result is seen. Still looking at this.

    With IBM SDK for Java 8.0.5.21 (current latest) the result is 1.000000000000000 with or without -Xint.

  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-10T15:16:10Z  
    • WSmith
    • ‏2018-09-10T15:10:07Z

    With IBM SDK for Java 8.0.5.21 (current latest) the result is 1.000000000000000 with or without -Xint.

    If I add an extra println to access the result before adding 1 to (0.05 / 12) then the problem goes away. I'll open a problem report for this.

  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-10T15:33:24Z  
    • WSmith
    • ‏2018-09-10T15:16:10Z

    If I add an extra println to access the result before adding 1 to (0.05 / 12) then the problem goes away. I'll open a problem report for this.

    internal Problem Report 139223 opened. I'll update again when we have something that can be tracked outside of IBM.

  • Hai_Quach
    Hai_Quach
    3 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2018-09-10T17:57:45Z  
    • WSmith
    • ‏2018-09-10T15:33:24Z

    internal Problem Report 139223 opened. I'll update again when we have something that can be tracked outside of IBM.

    It is similar to 

    https://bugs.java.com/view_bug.do?bug_id=6362557

    If calling precision method before doing add, the issue is gone.

  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2019-01-24T10:47:35Z  
    • WSmith
    • ‏2018-09-10T15:33:24Z

    internal Problem Report 139223 opened. I'll update again when we have something that can be tracked outside of IBM.

    chased this internal problem report again today.

  • WSmith
    WSmith
    14 Posts

    Re: IBK JDK 8 BIGDECIMAL.ADD() GIVES UNEXPECTED RESULTS

    ‏2019-01-24T15:28:29Z  
    • WSmith
    • ‏2019-01-24T10:47:35Z

    chased this internal problem report again today.

    this is expected to be fixed in the next release, I'll follow it up then