/** Get the closest int to x. * @param x number from which closest int is requested * @return closest int to x */ public static int round(final float x) { return (int) floor(x + 0.5f); }
/** {@inheritDoc} */ @Override public double value(double d) { return FastMath.floor(d); } };
/** Get the closest long to x. * @param x number from which closest long is requested * @return closest long to x */ public static long round(double x) { return (long) floor(x + 0.5); }
/** {@inheritDoc} */ @Override public RealVector mapFloorToSelf() { for (int i = 0; i < data.length; i++) { data[i] = FastMath.floor(data[i]); } return this; }
/** Get the smallest whole number larger than x. * @param x number from which ceil is requested * @return a double number c such that c is an integer c - 1.0 < x <= c */ public static double ceil(double x) { double y; if (x != x) { // NaN return x; } y = floor(x); if (y == x) { return y; } y += 1.0; if (y == 0) { return x*y; } return y; }
/** * Normalize an angle in a 2&pi wide interval around a center value. * <p>This method has three main uses:</p> * <ul> * <li>normalize an angle between 0 and 2π:<br/> * <code>a = MathUtils.normalizeAngle(a, FastMath.PI);</code></li> * <li>normalize an angle between -π and +π<br/> * <code>a = MathUtils.normalizeAngle(a, 0.0);</code></li> * <li>compute the angle between two defining angular positions:<br> * <code>angle = MathUtils.normalizeAngle(end, start) - start;</code></li> * </ul> * <p>Note that due to numerical accuracy and since π cannot be represented * exactly, the result interval is <em>closed</em>, it cannot be half-closed * as would be more satisfactory in a purely mathematical view.</p> * @param a angle to normalize * @param center center of the desired 2π interval for the result * @return a-2kπ with integer k and center-π <= a-2kπ <= center+π * @since 1.2 */ public static double normalizeAngle(double a, double center) { return a - TWO_PI * FastMath.floor((a + FastMath.PI - center) / TWO_PI); }
/** Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers. * @param x number from which nearest whole number is requested * @return a double number r such that r is an integer r - 0.5 <= x <= r + 0.5 */ public static double rint(double x) { double y = floor(x); double d = x - y; if (d > 0.5) { if (y == -1.0) { return -0.0; // Preserve sign of operand } return y+1.0; } if (d < 0.5) { return y; } /* half way, round to even */ long z = (long) y; return (z & 1) == 0 ? y : y + 1.0; }
/** * For a random variable X whose values are distributed according * to this distribution, this method returns P(x0 ≤ X ≤ x1). * * @param x0 the (inclusive) lower bound * @param x1 the (inclusive) upper bound * @return the probability that a random variable with this distribution * will take a value between <code>x0</code> and <code>x1</code>, * including the endpoints. * @throws MathException if the cumulative probability can not be * computed due to convergence or other numerical errors. * @throws IllegalArgumentException if <code>x0 > x1</code> */ @Override public double cumulativeProbability(double x0, double x1) throws MathException { if (x0 > x1) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1); } if (FastMath.floor(x0) < x0) { return cumulativeProbability(((int) FastMath.floor(x0)) + 1, (int) FastMath.floor(x1)); // don't want to count mass below x0 } else { // x0 is mathematical integer, so use as is return cumulativeProbability((int) FastMath.floor(x0), (int) FastMath.floor(x1)); } }
/** * For a random variable X whose values are distributed according * to this distribution, this method returns P(X = x). In other words, this * method represents the probability mass function, or PMF, for the distribution. * <p> * If <code>x</code> does not represent an integer value, 0 is returned. * * @param x the value at which the probability density function is evaluated * @return the value of the probability density function at x */ public double probability(double x) { double fl = FastMath.floor(x); if (fl == x) { return this.probability((int) x); } else { return 0; } }
/** * For a random variable X whose values are distributed according * to this distribution, this method returns P(X ≤ x). In other words, * this method represents the (cumulative) distribution function, or * CDF, for this distribution. * <p> * If <code>x</code> does not represent an integer value, the CDF is * evaluated at the greatest integer less than x. * * @param x the value at which the distribution function is evaluated. * @return cumulative probability that a random variable with this * distribution takes a value less than or equal to <code>x</code> * @throws MathException if the cumulative probability can not be * computed due to convergence or other numerical errors. */ public double cumulativeProbability(double x) throws MathException { return cumulativeProbability((int) FastMath.floor(x)); }
case BigDecimal.ROUND_CEILING : if (sign == -1) { unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY)); } else { unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY)); unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY)); break; case BigDecimal.ROUND_FLOOR : unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY)); } else { unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY)); double fraction = unscaled - FastMath.floor(unscaled); if (fraction > 0.5) { unscaled = FastMath.ceil(unscaled); } else { unscaled = FastMath.floor(unscaled); double fraction = unscaled - FastMath.floor(unscaled); if (fraction > 0.5) { unscaled = FastMath.ceil(unscaled); } else if (fraction < 0.5) { unscaled = FastMath.floor(unscaled); } else { if (FastMath.floor(unscaled) / 2.0 == FastMath.floor(Math .floor(unscaled) / 2.0)) { // even
if (z < 15.0) { double z2 = 2.0 * z; if (FastMath.floor(z2) == z2) { ret = EXACT_STIRLING_ERRORS[(int) z2]; } else {
final RecurrenceCoefficientsGenerator generator) { final int maxDegree = (int) FastMath.floor(FastMath.sqrt(2 * coefficients.size())) - 1; synchronized (PolynomialsUtils.class) { if (degree > maxDegree) {
return FastMath.floor(result + 0.5);
return factorial(n); return FastMath.floor(FastMath.exp(factorialLog(n)) + 0.5);
double fpos = FastMath.floor(pos); int intPos = (int) fpos; double dif = pos - fpos;
int targetIter = FastMath.max(1, FastMath.min(sequence.length - 2, (int) FastMath.floor(0.5 - 0.6 * log10R)));