groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 03/04: Trivial refactoring: extract common variables
Date Mon, 02 Dec 2019 10:39:17 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ebb56e169a900e4daf389413f44b0fced69f9b8b
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Mon Dec 2 17:41:51 2019 +0800

    Trivial refactoring: extract common variables
    
    (cherry picked from commit 9d53f2a019275e5c34e0aa90ef7f680ab2429e3c)
---
 src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 747570a..ea986f4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -16620,10 +16620,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @since 1.6.0
      */
     public static float trunc(Float number, int precision) {
+        final double p = Math.pow(10, precision);
+        final double n = number.doubleValue() * p;
         if (number < 0f) {
-            return (float)(Math.ceil(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
+            return (float) (Math.ceil(n) / p);
         }
-        return (float)(Math.floor(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
+        return (float) (Math.floor(n) / p);
     }
 
     /**


Mime
View raw message