/** * Returns the largest power of 10 that is less than or equal to the * the specified positive value. * * @param d the <code>double</code> number. * @return <code>floor(Log10(abs(d)))</code> * @throws ArithmeticException if <code>d <= 0<code> or <code>d</code> * is <code>NaN</code> or <code>Infinity</code>. **/ public static int floorLog10(double d) { int guess = (int) (LOG2_DIV_LOG10 * MathLib.floorLog2(d)); double pow10 = MathLib.toDoublePow10(1, guess); if ((pow10 <= d) && (pow10 * 10 > d)) return guess; if (pow10 > d) return guess - 1; return guess + 1; }