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

Method log10

output/java_guava/1.4.16/LongMath.java:166–191  ·  view source on GitHub ↗

Returns the base-10 logarithm of x, rounded according to the specified rounding mode. @throws IllegalArgumentException if x <= 0 @throws ArithmeticException if mode is RoundingMode#UNNECESSARY and x is not a power of ten

(long x, RoundingMode mode)

Source from the content-addressed store, hash-verified

164 */
165
166 @GwtIncompatible // TODO
167 @SuppressWarnings("fallthrough")
168 // TODO(kevinb): remove after this warning is disabled globally
169 public static int log10(long x, RoundingMode mode) {
170 checkPositive("x", x);
171 int logFloor = log10Floor(x);
172 long floorPow = powersOf10[logFloor];
173 switch (mode) {
174 case UNNECESSARY:
175 checkRoundingUnnecessary(x == floorPow);
176 // fall through
177 case FLOOR:
178 case DOWN:
179 return logFloor;
180 case CEILING:
181 case UP:
182 return logFloor + lessThanBranchFree(floorPow, x);
183 case HALF_DOWN:
184 case HALF_UP:
185 case HALF_EVEN:
186 // sqrt(10) is irrational, so log10(x)-logFloor is never exactly 0.5
187 return logFloor + lessThanBranchFree(halfPowersOf10[logFloor], x);
188 default:
189 throw new AssertionError();
190 }
191 }
192
193 @GwtIncompatible // TODO
194 static int log10Floor(long x) {

Callers 1

log10Method · 0.95

Calls 4

log10FloorMethod · 0.95
lessThanBranchFreeMethod · 0.95
checkPositiveMethod · 0.45

Tested by

no test coverage detected