You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/10/07 13:06:00 UTC
[jira] [Commented] (GROOVY-10786) Cannot call modulo operator (%) on BigDecimal/BigInteger types
[ https://issues.apache.org/jira/browse/GROOVY-10786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17614074#comment-17614074 ]
Eric Milles commented on GROOVY-10786:
--------------------------------------
{{BigInteger}} declares {{mod(BigInteger)}} method. "5g % 2" goes there, as does "new BigInteger(5) % 2" for me.
{{BigDecimal}} does not provide {{mod}} and {{BigDecimalMath}} does not provide {{modImpl}} probably for the same reasons.
> Cannot call modulo operator (%) on BigDecimal/BigInteger 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)