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

Method roundIntermediate

output/java_guava/1.4.19/DoubleMath.java:55–107  ·  view source on GitHub ↗
(double x, RoundingMode mode)

Source from the content-addressed store, hash-verified

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 }
107 }
108
109 /**
110 * Returns the {@code int} value that is equal to {@code x} rounded with the specified rounding

Callers 3

roundToIntMethod · 0.95
roundToLongMethod · 0.95
roundToBigIntegerMethod · 0.95

Calls 3

isMathematicalIntegerMethod · 0.95
isFiniteMethod · 0.45

Tested by

no test coverage detected