You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2010/09/30 20:03:59 UTC

DO NOT REPLY [Bug 50033] New: 'mod(13,12)' method in MathX should produce '1'

https://issues.apache.org/bugzilla/show_bug.cgi?id=50033

           Summary: 'mod(13,12)' method in MathX should produce '1'
           Product: POI
           Version: 3.7-dev
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: java@skow.org


Created an attachment (id=26106)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26106)
Patched MathX based on version 776505 (3.7b3)

The formula 'mod(13,12)' entered into Excel produces the answer of '1'.  POI is
evaluating 'mod(13,12)' to '0.9999999999999991'.

I have attached a patched version of MathX based on version 776505 which fixes
the problem.  Also attached is an updated TestMathX with the previously empty
'testMod' method filled in.  It still has some oddities when one or the other
values are negative (returning '0.6000000000000001' vs '0.6' for
'mod(-3.4,2.0)' for instance), but that was a pre-existing condition prior to
my change.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 50033] 'mod(13,12)' method in MathX should produce '1'

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50033

java@skow.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #26106|text/x-java                 |text/plain
          mime type|                            |
  Attachment #26106|0                           |1
           is patch|                            |

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 50033] 'mod(13,12)' method in MathX should produce '1'

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50033

Yegor Kozlov <ye...@dinom.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #2 from Yegor Kozlov <ye...@dinom.ru> 2010-10-01 08:04:02 EDT ---
Thanks for the patch, applied in r1003504

The fact that in some cases the results are slightly 'off' is normal, it is the
way floating-point arithmetic works. In particular, the value of 1.4 cannot be
represented as an exact value, on low-level it is a result of a truncated
series. A way to check it is via BigDecimal(1.4).toString() which returns
3.399999999999999911182158029987476766109466552734375. 


A smarter version of MathX.mod might use BigDecimal for calculations:

    public static double mod(double n, double d) {
        BigDecimal number = new BigDecimal(n);
        BigDecimal divisor = new BigDecimal(d);

        double result;

        if (d == 0) {
            result = Double.NaN;
        }
        else if (sign(n) == sign(d)) {
            result = number.remainder(divisor).doubleValue();
        }
        else {
            result =
number.remainder(divisor).add(divisor).remainder(divisor).doubleValue();
        }

        return result;
    }



In the case of MathX.mode this seems OK, but I'm reluctant to make this change.
Using BigDecimal for calculations should be project-wide.

Regards,
Yegor

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 50033] 'mod(13,12)' method in MathX should produce '1'

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50033

--- Comment #1 from java@skow.org 2010-09-30 14:04:42 EDT ---
Created an attachment (id=26107)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26107)
Test case which exposes the issue.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org