You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Val E (Jira)" <ji...@apache.org> on 2022/10/05 14:25:00 UTC

[jira] [Created] (GROOVY-10786) Cannot call modulo operator (%) on BigDecimal/BigInteger types

Val E created GROOVY-10786:
------------------------------

             Summary: Cannot call modulo operator (%) on BigDecimal/BigInteger types
                 Key: GROOVY-10786
                 URL: https://issues.apache.org/jira/browse/GROOVY-10786
             Project: Groovy
          Issue Type: Bug
            Reporter: Val E


 

It looks like _org.codehaus.groovy.runtime.typehandling.BigDecimalMath_ does not override the default mod() method from the abstract _org.codehaus.groovy.runtime.typehandling.NumberMath_
{code:java}
new BigInteger(5)%2 //ERROR
new BigDecimal(5.5)%2 //ERROR
5.5%2 //ERROR
new Double(5.5)%2 //OK
new Integer(5)%2 //OK
5%2 //OK
{code}
 

_Caused by: java.lang.UnsupportedOperationException: Cannot use mod() on this number type: java.math.BigDecimal with value: 2.0_
    _at org.codehaus.groovy.runtime.typehandling.NumberMath.createUnsupportedException(NumberMath.java:316)_
    _at org.codehaus.groovy.runtime.typehandling.NumberMath.modImpl(NumberMath.java:296)_
    _at org.codehaus.groovy.runtime.typehandling.NumberMath.mod(NumberMath.java:88)_
    _at org.codehaus.groovy.runtime.DefaultGroovyMethods.mod(DefaultGroovyMethods.java:16201)_

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)