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

Paul King commented on GROOVY-7129:
-----------------------------------

Looking at the implementation of {{DGM.power(Integer self, Integer exponent)}} 
and {{DGM.power(Long self, Integer exponent)}} they both keep the result in the 
original self type if possible but otherwise promote to BigInteger. This 
differs from {{DGM.power(Number self, Number exponent)}} which fits to the 
smallest fitting type, so:

(2 ** 30).getClass() // => Integer
(2L ** 30).getClass() // => Long
(2L ** 30.0).getClass() // => Integer
(2 ** 31).getClass() // => BigInteger
(2 ** 31.0).getClass() // => Long

So, there's obviously an inconsistency.


> Exponent integer classes differ
> -------------------------------
>
>                 Key: GROOVY-7129
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7129
>             Project: Groovy
>          Issue Type: Bug
>         Environment: Mac OSX 10.10, Groovy 2.3.7, JVM 1.8.0_20
>            Reporter: Rick Briganti
>            Priority: Minor
>         Attachments: FooTest.groovy
>
>
> Exponent math returns a different class type for the value compared to using 
> .getClass() on the normal number.
> This appears to occur when raising 2 to exponents between 31 and 62.
> {noformat}
> groovy:000> 2147483648.getClass()
> ===> class java.lang.Long
> groovy:000> (2 ** 31).getClass()
> ===> class java.math.BigInteger
> {noformat}
> Test case attached.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to