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)
| 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) { |
no test coverage detected