All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.lang.Math Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
/*

This is not an official specification document, and usage is restricted.

NOTICE


(c) 2005-2007 Sun Microsystems, Inc. All Rights Reserved.

Neither this file nor any files generated from it describe a complete specification, and they may only be used as described below. For example, no permission is given for you to incorporate this file, in whole or in part, in an implementation of a Java specification.

Sun Microsystems Inc. owns the copyright in this file and it is provided to you for informative, as opposed to normative, use. The file and any files generated from it may be used to generate other informative documentation, such as a unified set of documents of API signatures for a platform that includes technologies expressed as Java APIs. The file may also be used to produce "compilation stubs," which allow applications to be compiled and validated for such platforms.

Any work generated from this file, such as unified javadocs or compiled stub files, must be accompanied by this notice in its entirety.

This work corresponds to the API signatures of JSR 219: Foundation Profile 1.1. In the event of a discrepency between this work and the JSR 219 specification, which is available at http://www.jcp.org/en/jsr/detail?id=219, the latter takes precedence. */ package java.lang; import java.util.Random; /** * The class Math contains methods for performing basic * numeric operations such as the elementary exponential, logarithm, * square root, and trigonometric functions. *

* Unlike some of the numeric methods of class * StrictMath, all implementations of the equivalent * functions of class Math are not defined to return the * bit-for-bit same results. This relaxation permits * better-performing implementations where strict reproducibility is * not required. *

* By default many of the Math methods simply call * the equivalent method in StrictMath for their * implementation. Code generators are encouraged to use * platform-specific native libraries or microprocessor instructions, * where available, to provide higher-performance implementations of * Math methods. Such higher-performance * implementations still must conform to the specification for * Math. *

* The quality of implementation specifications concern two * properties, accuracy of the returned result and monotonicity of the * method. Accuracy of the floating-point Math methods * is measured in terms of ulps, units in the last place. For * a given floating-point format, an ulp of a specific real number * value is the difference between the two floating-point values * closest to that numerical value. When discussing the accuracy of a * method as a whole rather than at a specific argument, the number of * ulps cited is for the worst-case error at any argument. If a * method always has an error less than 0.5 ulps, the method always * returns the floating-point number nearest the exact result; such a * method is correctly rounded. A correctly rounded method is * generally the best a floating-point approximation can be; however, * it is impractical for many floating-point methods to be correctly * rounded. Instead, for the Math class, a larger error * bound of 1 or 2 ulps is allowed for certain methods. Informally, * with a 1 ulp error bound, when the exact result is a representable * number the exact result should be returned; otherwise, either of * the two floating-point numbers closest to the exact result may be * returned. Besides accuracy at individual arguments, maintaining * proper relations between the method at different arguments is also * important. Therefore, methods with more than 0.5 ulp errors are * required to be semi-monotonic: whenever the mathematical * function is non-decreasing, so is the floating-point approximation, * likewise, whenever the mathematical function is non-increasing, so * is the floating-point approximation. Not all approximations that * have 1 ulp accuracy will automatically meet the monotonicity * requirements. * * @author unascribed * @version 1.50, 02/02/00 * @since JDK1.0 */ public final class Math { /** * The double value that is closer than any other to * e, the base of the natural logarithms. */ public static final double E = 2.718281828459045; /** * The double value that is closer than any other to * pi, the ratio of the circumference of a circle to its * diameter. */ public static final double PI = 3.141592653589793; /* * This hidden constructor does not necessarily correspond to * a constructor in the original source file -- it keeps javadoc * from generating an inappropriate default constructor. */ private Math() { } /** * Returns the trigonometric sine of an angle. Special cases: *

  • If the argument is NaN or an infinity, then the * result is NaN. *
  • If the argument is zero, then the result is a zero with the * same sign as the argument.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a an angle, in radians. * @return the sine of the argument. */ public static double sin(double a) { return 0.0d; } /** * Returns the trigonometric cosine of an angle. Special cases: *

  • If the argument is NaN or an infinity, then the * result is NaN.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a an angle, in radians. * @return the cosine of the argument. */ public static double cos(double a) { return 0.0d; } /** * Returns the trigonometric tangent of an angle. Special cases: *

  • If the argument is NaN or an infinity, then the result * is NaN. *
  • If the argument is zero, then the result is a zero with the * same sign as the argument.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a an angle, in radians. * @return the tangent of the argument. */ public static double tan(double a) { return 0.0d; } /** * Returns the arc sine of an angle, in the range of -pi/2 through * pi/2. Special cases: *

  • If the argument is NaN or its absolute value is greater * than 1, then the result is NaN. *
  • If the argument is zero, then the result is a zero with the * same sign as the argument.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a the value whose arc sine is to be returned. * @return the arc sine of the argument. */ public static double asin(double a) { return 0.0d; } /** * Returns the arc cosine of an angle, in the range of 0.0 through * pi. Special case: *

  • If the argument is NaN or its absolute value is greater * than 1, then the result is NaN.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a the value whose arc cosine is to be returned. * @return the arc cosine of the argument. */ public static double acos(double a) { return 0.0d; } /** * Returns the arc tangent of an angle, in the range of -pi/2 * through pi/2. Special cases: *

  • If the argument is NaN, then the result is NaN. *
  • If the argument is zero, then the result is a zero with the * same sign as the argument.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a the value whose arc tangent is to be returned. * @return the arc tangent of the argument. */ public static double atan(double a) { return 0.0d; } /** * Converts an angle measured in degrees to an approximately * equivalent angle measured in radians. The conversion from * degrees to radians is generally inexact. * * @param angdeg an angle, in degrees * @return the measurement of the angle angdeg * in radians. * @since 1.2 */ public static double toRadians(double angdeg) { return 0.0d; } /** * Converts an angle measured in radians to an approximately * equivalent angle measured in degrees. The conversion from * radians to degrees is generally inexact; users should * not expect cos(toRadians(90.0)) to exactly * equal 0.0. * * @param angrad an angle, in radians * @return the measurement of the angle angrad * in degrees. * @since 1.2 */ public static double toDegrees(double angrad) { return 0.0d; } /** * Returns Euler's number e raised to the power of a * double value. Special cases: *

  • If the argument is NaN, the result is NaN. *
  • If the argument is positive infinity, then the result is * positive infinity. *
  • If the argument is negative infinity, then the result is * positive zero.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a the exponent to raise e to. * @return the value ea, * where e is the base of the natural logarithms. */ public static double exp(double a) { return 0.0d; } /** * Returns the natural logarithm (base e) of a double * value. Special cases: *

  • If the argument is NaN or less than zero, then the result * is NaN. *
  • If the argument is positive infinity, then the result is * positive infinity. *
  • If the argument is positive zero or negative zero, then the * result is negative infinity.
*

* A result must be within 1 ulp of the correctly rounded result. Results * must be semi-monotonic. * * @param a a number greater than 0.0. * @return the value ln a, the natural logarithm of * a. */ public static double log(double a) { return 0.0d; } /** * Returns the correctly rounded positive square root of a * double value. * Special cases: *

  • If the argument is NaN or less than zero, then the result * is NaN. *
  • If the argument is positive infinity, then the result is positive * infinity. *
  • If the argument is positive zero or negative zero, then the * result is the same as the argument.
* Otherwise, the result is the double value closest to * the true mathematical square root of the argument value. * * @param a a value. * * @return the positive square root of a. * If the argument is NaN or less than zero, the result is NaN. */ public static double sqrt(double a) { return 0.0d; } /** * Computes the remainder operation on two arguments as prescribed * by the IEEE 754 standard. * The remainder value is mathematically equal to * f1 - f2 × n, * where n is the mathematical integer closest to the exact * mathematical value of the quotient f1/f2, and if two * mathematical integers are equally close to f1/f2, * then n is the integer that is even. If the remainder is * zero, its sign is the same as the sign of the first argument. * Special cases: *
  • If either argument is NaN, or the first argument is infinite, * or the second argument is positive zero or negative zero, then the * result is NaN. *
  • If the first argument is finite and the second argument is * infinite, then the result is the same as the first argument.
* * @param f1 the dividend. * @param f2 the divisor. * @return the remainder when f1 is divided by * f2. */ public static double IEEEremainder(double f1, double f2) { return 0.0d; } /** * Returns the smallest (closest to negative infinity) * double value that is not less than the argument and is * equal to a mathematical integer. Special cases: *
  • If the argument value is already equal to a mathematical * integer, then the result is the same as the argument. *
  • If the argument is NaN or an infinity or positive zero or negative * zero, then the result is the same as the argument. *
  • If the argument value is less than zero but greater than -1.0, * then the result is negative zero.
* Note that the value of Math.ceil(x) is exactly the * value of -Math.floor(-x). * * @param a a value. * * @return the smallest (closest to negative infinity) * floating-point value that is not less than the argument * and is equal to a mathematical integer. */ public static double ceil(double a) { return 0.0d; } /** * Returns the largest (closest to positive infinity) * double value that is not greater than the argument and * is equal to a mathematical integer. Special cases: *
  • If the argument value is already equal to a mathematical * integer, then the result is the same as the argument. *
  • If the argument is NaN or an infinity or positive zero or * negative zero, then the result is the same as the argument.
* * @param a a value. * * @return the largest (closest to positive infinity) * floating-point value that is not greater than the argument * and is equal to a mathematical integer. */ public static double floor(double a) { return 0.0d; } /** * Returns the double value that is closest in value * to the argument and is equal to a mathematical integer. If two * double values that are mathematical integers are * equally close, the result is the integer value that is * even. Special cases: *
  • If the argument value is already equal to a mathematical * integer, then the result is the same as the argument. *
  • If the argument is NaN or an infinity or positive zero or negative * zero, then the result is the same as the argument.
* * @param a a double value. * @return the closest floating-point value to a that is * equal to a mathematical integer. */ public static double rint(double a) { return 0.0d; } /** * Converts rectangular coordinates (xy) * to polar (r, theta). * This method computes the phase theta by computing an arc tangent * of y/x in the range of -pi to pi. Special * cases: *
  • If either argument is NaN, then the result is NaN. *
  • If the first argument is positive zero and the second argument * is positive, or the first argument is positive and finite and the * second argument is positive infinity, then the result is positive * zero. *
  • If the first argument is negative zero and the second argument * is positive, or the first argument is negative and finite and the * second argument is positive infinity, then the result is negative zero. *
  • If the first argument is positive zero and the second argument * is negative, or the first argument is positive and finite and the * second argument is negative infinity, then the result is the * double value closest to pi. *
  • If the first argument is negative zero and the second argument * is negative, or the first argument is negative and finite and the * second argument is negative infinity, then the result is the * double value closest to -pi. *
  • If the first argument is positive and the second argument is * positive zero or negative zero, or the first argument is positive * infinity and the second argument is finite, then the result is the * double value closest to pi/2. *
  • If the first argument is negative and the second argument is * positive zero or negative zero, or the first argument is negative * infinity and the second argument is finite, then the result is the * double value closest to -pi/2. *
  • If both arguments are positive infinity, then the result is the * double value closest to pi/4. *
  • If the first argument is positive infinity and the second argument * is negative infinity, then the result is the double * value closest to 3*pi/4. *
  • If the first argument is negative infinity and the second argument * is positive infinity, then the result is the double value * closest to -pi/4. *
  • If both arguments are negative infinity, then the result is the * double value closest to -3*pi/4.
*

* A result must be within 2 ulps of the correctly rounded result. Results * must be semi-monotonic. * * @param y the ordinate coordinate * @param x the abscissa coordinate * @return the theta component of the point * (rtheta) * in polar coordinates that corresponds to the point * (xy) in Cartesian coordinates. */ public static double atan2(double y, double x) { return 0.0d; } /** * Returns the value of the first argument raised to the power of the * second argument. Special cases: * *

  • If the second argument is positive or negative zero, then the * result is 1.0. *
  • If the second argument is 1.0, then the result is the same as the * first argument. *
  • If the second argument is NaN, then the result is NaN. *
  • If the first argument is NaN and the second argument is nonzero, * then the result is NaN. * *
  • If *
      *
    • the absolute value of the first argument is greater than 1 * and the second argument is positive infinity, or *
    • the absolute value of the first argument is less than 1 and * the second argument is negative infinity, *
    * then the result is positive infinity. * *
  • If *
      *
    • the absolute value of the first argument is greater than 1 and * the second argument is negative infinity, or *
    • the absolute value of the * first argument is less than 1 and the second argument is positive * infinity, *
    * then the result is positive zero. * *
  • If the absolute value of the first argument equals 1 and the * second argument is infinite, then the result is NaN. * *
  • If *
      *
    • the first argument is positive zero and the second argument * is greater than zero, or *
    • the first argument is positive infinity and the second * argument is less than zero, *
    * then the result is positive zero. * *
  • If *
      *
    • the first argument is positive zero and the second argument * is less than zero, or *
    • the first argument is positive infinity and the second * argument is greater than zero, *
    * then the result is positive infinity. * *
  • If *
      *
    • the first argument is negative zero and the second argument * is greater than zero but not a finite odd integer, or *
    • the first argument is negative infinity and the second * argument is less than zero but not a finite odd integer, *
    * then the result is positive zero. * *
  • If *
      *
    • the first argument is negative zero and the second argument * is a positive finite odd integer, or *
    • the first argument is negative infinity and the second * argument is a negative finite odd integer, *
    * then the result is negative zero. * *
  • If *
      *
    • the first argument is negative zero and the second argument * is less than zero but not a finite odd integer, or *
    • the first argument is negative infinity and the second * argument is greater than zero but not a finite odd integer, *
    * then the result is positive infinity. * *
  • If *
      *
    • the first argument is negative zero and the second argument * is a negative finite odd integer, or *
    • the first argument is negative infinity and the second * argument is a positive finite odd integer, *
    * then the result is negative infinity. * *
  • If the first argument is finite and less than zero *
      *
    • if the second argument is a finite even integer, the * result is equal to the result of raising the absolute value of * the first argument to the power of the second argument * *
    • if the second argument is a finite odd integer, the result * is equal to the negative of the result of raising the absolute * value of the first argument to the power of the second * argument * *
    • if the second argument is finite and not an integer, then * the result is NaN. *
    * *
  • If both arguments are integers, then the result is exactly equal * to the mathematical result of raising the first argument to the power * of the second argument if that result can in fact be represented * exactly as a double value.
* *

(In the foregoing descriptions, a floating-point value is * considered to be an integer if and only if it is finite and a * fixed point of the method {@link #ceil ceil} or, * equivalently, a fixed point of the method {@link #floor * floor}. A value is a fixed point of a one-argument * method if and only if the result of applying the method to the * value is equal to the value.) * *

A result must be within 1 ulp of the correctly rounded * result. Results must be semi-monotonic. * * @param a the base. * @param b the exponent. * @return the value ab. */ public static double pow(double a, double b) { return 0.0d; } /** * Returns the closest int to the argument. The * result is rounded to an integer by adding 1/2, taking the * floor of the result, and casting the result to type int. * In other words, the result is equal to the value of the expression: *

(int)Math.floor(a + 0.5f)
*

* Special cases: *

  • If the argument is NaN, the result is 0. *
  • If the argument is negative infinity or any value less than or * equal to the value of Integer.MIN_VALUE, the result is * equal to the value of Integer.MIN_VALUE. *
  • If the argument is positive infinity or any value greater than or * equal to the value of Integer.MAX_VALUE, the result is * equal to the value of Integer.MAX_VALUE.
* * @param a a floating-point value to be rounded to an integer. * @return the value of the argument rounded to the nearest * int value. * @see java.lang.Integer#MAX_VALUE * @see java.lang.Integer#MIN_VALUE */ public static int round(float a) { return 0; } /** * Returns the closest long to the argument. The result * is rounded to an integer by adding 1/2, taking the floor of the * result, and casting the result to type long. In other * words, the result is equal to the value of the expression: *

(long)Math.floor(a + 0.5d)
*

* Special cases: *

  • If the argument is NaN, the result is 0. *
  • If the argument is negative infinity or any value less than or * equal to the value of Long.MIN_VALUE, the result is * equal to the value of Long.MIN_VALUE. *
  • If the argument is positive infinity or any value greater than or * equal to the value of Long.MAX_VALUE, the result is * equal to the value of Long.MAX_VALUE.
* * @param a a floating-point value to be rounded to a * long. * @return the value of the argument rounded to the nearest * long value. * @see java.lang.Long#MAX_VALUE * @see java.lang.Long#MIN_VALUE */ public static long round(double a) { return -1; } /** * Returns a double value with a positive sign, greater * than or equal to 0.0 and less than 1.0. * Returned values are chosen pseudorandomly with (approximately) * uniform distribution from that range. *

* When this method is first called, it creates a single new * pseudorandom-number generator, exactly as if by the expression *

new java.util.Random
* This new pseudorandom-number generator is used thereafter for all * calls to this method and is used nowhere else. *

* This method is properly synchronized to allow correct use by more * than one thread. However, if many threads need to generate * pseudorandom numbers at a great rate, it may reduce contention for * each thread to have its own pseudorandom-number generator. * * @return a pseudorandom double greater than or equal * to 0.0 and less than 1.0. * @see java.util.Random#nextDouble() */ public static double random() { return 0.0d; } /** * Returns the absolute value of an int value. * If the argument is not negative, the argument is returned. * If the argument is negative, the negation of the argument is returned. *

* Note that if the argument is equal to the value of * Integer.MIN_VALUE, the most negative representable * int value, the result is that same value, which is * negative. * * @param a the argument whose absolute value is to be determined * @return the absolute value of the argument. * @see java.lang.Integer#MIN_VALUE */ public static int abs(int a) { return 0; } /** * Returns the absolute value of a long value. * If the argument is not negative, the argument is returned. * If the argument is negative, the negation of the argument is returned. *

* Note that if the argument is equal to the value of * Long.MIN_VALUE, the most negative representable * long value, the result is that same value, which is * negative. * * @param a the argument whose absolute value is to be determined * @return the absolute value of the argument. * @see java.lang.Long#MIN_VALUE */ public static long abs(long a) { return -1; } /** * Returns the absolute value of a float value. * If the argument is not negative, the argument is returned. * If the argument is negative, the negation of the argument is returned. * Special cases: *

  • If the argument is positive zero or negative zero, the * result is positive zero. *
  • If the argument is infinite, the result is positive infinity. *
  • If the argument is NaN, the result is NaN.
* In other words, the result is the same as the value of the expression: *

Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))
* * @param a the argument whose absolute value is to be determined * @return the absolute value of the argument. */ public static float abs(float a) { return 0.0f; } /** * Returns the absolute value of a double value. * If the argument is not negative, the argument is returned. * If the argument is negative, the negation of the argument is returned. * Special cases: *
  • If the argument is positive zero or negative zero, the result * is positive zero. *
  • If the argument is infinite, the result is positive infinity. *
  • If the argument is NaN, the result is NaN.
* In other words, the result is the same as the value of the expression: *

Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1) * * @param a the argument whose absolute value is to be determined * @return the absolute value of the argument. */ public static double abs(double a) { return 0.0d; } /** * Returns the greater of two int values. That is, the * result is the argument closer to the value of * Integer.MAX_VALUE. If the arguments have the same value, * the result is that same value. * * @param a an argument. * @param b another argument. * @return the larger of a and b. * @see java.lang.Long#MAX_VALUE */ public static int max(int a, int b) { return 0; } /** * Returns the greater of two long values. That is, the * result is the argument closer to the value of * Long.MAX_VALUE. If the arguments have the same value, * the result is that same value. * * @param a an argument. * @param b another argument. * @return the larger of a and b. * @see java.lang.Long#MAX_VALUE */ public static long max(long a, long b) { return -1; } /** * Returns the greater of two float values. That is, * the result is the argument closer to positive infinity. If the * arguments have the same value, the result is that same * value. If either value is NaN, then the result is NaN. Unlike * the the numerical comparison operators, this method considers * negative zero to be strictly smaller than positive zero. If one * argument is positive zero and the other negative zero, the * result is positive zero. * * @param a an argument. * @param b another argument. * @return the larger of a and b. */ public static float max(float a, float b) { return 0.0f; } /** * Returns the greater of two double values. That * is, the result is the argument closer to positive infinity. If * the arguments have the same value, the result is that same * value. If either value is NaN, then the result is NaN. Unlike * the the numerical comparison operators, this method considers * negative zero to be strictly smaller than positive zero. If one * argument is positive zero and the other negative zero, the * result is positive zero. * * @param a an argument. * @param b another argument. * @return the larger of a and b. */ public static double max(double a, double b) { return 0.0d; } /** * Returns the smaller of two int values. That is, * the result the argument closer to the value of * Integer.MIN_VALUE. If the arguments have the same * value, the result is that same value. * * @param a an argument. * @param b another argument. * @return the smaller of a and b. * @see java.lang.Long#MIN_VALUE */ public static int min(int a, int b) { return 0; } /** * Returns the smaller of two long values. That is, * the result is the argument closer to the value of * Long.MIN_VALUE. If the arguments have the same * value, the result is that same value. * * @param a an argument. * @param b another argument. * @return the smaller of a and b. * @see java.lang.Long#MIN_VALUE */ public static long min(long a, long b) { return -1; } /** * Returns the smaller of two float values. That is, * the result is the value closer to negative infinity. If the * arguments have the same value, the result is that same * value. If either value is NaN, then the result is NaN. Unlike * the the numerical comparison operators, this method considers * negative zero to be strictly smaller than positive zero. If * one argument is positive zero and the other is negative zero, * the result is negative zero. * * @param a an argument. * @param b another argument. * @return the smaller of a and b. */ public static float min(float a, float b) { return 0.0f; } /** * Returns the smaller of two double values. That * is, the result is the value closer to negative infinity. If the * arguments have the same value, the result is that same * value. If either value is NaN, then the result is NaN. Unlike * the the numerical comparison operators, this method considers * negative zero to be strictly smaller than positive zero. If one * argument is positive zero and the other is negative zero, the * result is negative zero. * * @param a an argument. * @param b another argument. * @return the smaller of a and b. */ public static double min(double a, double b) { return 0.0d; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy