Here you can find the source of ceily(double a, double precision)
double
value that is not less than the argument and is equal for at least a precision value.
Math.ceil(a/precision)*precision
.
public static double ceily(double a, double precision)
//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 ⌈a/precision⌉*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>⌈㏒<sub>10</sub> a⌉</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); } }