From 145cc675d35b677157eb6d3ef57c1104dd5142e2 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Fri, 17 Jan 2014 10:53:00 +0000 Subject: [PATCH] MATH-1089 Slightly simpler implementation. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1559067 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/math3/util/Precision.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/math3/util/Precision.java b/src/main/java/org/apache/commons/math3/util/Precision.java index 441e015ac..7b02c1677 100644 --- a/src/main/java/org/apache/commons/math3/util/Precision.java +++ b/src/main/java/org/apache/commons/math3/util/Precision.java @@ -60,6 +60,8 @@ public class Precision { private static final long SGN_MASK = 0x8000000000000000L; /** Offset to order signed double numbers lexicographically. */ private static final int SGN_MASK_FLOAT = 0x80000000; + /** Positive zero. */ + private static final double POSITIVE_ZERO = 0d; static { /* @@ -396,7 +398,7 @@ public class Precision { .setScale(scale, roundingMethod)) .doubleValue(); // MATH-1089: negative values rounded to zero should result in negative zero - return rounded == 0.0 ? rounded * FastMath.copySign(1d, x) : rounded; + return rounded == POSITIVE_ZERO ? POSITIVE_ZERO * x : rounded; } catch (NumberFormatException ex) { if (Double.isInfinite(x)) { return x;