Java Ceil ceily(double a, double precision)

Here you can find the source of ceily(double a, double precision)

Description

Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal for at least a precision value.

License

Open Source License

Return

⌈a/precision⌉*precision = Math.ceil(a/precision)*precision.

Declaration

public static double ceily(double a, double precision) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from www  .  j  av  a2 s . c o m
     * The default tolerance for two numbers to be treated equal.
     * (experimental)
     * @see #setDefaultTolerance(double)
     * @invariants DefaultTolerance ≥ 0
     */
    private static double DefaultTolerance = .00000000001;

    /**
     * Returns the smallest (closest to negative infinity)
     * <code>double</code> value that is not less than the argument and
     * is equal for at least a precision value.
     * @return &lceil;a/precision&rceil;*precision = <code>Math.ceil(a/precision)*precision</code>.
     * @see #floory(double, double)
     */
    public static double ceily(double a, double precision) {
        return Math.ceil(a / precision) * precision;
    }

    public static double ceily(double a) {
        return ceily(a, precisionFor(a));
    }

    /**
     * Get the precision for a given a specified tolerance relative to the magnitude of a.
     * <p>
     * Roughly gives the precision for tolerance percent of a, but adjusted to decimal digits.
     * </p>
     * @return tolerance * 10<sup>&lceil;&#13266;<sub>10</sub> a&rceil;</sup>.
     */
    public static double precisionFor(double a, double tolerance) {
        return tolerance * Math.pow(10, Math.ceil(Math.log(a) / Math.log(10)));
    }

    /**
     * Get the precision for a default tolerance relative to the magnitude of a.
     */
    public static double precisionFor(double a) {
        return precisionFor(a, DefaultTolerance);
    }
}

Related

  1. ceilSec(long milli)
  2. ceilToBase(int number, int base)
  3. ceilToPowerOfTwo(float value)
  4. ceilToQuarterMs(float f)
  5. ceilU(final float value)