[ 
https://issues.apache.org/jira/browse/GROOVY-10786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17625430#comment-17625430
 ] 

Paul King commented on GROOVY-10786:
------------------------------------

One thing which I noticed is that for BigInteger, we should also be using 
remainder and not mod.
{code:java}
def nums = [-10, -10L, -10f, -10d, -10G, -10.0G]
assert nums.collect{ it % 3 } == [-1, -1, -1f, -1d, 2G, -1.0G]
{code}
I'll create a separate issue for that breaking change (for negative numbers).

> Cannot call modulo operator (%) on BigDecimal types
> ---------------------------------------------------
>
>                 Key: GROOVY-10786
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10786
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Val E
>            Priority: Minor
>
>  
> 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: 5.5_
>     _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)

Reply via email to