Java floor floor10(double a)

Here you can find the source of floor10(double a)

Description

Returns the largest (closest to positive infinity) double value that is a power of 10 not greater than the argument.

License

BSD License

Parameter

Parameter Description
a a number greater than 0.0

Return

the largest double value that is a power of 10 not greater than the argument

Declaration

public static double floor10(double a) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /** Natural log of 10, used in {@code log10} function. */
    public static final double L10 = Math.log(10.0);

    /**// w  ww. j a  v  a  2s  . c  o  m
     * Returns the largest (closest to positive infinity) double value
     * that is a power of 10 not greater than the argument.  Special
     * cases:
     * <ul>
     *   <li>If the argument value is already equal to a power of 10,
     *   then the result is the same as the argument.</li>
     *   <li>If the argument is NaN or an infinity or positive zero or
     *   negative zero, then the result is the same as the
     *   argument.</li>
     * </ul>
     *
     * @param a a number greater than 0.0
     * @return the largest double value that is a power of 10 not
     * greater than the argument
     */
    public static double floor10(double a) {
        return Math.pow(10, Math.floor(log10(a)));
    }

    /**
     * Raises first argument to the power of the second argument.
     *
     * @param x value to raise
     * @param y amount to raise to
     * @return <code>x<sup>y</sup></code>
     */
    public static float pow(float x, int y) {
        float val = 1.0f;
        for (int i = 0; i < Math.abs(y); i++) {
            val *= x;
        }
        if (y < 0) {
            return 1.0f / val;
        }
        return val;
    }

    /**
     * Returns the log base 10 of <code>a</code> double value.
     *
     * @param a a number greater than 0.0
     * @return the value {@code log<sub>10</sub>(a)}
     */
    public static double log10(double a) {
        return Math.log(a) / L10;
    }
}

Related

  1. floor(int number, int divisor)
  2. floor(int x, int quantum)
  3. floor(Integer a)
  4. Floor(Object in, int val)
  5. floor(String input)
  6. floor1e5(double coordinate)
  7. floor2(int a, int preserveDigits)
  8. floor_double(double a)
  9. floor_double(double value)