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

[jira] [Updated] (GROOVY-3478) Patch: Automatic type promotion for numbers

     [ https://issues.apache.org/jira/browse/GROOVY-3478?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-3478:
------------------------------
    Summary: Patch: Automatic type promotion for numbers  (was: Patch: Dynamic type promotion)

> Patch: Automatic type promotion for numbers
> -------------------------------------------
>
>                 Key: GROOVY-3478
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3478
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-runtime
>         Environment: N/A
>            Reporter: Olov Lassus
>            Priority: Major
>             Fix For: 4.x
>
>         Attachments: groovy_dynamic_type_promotion.patch
>
>
> {noformat}
> groovy:000> 1000 * 1000000000
> ===> 1000000000000
> {noformat}
> More info in mail thread http://www.nabble.com/Patch:-Dynamic-type-promotion-td22976282.html
> Patch attached. Diffstat:
> {noformat}
> main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java        |   23 -
> main/org/codehaus/groovy/runtime/InvokerHelper.java               |   20 -
> main/org/codehaus/groovy/runtime/typehandling/BigIntegerMath.java |   26 +
> main/org/codehaus/groovy/runtime/typehandling/IntegerMath.java    |   70 ++++
> main/org/codehaus/groovy/runtime/typehandling/LongMath.java       |   85 ++++--
> main/org/codehaus/groovy/runtime/typehandling/NumberMath.java     |   90 ++++--
> test/groovy/operator/IntegerOperatorsTest.groovy                  |  141 +++++++++-
> 7 files changed, 369 insertions(+), 86 deletions(-)
> {noformat}
> I'll also keep an updated patch available at http://dl.getdropbox.com/u/283098/patches/groovy_dynamic_type_promotion.patch
> Here's an overview of the patch:
> * Added test cases to IntegerOperatorsTest.groovy
> * Modified NumberMath toBigInteger and toBigDecimal methods to call into DefaultGroovyMethods versions
> * Modified IntegerMath to support dynamic type promotion for abs, add, subtract, multiply, unary minus and left shift.
> * Modified BigIntegerMath to support left shift and right shift. It does not support unsigned right shift (>>>).
> * Modified LongMath to support dynamic type promotion for abs, add, subtract, multiply, unary minus and left shift. Also changed a few "new Long" to "Long.valueOf" since it can be faster.
> * Modified DefaultGroovyMethods.abs to call into NumberMath. Optimized toBigInteger so that it doesn't do unnecessary string conversions. Tweaked a few comments.
> * Modified InvokerHelper.unaryMinus. Tweaked some valueOf.
> * Modified semantics for the shift operators. It's now type coerced/promoted the same as other binary operators. Negative shifts are not allowed.



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