You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Kenneth Gendron (Jira)" <ji...@apache.org> on 2020/01/01 11:52:00 UTC

[jira] [Commented] (GROOVY-8948) BigDecimal to primtive conversion not working

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

Kenneth Gendron commented on GROOVY-8948:
-----------------------------------------

It actually works dynamically; however, if you compile statically it will not.  Sorry for not mentioning that earlier.

 
{code:java}
class Foo {
    void foo() {
        Math.ceil(1/2);
    }
}
{code}
 

When running *groovyc --compile-static* on it, it fails:

 
{noformat}
Foo.groovy: 3: [Static type checking] - Cannot find matching method java.lang.Math#ceil(java.math.BigDecimal). Please check if the declared type is correct and if the method exists.
 @ line 3, column 9.
         Math.ceil(1/2);
         ^
1 error
{noformat}
 

> BigDecimal to primtive conversion not working
> ---------------------------------------------
>
>                 Key: GROOVY-8948
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8948
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.5.5
>            Reporter: Kenneth Gendron
>            Priority: Minor
>
> The following code will not compile with Groovy:
> {code:java}
> Math.ceil(1/2){code}
> Groovy insists that it try to find Math.ceil(BigDecimal), as opposed to performing the conversion to a double.  The following will work though:
> {code:java}
> Math.ceil((double)1/2){code}
> But the above should not be necessary as Groovy should unbox it.
> Incidentally, this did work with version 2.4.12 and below.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)