jaroslav@67: /*
jaroslav@67: * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
jaroslav@67: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@67: *
jaroslav@67: * This code is free software; you can redistribute it and/or modify it
jaroslav@67: * under the terms of the GNU General Public License version 2 only, as
jaroslav@67: * published by the Free Software Foundation. Oracle designates this
jaroslav@67: * particular file as subject to the "Classpath" exception as provided
jaroslav@67: * by Oracle in the LICENSE file that accompanied this code.
jaroslav@67: *
jaroslav@67: * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@67: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@67: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jaroslav@67: * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@67: * accompanied this code).
jaroslav@67: *
jaroslav@67: * You should have received a copy of the GNU General Public License version
jaroslav@67: * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@67: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@67: *
jaroslav@67: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@67: * or visit www.oracle.com if you need additional information or have any
jaroslav@67: * questions.
jaroslav@67: */
jaroslav@67:
jaroslav@67: package java.lang;
jaroslav@67:
jaroslav@104: import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@104:
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * The class {@code Math} contains methods for performing basic
jaroslav@67: * numeric operations such as the elementary exponential, logarithm,
jaroslav@67: * square root, and trigonometric functions.
jaroslav@67: *
jaroslav@67: *
Unlike some of the numeric methods of class
jaroslav@67: * {@code StrictMath}, all implementations of the equivalent
jaroslav@67: * functions of class {@code Math} are not defined to return the
jaroslav@67: * bit-for-bit same results. This relaxation permits
jaroslav@67: * better-performing implementations where strict reproducibility is
jaroslav@67: * not required.
jaroslav@67: *
jaroslav@67: *
By default many of the {@code Math} methods simply call
jaroslav@67: * the equivalent method in {@code StrictMath} for their
jaroslav@67: * implementation. Code generators are encouraged to use
jaroslav@67: * platform-specific native libraries or microprocessor instructions,
jaroslav@67: * where available, to provide higher-performance implementations of
jaroslav@67: * {@code Math} methods. Such higher-performance
jaroslav@67: * implementations still must conform to the specification for
jaroslav@67: * {@code Math}.
jaroslav@67: *
jaroslav@67: *
The quality of implementation specifications concern two
jaroslav@67: * properties, accuracy of the returned result and monotonicity of the
jaroslav@67: * method. Accuracy of the floating-point {@code Math} methods
jaroslav@67: * is measured in terms of ulps, units in the last place. For
jaroslav@67: * a given floating-point format, an ulp of a specific real number
jaroslav@67: * value is the distance between the two floating-point values
jaroslav@67: * bracketing that numerical value. When discussing the accuracy of a
jaroslav@67: * method as a whole rather than at a specific argument, the number of
jaroslav@67: * ulps cited is for the worst-case error at any argument. If a
jaroslav@67: * method always has an error less than 0.5 ulps, the method always
jaroslav@67: * returns the floating-point number nearest the exact result; such a
jaroslav@67: * method is correctly rounded. A correctly rounded method is
jaroslav@67: * generally the best a floating-point approximation can be; however,
jaroslav@67: * it is impractical for many floating-point methods to be correctly
jaroslav@67: * rounded. Instead, for the {@code Math} class, a larger error
jaroslav@67: * bound of 1 or 2 ulps is allowed for certain methods. Informally,
jaroslav@67: * with a 1 ulp error bound, when the exact result is a representable
jaroslav@67: * number, the exact result should be returned as the computed result;
jaroslav@67: * otherwise, either of the two floating-point values which bracket
jaroslav@67: * the exact result may be returned. For exact results large in
jaroslav@67: * magnitude, one of the endpoints of the bracket may be infinite.
jaroslav@67: * Besides accuracy at individual arguments, maintaining proper
jaroslav@67: * relations between the method at different arguments is also
jaroslav@67: * important. Therefore, most methods with more than 0.5 ulp errors
jaroslav@67: * are required to be semi-monotonic: whenever the mathematical
jaroslav@67: * function is non-decreasing, so is the floating-point approximation,
jaroslav@67: * likewise, whenever the mathematical function is non-increasing, so
jaroslav@67: * is the floating-point approximation. Not all approximations that
jaroslav@67: * have 1 ulp accuracy will automatically meet the monotonicity
jaroslav@67: * requirements.
jaroslav@67: *
jaroslav@67: * @author unascribed
jaroslav@67: * @author Joseph D. Darcy
jaroslav@67: * @since JDK1.0
jaroslav@67: */
jaroslav@67:
jaroslav@67: public final class Math {
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Don't let anyone instantiate this class.
jaroslav@67: */
jaroslav@67: private Math() {}
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * The {@code double} value that is closer than any other to
jaroslav@67: * e, the base of the natural logarithms.
jaroslav@67: */
jaroslav@67: public static final double E = 2.7182818284590452354;
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * The {@code double} value that is closer than any other to
jaroslav@67: * pi, the ratio of the circumference of a circle to its
jaroslav@67: * diameter.
jaroslav@67: */
jaroslav@67: public static final double PI = 3.14159265358979323846;
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the trigonometric sine of an angle. Special cases:
jaroslav@67: *
- If the argument is NaN or an infinity, then the
jaroslav@67: * result is NaN.
jaroslav@67: *
- If the argument is zero, then the result is a zero with the
jaroslav@67: * same sign as the argument.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a an angle, in radians.
jaroslav@67: * @return the sine of the argument.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.sin(a);")
jaroslav@67: public static double sin(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the trigonometric cosine of an angle. Special cases:
jaroslav@67: *
- If the argument is NaN or an infinity, then the
jaroslav@67: * result is NaN.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a an angle, in radians.
jaroslav@67: * @return the cosine of the argument.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.cos(a);")
jaroslav@67: public static double cos(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the trigonometric tangent of an angle. Special cases:
jaroslav@67: *
- If the argument is NaN or an infinity, then the result
jaroslav@67: * is NaN.
jaroslav@67: *
- If the argument is zero, then the result is a zero with the
jaroslav@67: * same sign as the argument.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a an angle, in radians.
jaroslav@67: * @return the tangent of the argument.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.tan(a);")
jaroslav@67: public static double tan(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the arc sine of a value; the returned angle is in the
jaroslav@67: * range -pi/2 through pi/2. Special cases:
jaroslav@67: *
- If the argument is NaN or its absolute value is greater
jaroslav@67: * than 1, then the result is NaN.
jaroslav@67: *
- If the argument is zero, then the result is a zero with the
jaroslav@67: * same sign as the argument.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a the value whose arc sine is to be returned.
jaroslav@67: * @return the arc sine of the argument.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.asin(a);")
jaroslav@67: public static double asin(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the arc cosine of a value; the returned angle is in the
jaroslav@67: * range 0.0 through pi. Special case:
jaroslav@67: *
- If the argument is NaN or its absolute value is greater
jaroslav@67: * than 1, then the result is NaN.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a the value whose arc cosine is to be returned.
jaroslav@67: * @return the arc cosine of the argument.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.acos(a);")
jaroslav@67: public static double acos(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the arc tangent of a value; the returned angle is in the
jaroslav@67: * range -pi/2 through pi/2. Special cases:
jaroslav@67: *
- If the argument is NaN, then the result is NaN.
jaroslav@67: *
- If the argument is zero, then the result is a zero with the
jaroslav@67: * same sign as the argument.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a the value whose arc tangent is to be returned.
jaroslav@67: * @return the arc tangent of the argument.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.atan(a);")
jaroslav@67: public static double atan(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Converts an angle measured in degrees to an approximately
jaroslav@67: * equivalent angle measured in radians. The conversion from
jaroslav@67: * degrees to radians is generally inexact.
jaroslav@67: *
jaroslav@67: * @param angdeg an angle, in degrees
jaroslav@67: * @return the measurement of the angle {@code angdeg}
jaroslav@67: * in radians.
jaroslav@67: * @since 1.2
jaroslav@67: */
jaroslav@67: public static double toRadians(double angdeg) {
jaroslav@67: return angdeg / 180.0 * PI;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Converts an angle measured in radians to an approximately
jaroslav@67: * equivalent angle measured in degrees. The conversion from
jaroslav@67: * radians to degrees is generally inexact; users should
jaroslav@67: * not expect {@code cos(toRadians(90.0))} to exactly
jaroslav@67: * equal {@code 0.0}.
jaroslav@67: *
jaroslav@67: * @param angrad an angle, in radians
jaroslav@67: * @return the measurement of the angle {@code angrad}
jaroslav@67: * in degrees.
jaroslav@67: * @since 1.2
jaroslav@67: */
jaroslav@67: public static double toDegrees(double angrad) {
jaroslav@67: return angrad * 180.0 / PI;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns Euler's number e raised to the power of a
jaroslav@67: * {@code double} value. Special cases:
jaroslav@67: *
- If the argument is NaN, the result is NaN.
jaroslav@67: *
- If the argument is positive infinity, then the result is
jaroslav@67: * positive infinity.
jaroslav@67: *
- If the argument is negative infinity, then the result is
jaroslav@67: * positive zero.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a the exponent to raise e to.
jaroslav@67: * @return the value e{@code a},
jaroslav@67: * where e is the base of the natural logarithms.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.exp(a);")
jaroslav@67: public static double exp(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the natural logarithm (base e) of a {@code double}
jaroslav@67: * value. Special cases:
jaroslav@67: *
- If the argument is NaN or less than zero, then the result
jaroslav@67: * is NaN.
jaroslav@67: *
- If the argument is positive infinity, then the result is
jaroslav@67: * positive infinity.
jaroslav@67: *
- If the argument is positive zero or negative zero, then the
jaroslav@67: * result is negative infinity.
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a a value
jaroslav@67: * @return the value ln {@code a}, the natural logarithm of
jaroslav@67: * {@code a}.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.log(a);")
jaroslav@67: public static double log(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the base 10 logarithm of a {@code double} value.
jaroslav@67: * Special cases:
jaroslav@67: *
jaroslav@67: *
- If the argument is NaN or less than zero, then the result
jaroslav@67: * is NaN.
jaroslav@67: *
- If the argument is positive infinity, then the result is
jaroslav@67: * positive infinity.
jaroslav@67: *
- If the argument is positive zero or negative zero, then the
jaroslav@67: * result is negative infinity.
jaroslav@67: *
- If the argument is equal to 10n for
jaroslav@67: * integer n, then the result is n.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a a value
jaroslav@67: * @return the base 10 logarithm of {@code a}.
jaroslav@67: * @since 1.5
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
jaroslav@67: public static double log10(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the correctly rounded positive square root of a
jaroslav@67: * {@code double} value.
jaroslav@67: * Special cases:
jaroslav@67: *
- If the argument is NaN or less than zero, then the result
jaroslav@67: * is NaN.
jaroslav@67: *
- If the argument is positive infinity, then the result is positive
jaroslav@67: * infinity.
jaroslav@67: *
- If the argument is positive zero or negative zero, then the
jaroslav@67: * result is the same as the argument.
jaroslav@67: * Otherwise, the result is the {@code double} value closest to
jaroslav@67: * the true mathematical square root of the argument value.
jaroslav@67: *
jaroslav@67: * @param a a value.
jaroslav@67: * @return the positive square root of {@code a}.
jaroslav@67: * If the argument is NaN or less than zero, the result is NaN.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.sqrt(a);")
jaroslav@67: public static double sqrt(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the smallest (closest to negative infinity)
jaroslav@67: * {@code double} value that is greater than or equal to the
jaroslav@67: * argument and is equal to a mathematical integer. Special cases:
jaroslav@67: * - If the argument value is already equal to a
jaroslav@67: * mathematical integer, then the result is the same as the
jaroslav@67: * argument.
- If the argument is NaN or an infinity or
jaroslav@67: * positive zero or negative zero, then the result is the same as
jaroslav@67: * the argument.
- If the argument value is less than zero but
jaroslav@67: * greater than -1.0, then the result is negative zero.
Note
jaroslav@67: * that the value of {@code Math.ceil(x)} is exactly the
jaroslav@67: * value of {@code -Math.floor(-x)}.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param a a value.
jaroslav@67: * @return the smallest (closest to negative infinity)
jaroslav@67: * floating-point value that is greater than or equal to
jaroslav@67: * the argument and is equal to a mathematical integer.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.ceil(a);")
jaroslav@67: public static double ceil(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the largest (closest to positive infinity)
jaroslav@67: * {@code double} value that is less than or equal to the
jaroslav@67: * argument and is equal to a mathematical integer. Special cases:
jaroslav@67: * - If the argument value is already equal to a
jaroslav@67: * mathematical integer, then the result is the same as the
jaroslav@67: * argument.
- If the argument is NaN or an infinity or
jaroslav@67: * positive zero or negative zero, then the result is the same as
jaroslav@67: * the argument.
jaroslav@67: *
jaroslav@67: * @param a a value.
jaroslav@67: * @return the largest (closest to positive infinity)
jaroslav@67: * floating-point value that less than or equal to the argument
jaroslav@67: * and is equal to a mathematical integer.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.floor(a);")
jaroslav@67: public static double floor(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the angle theta from the conversion of rectangular
jaroslav@67: * coordinates ({@code x}, {@code y}) to polar
jaroslav@67: * coordinates (r, theta).
jaroslav@67: * This method computes the phase theta by computing an arc tangent
jaroslav@67: * of {@code y/x} in the range of -pi to pi. Special
jaroslav@67: * cases:
jaroslav@67: * - If either argument is NaN, then the result is NaN.
jaroslav@67: *
- If the first argument is positive zero and the second argument
jaroslav@67: * is positive, or the first argument is positive and finite and the
jaroslav@67: * second argument is positive infinity, then the result is positive
jaroslav@67: * zero.
jaroslav@67: *
- If the first argument is negative zero and the second argument
jaroslav@67: * is positive, or the first argument is negative and finite and the
jaroslav@67: * second argument is positive infinity, then the result is negative zero.
jaroslav@67: *
- If the first argument is positive zero and the second argument
jaroslav@67: * is negative, or the first argument is positive and finite and the
jaroslav@67: * second argument is negative infinity, then the result is the
jaroslav@67: * {@code double} value closest to pi.
jaroslav@67: *
- If the first argument is negative zero and the second argument
jaroslav@67: * is negative, or the first argument is negative and finite and the
jaroslav@67: * second argument is negative infinity, then the result is the
jaroslav@67: * {@code double} value closest to -pi.
jaroslav@67: *
- If the first argument is positive and the second argument is
jaroslav@67: * positive zero or negative zero, or the first argument is positive
jaroslav@67: * infinity and the second argument is finite, then the result is the
jaroslav@67: * {@code double} value closest to pi/2.
jaroslav@67: *
- If the first argument is negative and the second argument is
jaroslav@67: * positive zero or negative zero, or the first argument is negative
jaroslav@67: * infinity and the second argument is finite, then the result is the
jaroslav@67: * {@code double} value closest to -pi/2.
jaroslav@67: *
- If both arguments are positive infinity, then the result is the
jaroslav@67: * {@code double} value closest to pi/4.
jaroslav@67: *
- If the first argument is positive infinity and the second argument
jaroslav@67: * is negative infinity, then the result is the {@code double}
jaroslav@67: * value closest to 3*pi/4.
jaroslav@67: *
- If the first argument is negative infinity and the second argument
jaroslav@67: * is positive infinity, then the result is the {@code double} value
jaroslav@67: * closest to -pi/4.
jaroslav@67: *
- If both arguments are negative infinity, then the result is the
jaroslav@67: * {@code double} value closest to -3*pi/4.
jaroslav@67: *
jaroslav@67: * The computed result must be within 2 ulps of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param y the ordinate coordinate
jaroslav@67: * @param x the abscissa coordinate
jaroslav@67: * @return the theta component of the point
jaroslav@67: * (r, theta)
jaroslav@67: * in polar coordinates that corresponds to the point
jaroslav@67: * (x, y) in Cartesian coordinates.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
jaroslav@67: public static double atan2(double y, double x) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the value of the first argument raised to the power of the
jaroslav@67: * second argument. Special cases:
jaroslav@67: *
jaroslav@67: *
- If the second argument is positive or negative zero, then the
jaroslav@67: * result is 1.0.
jaroslav@67: *
- If the second argument is 1.0, then the result is the same as the
jaroslav@67: * first argument.
jaroslav@67: *
- If the second argument is NaN, then the result is NaN.
jaroslav@67: *
- If the first argument is NaN and the second argument is nonzero,
jaroslav@67: * then the result is NaN.
jaroslav@67: *
jaroslav@67: *
- If
jaroslav@67: *
jaroslav@67: * - the absolute value of the first argument is greater than 1
jaroslav@67: * and the second argument is positive infinity, or
jaroslav@67: *
- the absolute value of the first argument is less than 1 and
jaroslav@67: * the second argument is negative infinity,
jaroslav@67: *
jaroslav@67: * then the result is positive infinity.
jaroslav@67: *
jaroslav@67: * - If
jaroslav@67: *
jaroslav@67: * - the absolute value of the first argument is greater than 1 and
jaroslav@67: * the second argument is negative infinity, or
jaroslav@67: *
- the absolute value of the
jaroslav@67: * first argument is less than 1 and the second argument is positive
jaroslav@67: * infinity,
jaroslav@67: *
jaroslav@67: * then the result is positive zero.
jaroslav@67: *
jaroslav@67: * - If the absolute value of the first argument equals 1 and the
jaroslav@67: * second argument is infinite, then the result is NaN.
jaroslav@67: *
jaroslav@67: *
- If
jaroslav@67: *
jaroslav@67: * - the first argument is positive zero and the second argument
jaroslav@67: * is greater than zero, or
jaroslav@67: *
- the first argument is positive infinity and the second
jaroslav@67: * argument is less than zero,
jaroslav@67: *
jaroslav@67: * then the result is positive zero.
jaroslav@67: *
jaroslav@67: * - If
jaroslav@67: *
jaroslav@67: * - the first argument is positive zero and the second argument
jaroslav@67: * is less than zero, or
jaroslav@67: *
- the first argument is positive infinity and the second
jaroslav@67: * argument is greater than zero,
jaroslav@67: *
jaroslav@67: * then the result is positive infinity.
jaroslav@67: *
jaroslav@67: * - If
jaroslav@67: *
jaroslav@67: * - the first argument is negative zero and the second argument
jaroslav@67: * is greater than zero but not a finite odd integer, or
jaroslav@67: *
- the first argument is negative infinity and the second
jaroslav@67: * argument is less than zero but not a finite odd integer,
jaroslav@67: *
jaroslav@67: * then the result is positive zero.
jaroslav@67: *
jaroslav@67: * - If
jaroslav@67: *
jaroslav@67: * - the first argument is negative zero and the second argument
jaroslav@67: * is a positive finite odd integer, or
jaroslav@67: *
- the first argument is negative infinity and the second
jaroslav@67: * argument is a negative finite odd integer,
jaroslav@67: *
jaroslav@67: * then the result is negative zero.
jaroslav@67: *
jaroslav@67: * - If
jaroslav@67: *
jaroslav@67: * - the first argument is negative zero and the second argument
jaroslav@67: * is less than zero but not a finite odd integer, or
jaroslav@67: *
- the first argument is negative infinity and the second
jaroslav@67: * argument is greater than zero but not a finite odd integer,
jaroslav@67: *
jaroslav@67: * then the result is positive infinity.
jaroslav@67: *
jaroslav@67: * - If
jaroslav@67: *
jaroslav@67: * - the first argument is negative zero and the second argument
jaroslav@67: * is a negative finite odd integer, or
jaroslav@67: *
- the first argument is negative infinity and the second
jaroslav@67: * argument is a positive finite odd integer,
jaroslav@67: *
jaroslav@67: * then the result is negative infinity.
jaroslav@67: *
jaroslav@67: * - If the first argument is finite and less than zero
jaroslav@67: *
jaroslav@67: * - if the second argument is a finite even integer, the
jaroslav@67: * result is equal to the result of raising the absolute value of
jaroslav@67: * the first argument to the power of the second argument
jaroslav@67: *
jaroslav@67: *
- if the second argument is a finite odd integer, the result
jaroslav@67: * is equal to the negative of the result of raising the absolute
jaroslav@67: * value of the first argument to the power of the second
jaroslav@67: * argument
jaroslav@67: *
jaroslav@67: *
- if the second argument is finite and not an integer, then
jaroslav@67: * the result is NaN.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * - If both arguments are integers, then the result is exactly equal
jaroslav@67: * to the mathematical result of raising the first argument to the power
jaroslav@67: * of the second argument if that result can in fact be represented
jaroslav@67: * exactly as a {@code double} value.
jaroslav@67: *
jaroslav@67: * (In the foregoing descriptions, a floating-point value is
jaroslav@67: * considered to be an integer if and only if it is finite and a
jaroslav@67: * fixed point of the method {@link #ceil ceil} or,
jaroslav@67: * equivalently, a fixed point of the method {@link #floor
jaroslav@67: * floor}. A value is a fixed point of a one-argument
jaroslav@67: * method if and only if the result of applying the method to the
jaroslav@67: * value is equal to the value.)
jaroslav@67: *
jaroslav@67: *
The computed result must be within 1 ulp of the exact result.
jaroslav@67: * Results must be semi-monotonic.
jaroslav@67: *
jaroslav@67: * @param a the base.
jaroslav@67: * @param b the exponent.
jaroslav@67: * @return the value {@code a}{@code b}.
jaroslav@67: */
jtulach@132: @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
jaroslav@67: public static double pow(double a, double b) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the closest {@code int} to the argument, with ties
jaroslav@67: * rounding up.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * Special cases:
jaroslav@67: *
- If the argument is NaN, the result is 0.
jaroslav@67: *
- If the argument is negative infinity or any value less than or
jaroslav@67: * equal to the value of {@code Integer.MIN_VALUE}, the result is
jaroslav@67: * equal to the value of {@code Integer.MIN_VALUE}.
jaroslav@67: *
- If the argument is positive infinity or any value greater than or
jaroslav@67: * equal to the value of {@code Integer.MAX_VALUE}, the result is
jaroslav@67: * equal to the value of {@code Integer.MAX_VALUE}.
jaroslav@67: *
jaroslav@67: * @param a a floating-point value to be rounded to an integer.
jaroslav@67: * @return the value of the argument rounded to the nearest
jaroslav@67: * {@code int} value.
jaroslav@67: * @see java.lang.Integer#MAX_VALUE
jaroslav@67: * @see java.lang.Integer#MIN_VALUE
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.round(a);")
jaroslav@67: public static int round(float a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the closest {@code long} to the argument, with ties
jaroslav@67: * rounding up.
jaroslav@67: *
jaroslav@67: * Special cases:
jaroslav@67: *
- If the argument is NaN, the result is 0.
jaroslav@67: *
- If the argument is negative infinity or any value less than or
jaroslav@67: * equal to the value of {@code Long.MIN_VALUE}, the result is
jaroslav@67: * equal to the value of {@code Long.MIN_VALUE}.
jaroslav@67: *
- If the argument is positive infinity or any value greater than or
jaroslav@67: * equal to the value of {@code Long.MAX_VALUE}, the result is
jaroslav@67: * equal to the value of {@code Long.MAX_VALUE}.
jaroslav@67: *
jaroslav@67: * @param a a floating-point value to be rounded to a
jaroslav@67: * {@code long}.
jaroslav@67: * @return the value of the argument rounded to the nearest
jaroslav@67: * {@code long} value.
jaroslav@67: * @see java.lang.Long#MAX_VALUE
jaroslav@67: * @see java.lang.Long#MIN_VALUE
jaroslav@67: */
jtulach@132: @JavaScriptBody(args="a", body="return Math.round(a);")
jaroslav@67: public static long round(double a) {
jtulach@132: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@84: // private static Random randomNumberGenerator;
jaroslav@84: //
jaroslav@84: // private static synchronized Random initRNG() {
jaroslav@84: // Random rnd = randomNumberGenerator;
jaroslav@84: // return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns a {@code double} value with a positive sign, greater
jaroslav@67: * than or equal to {@code 0.0} and less than {@code 1.0}.
jaroslav@67: * Returned values are chosen pseudorandomly with (approximately)
jaroslav@67: * uniform distribution from that range.
jaroslav@67: *
jaroslav@67: * When this method is first called, it creates a single new
jaroslav@67: * pseudorandom-number generator, exactly as if by the expression
jaroslav@67: *
jaroslav@67: *
{@code new java.util.Random()}
jaroslav@67: *
jaroslav@67: * This new pseudorandom-number generator is used thereafter for
jaroslav@67: * all calls to this method and is used nowhere else.
jaroslav@67: *
jaroslav@67: * This method is properly synchronized to allow correct use by
jaroslav@67: * more than one thread. However, if many threads need to generate
jaroslav@67: * pseudorandom numbers at a great rate, it may reduce contention
jaroslav@67: * for each thread to have its own pseudorandom-number generator.
jaroslav@67: *
jaroslav@67: * @return a pseudorandom {@code double} greater than or equal
jaroslav@67: * to {@code 0.0} and less than {@code 1.0}.
jaroslav@67: * @see Random#nextDouble()
jaroslav@67: */
jaroslav@67: public static double random() {
jaroslav@84: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the absolute value of an {@code int} value.
jaroslav@67: * If the argument is not negative, the argument is returned.
jaroslav@67: * If the argument is negative, the negation of the argument is returned.
jaroslav@67: *
jaroslav@67: *
Note that if the argument is equal to the value of
jaroslav@67: * {@link Integer#MIN_VALUE}, the most negative representable
jaroslav@67: * {@code int} value, the result is that same value, which is
jaroslav@67: * negative.
jaroslav@67: *
jaroslav@67: * @param a the argument whose absolute value is to be determined
jaroslav@67: * @return the absolute value of the argument.
jaroslav@67: */
jaroslav@67: public static int abs(int a) {
jaroslav@67: return (a < 0) ? -a : a;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the absolute value of a {@code long} value.
jaroslav@67: * If the argument is not negative, the argument is returned.
jaroslav@67: * If the argument is negative, the negation of the argument is returned.
jaroslav@67: *
jaroslav@67: *
Note that if the argument is equal to the value of
jaroslav@67: * {@link Long#MIN_VALUE}, the most negative representable
jaroslav@67: * {@code long} value, the result is that same value, which
jaroslav@67: * is negative.
jaroslav@67: *
jaroslav@67: * @param a the argument whose absolute value is to be determined
jaroslav@67: * @return the absolute value of the argument.
jaroslav@67: */
jaroslav@67: public static long abs(long a) {
jaroslav@67: return (a < 0) ? -a : a;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the absolute value of a {@code float} value.
jaroslav@67: * If the argument is not negative, the argument is returned.
jaroslav@67: * If the argument is negative, the negation of the argument is returned.
jaroslav@67: * Special cases:
jaroslav@67: *
- If the argument is positive zero or negative zero, the
jaroslav@67: * result is positive zero.
jaroslav@67: *
- If the argument is infinite, the result is positive infinity.
jaroslav@67: *
- If the argument is NaN, the result is NaN.
jaroslav@67: * In other words, the result is the same as the value of the expression:
jaroslav@67: * {@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
jaroslav@67: *
jaroslav@67: * @param a the argument whose absolute value is to be determined
jaroslav@67: * @return the absolute value of the argument.
jaroslav@67: */
jaroslav@67: public static float abs(float a) {
jaroslav@67: return (a <= 0.0F) ? 0.0F - a : a;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the absolute value of a {@code double} value.
jaroslav@67: * If the argument is not negative, the argument is returned.
jaroslav@67: * If the argument is negative, the negation of the argument is returned.
jaroslav@67: * Special cases:
jaroslav@67: *
- If the argument is positive zero or negative zero, the result
jaroslav@67: * is positive zero.
jaroslav@67: *
- If the argument is infinite, the result is positive infinity.
jaroslav@67: *
- If the argument is NaN, the result is NaN.
jaroslav@67: * In other words, the result is the same as the value of the expression:
jaroslav@67: * {@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
jaroslav@67: *
jaroslav@67: * @param a the argument whose absolute value is to be determined
jaroslav@67: * @return the absolute value of the argument.
jaroslav@67: */
jaroslav@67: public static double abs(double a) {
jaroslav@67: return (a <= 0.0D) ? 0.0D - a : a;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the greater of two {@code int} values. That is, the
jaroslav@67: * result is the argument closer to the value of
jaroslav@67: * {@link Integer#MAX_VALUE}. If the arguments have the same value,
jaroslav@67: * the result is that same value.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the larger of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@67: public static int max(int a, int b) {
jaroslav@67: return (a >= b) ? a : b;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the greater of two {@code long} values. That is, the
jaroslav@67: * result is the argument closer to the value of
jaroslav@67: * {@link Long#MAX_VALUE}. If the arguments have the same value,
jaroslav@67: * the result is that same value.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the larger of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@67: public static long max(long a, long b) {
jaroslav@67: return (a >= b) ? a : b;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the greater of two {@code float} values. That is,
jaroslav@67: * the result is the argument closer to positive infinity. If the
jaroslav@67: * arguments have the same value, the result is that same
jaroslav@67: * value. If either value is NaN, then the result is NaN. Unlike
jaroslav@67: * the numerical comparison operators, this method considers
jaroslav@67: * negative zero to be strictly smaller than positive zero. If one
jaroslav@67: * argument is positive zero and the other negative zero, the
jaroslav@67: * result is positive zero.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the larger of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@104: @JavaScriptBody(args={"a", "b"},
jaroslav@104: body="return Math.max(a,b);"
jaroslav@104: )
jaroslav@67: public static float max(float a, float b) {
jaroslav@104: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the greater of two {@code double} values. That
jaroslav@67: * is, the result is the argument closer to positive infinity. If
jaroslav@67: * the arguments have the same value, the result is that same
jaroslav@67: * value. If either value is NaN, then the result is NaN. Unlike
jaroslav@67: * the numerical comparison operators, this method considers
jaroslav@67: * negative zero to be strictly smaller than positive zero. If one
jaroslav@67: * argument is positive zero and the other negative zero, the
jaroslav@67: * result is positive zero.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the larger of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@104: @JavaScriptBody(args={"a", "b"},
jaroslav@104: body="return Math.max(a,b);"
jaroslav@104: )
jaroslav@67: public static double max(double a, double b) {
jaroslav@104: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the smaller of two {@code int} values. That is,
jaroslav@67: * the result the argument closer to the value of
jaroslav@67: * {@link Integer#MIN_VALUE}. If the arguments have the same
jaroslav@67: * value, the result is that same value.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the smaller of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@67: public static int min(int a, int b) {
jaroslav@67: return (a <= b) ? a : b;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the smaller of two {@code long} values. That is,
jaroslav@67: * the result is the argument closer to the value of
jaroslav@67: * {@link Long#MIN_VALUE}. If the arguments have the same
jaroslav@67: * value, the result is that same value.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the smaller of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@67: public static long min(long a, long b) {
jaroslav@67: return (a <= b) ? a : b;
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the smaller of two {@code float} values. That is,
jaroslav@67: * the result is the value closer to negative infinity. If the
jaroslav@67: * arguments have the same value, the result is that same
jaroslav@67: * value. If either value is NaN, then the result is NaN. Unlike
jaroslav@67: * the numerical comparison operators, this method considers
jaroslav@67: * negative zero to be strictly smaller than positive zero. If
jaroslav@67: * one argument is positive zero and the other is negative zero,
jaroslav@67: * the result is negative zero.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the smaller of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@104: @JavaScriptBody(args={"a", "b"},
jaroslav@104: body="return Math.min(a,b);"
jaroslav@104: )
jaroslav@67: public static float min(float a, float b) {
jaroslav@104: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the smaller of two {@code double} values. That
jaroslav@67: * is, the result is the value closer to negative infinity. If the
jaroslav@67: * arguments have the same value, the result is that same
jaroslav@67: * value. If either value is NaN, then the result is NaN. Unlike
jaroslav@67: * the numerical comparison operators, this method considers
jaroslav@67: * negative zero to be strictly smaller than positive zero. If one
jaroslav@67: * argument is positive zero and the other is negative zero, the
jaroslav@67: * result is negative zero.
jaroslav@67: *
jaroslav@67: * @param a an argument.
jaroslav@67: * @param b another argument.
jaroslav@67: * @return the smaller of {@code a} and {@code b}.
jaroslav@67: */
jaroslav@104: @JavaScriptBody(args={"a", "b"},
jaroslav@104: body="return Math.min(a,b);"
jaroslav@104: )
jaroslav@67: public static double min(double a, double b) {
jaroslav@104: throw new UnsupportedOperationException();
jaroslav@67: }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the size of an ulp of the argument. An ulp of a
jaroslav@67: * {@code double} value is the positive distance between this
jaroslav@67: * floating-point value and the {@code double} value next
jaroslav@67: * larger in magnitude. Note that for non-NaN x,
jaroslav@67: * ulp(-x) == ulp(x)
.
jaroslav@67: *
jaroslav@67: *
Special Cases:
jaroslav@67: *
jaroslav@67: * - If the argument is NaN, then the result is NaN.
jaroslav@67: *
- If the argument is positive or negative infinity, then the
jaroslav@67: * result is positive infinity.
jaroslav@67: *
- If the argument is positive or negative zero, then the result is
jaroslav@67: * {@code Double.MIN_VALUE}.
jaroslav@67: *
- If the argument is ±{@code Double.MAX_VALUE}, then
jaroslav@67: * the result is equal to 2971.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param d the floating-point value whose ulp is to be returned
jaroslav@67: * @return the size of an ulp of the argument
jaroslav@67: * @author Joseph D. Darcy
jaroslav@67: * @since 1.5
jaroslav@67: */
jaroslav@84: // public static double ulp(double d) {
jaroslav@84: // return sun.misc.FpUtils.ulp(d);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the size of an ulp of the argument. An ulp of a
jaroslav@67: * {@code float} value is the positive distance between this
jaroslav@67: * floating-point value and the {@code float} value next
jaroslav@67: * larger in magnitude. Note that for non-NaN x,
jaroslav@67: * ulp(-x) == ulp(x)
.
jaroslav@67: *
jaroslav@67: * Special Cases:
jaroslav@67: *
jaroslav@67: * - If the argument is NaN, then the result is NaN.
jaroslav@67: *
- If the argument is positive or negative infinity, then the
jaroslav@67: * result is positive infinity.
jaroslav@67: *
- If the argument is positive or negative zero, then the result is
jaroslav@67: * {@code Float.MIN_VALUE}.
jaroslav@67: *
- If the argument is ±{@code Float.MAX_VALUE}, then
jaroslav@67: * the result is equal to 2104.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param f the floating-point value whose ulp is to be returned
jaroslav@67: * @return the size of an ulp of the argument
jaroslav@67: * @author Joseph D. Darcy
jaroslav@67: * @since 1.5
jaroslav@67: */
jaroslav@84: // public static float ulp(float f) {
jaroslav@84: // return sun.misc.FpUtils.ulp(f);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the signum function of the argument; zero if the argument
jaroslav@67: * is zero, 1.0 if the argument is greater than zero, -1.0 if the
jaroslav@67: * argument is less than zero.
jaroslav@67: *
jaroslav@67: * Special Cases:
jaroslav@67: *
jaroslav@67: * - If the argument is NaN, then the result is NaN.
jaroslav@67: *
- If the argument is positive zero or negative zero, then the
jaroslav@67: * result is the same as the argument.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param d the floating-point value whose signum is to be returned
jaroslav@67: * @return the signum function of the argument
jaroslav@67: * @author Joseph D. Darcy
jaroslav@67: * @since 1.5
jaroslav@67: */
jaroslav@84: // public static double signum(double d) {
jaroslav@84: // return sun.misc.FpUtils.signum(d);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the signum function of the argument; zero if the argument
jaroslav@67: * is zero, 1.0f if the argument is greater than zero, -1.0f if the
jaroslav@67: * argument is less than zero.
jaroslav@67: *
jaroslav@67: * Special Cases:
jaroslav@67: *
jaroslav@67: * - If the argument is NaN, then the result is NaN.
jaroslav@67: *
- If the argument is positive zero or negative zero, then the
jaroslav@67: * result is the same as the argument.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param f the floating-point value whose signum is to be returned
jaroslav@67: * @return the signum function of the argument
jaroslav@67: * @author Joseph D. Darcy
jaroslav@67: * @since 1.5
jaroslav@67: */
jaroslav@84: // public static float signum(float f) {
jaroslav@84: // return sun.misc.FpUtils.signum(f);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the first floating-point argument with the sign of the
jaroslav@67: * second floating-point argument. Note that unlike the {@link
jaroslav@67: * StrictMath#copySign(double, double) StrictMath.copySign}
jaroslav@67: * method, this method does not require NaN {@code sign}
jaroslav@67: * arguments to be treated as positive values; implementations are
jaroslav@67: * permitted to treat some NaN arguments as positive and other NaN
jaroslav@67: * arguments as negative to allow greater performance.
jaroslav@67: *
jaroslav@67: * @param magnitude the parameter providing the magnitude of the result
jaroslav@67: * @param sign the parameter providing the sign of the result
jaroslav@67: * @return a value with the magnitude of {@code magnitude}
jaroslav@67: * and the sign of {@code sign}.
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static double copySign(double magnitude, double sign) {
jaroslav@84: // return sun.misc.FpUtils.rawCopySign(magnitude, sign);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the first floating-point argument with the sign of the
jaroslav@67: * second floating-point argument. Note that unlike the {@link
jaroslav@67: * StrictMath#copySign(float, float) StrictMath.copySign}
jaroslav@67: * method, this method does not require NaN {@code sign}
jaroslav@67: * arguments to be treated as positive values; implementations are
jaroslav@67: * permitted to treat some NaN arguments as positive and other NaN
jaroslav@67: * arguments as negative to allow greater performance.
jaroslav@67: *
jaroslav@67: * @param magnitude the parameter providing the magnitude of the result
jaroslav@67: * @param sign the parameter providing the sign of the result
jaroslav@67: * @return a value with the magnitude of {@code magnitude}
jaroslav@67: * and the sign of {@code sign}.
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static float copySign(float magnitude, float sign) {
jaroslav@84: // return sun.misc.FpUtils.rawCopySign(magnitude, sign);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the unbiased exponent used in the representation of a
jaroslav@67: * {@code float}. Special cases:
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * - If the argument is NaN or infinite, then the result is
jaroslav@67: * {@link Float#MAX_EXPONENT} + 1.
jaroslav@67: *
- If the argument is zero or subnormal, then the result is
jaroslav@67: * {@link Float#MIN_EXPONENT} -1.
jaroslav@67: *
jaroslav@67: * @param f a {@code float} value
jaroslav@67: * @return the unbiased exponent of the argument
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static int getExponent(float f) {
jaroslav@84: // return sun.misc.FpUtils.getExponent(f);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the unbiased exponent used in the representation of a
jaroslav@67: * {@code double}. Special cases:
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * - If the argument is NaN or infinite, then the result is
jaroslav@67: * {@link Double#MAX_EXPONENT} + 1.
jaroslav@67: *
- If the argument is zero or subnormal, then the result is
jaroslav@67: * {@link Double#MIN_EXPONENT} -1.
jaroslav@67: *
jaroslav@67: * @param d a {@code double} value
jaroslav@67: * @return the unbiased exponent of the argument
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static int getExponent(double d) {
jaroslav@84: // return sun.misc.FpUtils.getExponent(d);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the floating-point number adjacent to the first
jaroslav@67: * argument in the direction of the second argument. If both
jaroslav@67: * arguments compare as equal the second argument is returned.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * Special cases:
jaroslav@67: *
jaroslav@67: * - If either argument is a NaN, then NaN is returned.
jaroslav@67: *
jaroslav@67: *
- If both arguments are signed zeros, {@code direction}
jaroslav@67: * is returned unchanged (as implied by the requirement of
jaroslav@67: * returning the second argument if the arguments compare as
jaroslav@67: * equal).
jaroslav@67: *
jaroslav@67: *
- If {@code start} is
jaroslav@67: * ±{@link Double#MIN_VALUE} and {@code direction}
jaroslav@67: * has a value such that the result should have a smaller
jaroslav@67: * magnitude, then a zero with the same sign as {@code start}
jaroslav@67: * is returned.
jaroslav@67: *
jaroslav@67: *
- If {@code start} is infinite and
jaroslav@67: * {@code direction} has a value such that the result should
jaroslav@67: * have a smaller magnitude, {@link Double#MAX_VALUE} with the
jaroslav@67: * same sign as {@code start} is returned.
jaroslav@67: *
jaroslav@67: *
- If {@code start} is equal to ±
jaroslav@67: * {@link Double#MAX_VALUE} and {@code direction} has a
jaroslav@67: * value such that the result should have a larger magnitude, an
jaroslav@67: * infinity with same sign as {@code start} is returned.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param start starting floating-point value
jaroslav@67: * @param direction value indicating which of
jaroslav@67: * {@code start}'s neighbors or {@code start} should
jaroslav@67: * be returned
jaroslav@67: * @return The floating-point number adjacent to {@code start} in the
jaroslav@67: * direction of {@code direction}.
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static double nextAfter(double start, double direction) {
jaroslav@84: // return sun.misc.FpUtils.nextAfter(start, direction);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the floating-point number adjacent to the first
jaroslav@67: * argument in the direction of the second argument. If both
jaroslav@67: * arguments compare as equal a value equivalent to the second argument
jaroslav@67: * is returned.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * Special cases:
jaroslav@67: *
jaroslav@67: * - If either argument is a NaN, then NaN is returned.
jaroslav@67: *
jaroslav@67: *
- If both arguments are signed zeros, a value equivalent
jaroslav@67: * to {@code direction} is returned.
jaroslav@67: *
jaroslav@67: *
- If {@code start} is
jaroslav@67: * ±{@link Float#MIN_VALUE} and {@code direction}
jaroslav@67: * has a value such that the result should have a smaller
jaroslav@67: * magnitude, then a zero with the same sign as {@code start}
jaroslav@67: * is returned.
jaroslav@67: *
jaroslav@67: *
- If {@code start} is infinite and
jaroslav@67: * {@code direction} has a value such that the result should
jaroslav@67: * have a smaller magnitude, {@link Float#MAX_VALUE} with the
jaroslav@67: * same sign as {@code start} is returned.
jaroslav@67: *
jaroslav@67: *
- If {@code start} is equal to ±
jaroslav@67: * {@link Float#MAX_VALUE} and {@code direction} has a
jaroslav@67: * value such that the result should have a larger magnitude, an
jaroslav@67: * infinity with same sign as {@code start} is returned.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param start starting floating-point value
jaroslav@67: * @param direction value indicating which of
jaroslav@67: * {@code start}'s neighbors or {@code start} should
jaroslav@67: * be returned
jaroslav@67: * @return The floating-point number adjacent to {@code start} in the
jaroslav@67: * direction of {@code direction}.
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static float nextAfter(float start, double direction) {
jaroslav@84: // return sun.misc.FpUtils.nextAfter(start, direction);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the floating-point value adjacent to {@code d} in
jaroslav@67: * the direction of positive infinity. This method is
jaroslav@67: * semantically equivalent to {@code nextAfter(d,
jaroslav@67: * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
jaroslav@67: * implementation may run faster than its equivalent
jaroslav@67: * {@code nextAfter} call.
jaroslav@67: *
jaroslav@67: * Special Cases:
jaroslav@67: *
jaroslav@67: * - If the argument is NaN, the result is NaN.
jaroslav@67: *
jaroslav@67: *
- If the argument is positive infinity, the result is
jaroslav@67: * positive infinity.
jaroslav@67: *
jaroslav@67: *
- If the argument is zero, the result is
jaroslav@67: * {@link Double#MIN_VALUE}
jaroslav@67: *
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param d starting floating-point value
jaroslav@67: * @return The adjacent floating-point value closer to positive
jaroslav@67: * infinity.
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static double nextUp(double d) {
jaroslav@84: // return sun.misc.FpUtils.nextUp(d);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Returns the floating-point value adjacent to {@code f} in
jaroslav@67: * the direction of positive infinity. This method is
jaroslav@67: * semantically equivalent to {@code nextAfter(f,
jaroslav@67: * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
jaroslav@67: * implementation may run faster than its equivalent
jaroslav@67: * {@code nextAfter} call.
jaroslav@67: *
jaroslav@67: * Special Cases:
jaroslav@67: *
jaroslav@67: * - If the argument is NaN, the result is NaN.
jaroslav@67: *
jaroslav@67: *
- If the argument is positive infinity, the result is
jaroslav@67: * positive infinity.
jaroslav@67: *
jaroslav@67: *
- If the argument is zero, the result is
jaroslav@67: * {@link Float#MIN_VALUE}
jaroslav@67: *
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param f starting floating-point value
jaroslav@67: * @return The adjacent floating-point value closer to positive
jaroslav@67: * infinity.
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static float nextUp(float f) {
jaroslav@84: // return sun.misc.FpUtils.nextUp(f);
jaroslav@84: // }
jaroslav@67:
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Return {@code d} ×
jaroslav@67: * 2{@code scaleFactor} rounded as if performed
jaroslav@67: * by a single correctly rounded floating-point multiply to a
jaroslav@67: * member of the double value set. See the Java
jaroslav@67: * Language Specification for a discussion of floating-point
jaroslav@67: * value sets. If the exponent of the result is between {@link
jaroslav@67: * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
jaroslav@67: * answer is calculated exactly. If the exponent of the result
jaroslav@67: * would be larger than {@code Double.MAX_EXPONENT}, an
jaroslav@67: * infinity is returned. Note that if the result is subnormal,
jaroslav@67: * precision may be lost; that is, when {@code scalb(x, n)}
jaroslav@67: * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
jaroslav@67: * x. When the result is non-NaN, the result has the same
jaroslav@67: * sign as {@code d}.
jaroslav@67: *
jaroslav@67: * Special cases:
jaroslav@67: *
jaroslav@67: * - If the first argument is NaN, NaN is returned.
jaroslav@67: *
- If the first argument is infinite, then an infinity of the
jaroslav@67: * same sign is returned.
jaroslav@67: *
- If the first argument is zero, then a zero of the same
jaroslav@67: * sign is returned.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param d number to be scaled by a power of two.
jaroslav@67: * @param scaleFactor power of 2 used to scale {@code d}
jaroslav@67: * @return {@code d} × 2{@code scaleFactor}
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static double scalb(double d, int scaleFactor) {
jaroslav@84: // return sun.misc.FpUtils.scalb(d, scaleFactor);
jaroslav@84: // }
jaroslav@67:
jaroslav@67: /**
jaroslav@67: * Return {@code f} ×
jaroslav@67: * 2{@code scaleFactor} rounded as if performed
jaroslav@67: * by a single correctly rounded floating-point multiply to a
jaroslav@67: * member of the float value set. See the Java
jaroslav@67: * Language Specification for a discussion of floating-point
jaroslav@67: * value sets. If the exponent of the result is between {@link
jaroslav@67: * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
jaroslav@67: * answer is calculated exactly. If the exponent of the result
jaroslav@67: * would be larger than {@code Float.MAX_EXPONENT}, an
jaroslav@67: * infinity is returned. Note that if the result is subnormal,
jaroslav@67: * precision may be lost; that is, when {@code scalb(x, n)}
jaroslav@67: * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
jaroslav@67: * x. When the result is non-NaN, the result has the same
jaroslav@67: * sign as {@code f}.
jaroslav@67: *
jaroslav@67: * Special cases:
jaroslav@67: *
jaroslav@67: * - If the first argument is NaN, NaN is returned.
jaroslav@67: *
- If the first argument is infinite, then an infinity of the
jaroslav@67: * same sign is returned.
jaroslav@67: *
- If the first argument is zero, then a zero of the same
jaroslav@67: * sign is returned.
jaroslav@67: *
jaroslav@67: *
jaroslav@67: * @param f number to be scaled by a power of two.
jaroslav@67: * @param scaleFactor power of 2 used to scale {@code f}
jaroslav@67: * @return {@code f} × 2{@code scaleFactor}
jaroslav@67: * @since 1.6
jaroslav@67: */
jaroslav@84: // public static float scalb(float f, int scaleFactor) {
jaroslav@84: // return sun.misc.FpUtils.scalb(f, scaleFactor);
jaroslav@84: // }
jaroslav@67: }