You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/12/02 09:52:37 UTC
[groovy] 01/02: Trivial refactoring: extract common variables
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 9d53f2a019275e5c34e0aa90ef7f680ab2429e3c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Dec 2 17:41:51 2019 +0800
Trivial refactoring: extract common variables
---
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);
}
/**