MCPcopy Create free account
hub / github.com/antlr/codebuff / DoubleMath

Class DoubleMath

output/java_guava/1.4.17/DoubleMath.java:49–532  ·  view source on GitHub ↗

A class for arithmetic on doubles that is not covered by java.lang.Math. @author Louis Wasserman @since 11.0

Source from the content-addressed store, hash-verified

47
48
49@GwtCompatible(emulated = true)
50public final class DoubleMath {
51 /*
52 * This method returns a value y such that rounding y DOWN (towards zero) gives the same result as
53 * rounding x according to the specified mode.
54 */
55 @GwtIncompatible // #isMathematicalInteger, com.google.common.math.DoubleUtils
56 static double roundIntermediate(double x, RoundingMode mode) {
57 if (!isFinite(x)) {
58 throw new ArithmeticException("input is infinite or NaN");
59 }
60 switch (mode) {
61 case UNNECESSARY:
62 checkRoundingUnnecessary(isMathematicalInteger(x));
63 return x;
64 case FLOOR:
65 if (x >= 0.0 || isMathematicalInteger(x)) {
66 return x;
67 } else {
68 return x - 1.0;
69 }
70 case CEILING:
71 if (x <= 0.0 || isMathematicalInteger(x)) {
72 return x;
73 } else {
74 return x + 1.0;
75 }
76 case DOWN:
77 return x;
78 case UP:
79 if (isMathematicalInteger(x)) {
80 return x;
81 } else {
82 return x + Math.copySign(1.0, x);
83 }
84 case HALF_EVEN:
85 return rint(x);
86 case HALF_UP:
87 {
88 double z = rint(x);
89 if (abs(x - z) == 0.5) {
90 return x + copySign(0.5, x);
91 } else {
92 return z;
93 }
94 }
95 case HALF_DOWN:
96 {
97 double z = rint(x);
98 if (abs(x - z) == 0.5) {
99 return x;
100 } else {
101 return z;
102 }
103 }
104 default:
105 throw new AssertionError();
106 }

Callers

nothing calls this directly

Calls 1

logMethod · 0.80

Tested by

no test coverage detected