mirror of
https://github.com/apache/commons-math.git
synced 2025-02-06 10:09:26 +00:00
MATH-1089
Slightly simpler implementation. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1559067 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e91d0f0510
commit
145cc675d3
@ -60,6 +60,8 @@ public class Precision {
|
|||||||
private static final long SGN_MASK = 0x8000000000000000L;
|
private static final long SGN_MASK = 0x8000000000000000L;
|
||||||
/** Offset to order signed double numbers lexicographically. */
|
/** Offset to order signed double numbers lexicographically. */
|
||||||
private static final int SGN_MASK_FLOAT = 0x80000000;
|
private static final int SGN_MASK_FLOAT = 0x80000000;
|
||||||
|
/** Positive zero. */
|
||||||
|
private static final double POSITIVE_ZERO = 0d;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
/*
|
/*
|
||||||
@ -396,7 +398,7 @@ public class Precision {
|
|||||||
.setScale(scale, roundingMethod))
|
.setScale(scale, roundingMethod))
|
||||||
.doubleValue();
|
.doubleValue();
|
||||||
// MATH-1089: negative values rounded to zero should result in negative zero
|
// 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) {
|
} catch (NumberFormatException ex) {
|
||||||
if (Double.isInfinite(x)) {
|
if (Double.isInfinite(x)) {
|
||||||
return x;
|
return x;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user