1 *java.lang.Math* *Math* The class Math contains methods for performing basic
4 public final class Math
5 extends |java.lang.Object|
7 |java.lang.Math_Description|
8 |java.lang.Math_Fields|
9 |java.lang.Math_Constructors|
10 |java.lang.Math_Methods|
12 ================================================================================
14 *java.lang.Math_Fields*
15 |double_java.lang.Math.E|
16 |double_java.lang.Math.PI|
18 *java.lang.Math_Methods*
19 |java.lang.Math.abs(double)|Returns the absolute value of a double value.
20 |java.lang.Math.abs(float)|Returns the absolute value of a float value.
21 |java.lang.Math.abs(int)|Returns the absolute value of an int value.
22 |java.lang.Math.abs(long)|Returns the absolute value of a long value.
23 |java.lang.Math.acos(double)|Returns the arc cosine of a value; the returned an
24 |java.lang.Math.asin(double)|Returns the arc sine of a value; the returned angl
25 |java.lang.Math.atan(double)|Returns the arc tangent of a value; the returned a
26 |java.lang.Math.atan2(double,double)|Returns the angle theta from the conversio
27 |java.lang.Math.cbrt(double)|Returns the cube root of a double value.
28 |java.lang.Math.ceil(double)|Returns the smallest (closest to negative infinity
29 |java.lang.Math.copySign(double,double)|Returns the first floating-point argume
30 |java.lang.Math.copySign(float,float)|Returns the first floating-point argument
31 |java.lang.Math.cos(double)|Returns the trigonometric cosine of an angle.
32 |java.lang.Math.cosh(double)|Returns the hyperbolic cosine of a double value.
33 |java.lang.Math.exp(double)|Returns Euler's number e raised to the power of a
34 |java.lang.Math.expm1(double)|Returns ex-1.
35 |java.lang.Math.floor(double)|Returns the largest (closest to positive infinity
36 |java.lang.Math.getExponent(double)|Returns the unbiased exponent used in the r
37 |java.lang.Math.getExponent(float)|Returns the unbiased exponent used in the re
38 |java.lang.Math.hypot(double,double)|Returns sqrt(x2+y2) without intermediate
39 |java.lang.Math.IEEEremainder(double,double)|Computes the remainder operation o
40 |java.lang.Math.log(double)|Returns the natural logarithm (base e) of a double
41 |java.lang.Math.log10(double)|Returns the base 10 logarithm of a double value.
42 |java.lang.Math.log1p(double)|Returns the natural logarithm of the sum of the a
43 |java.lang.Math.max(double,double)|Returns the greater of two double values.
44 |java.lang.Math.max(float,float)|Returns the greater of two float values.
45 |java.lang.Math.max(int,int)|Returns the greater of two int values.
46 |java.lang.Math.max(long,long)|Returns the greater of two long values.
47 |java.lang.Math.min(double,double)|Returns the smaller of two double values.
48 |java.lang.Math.min(float,float)|Returns the smaller of two float values.
49 |java.lang.Math.min(int,int)|Returns the smaller of two int values.
50 |java.lang.Math.min(long,long)|Returns the smaller of two long values.
51 |java.lang.Math.nextAfter(double,double)|Returns the floating-point number adja
52 |java.lang.Math.nextAfter(float,double)|Returns the floating-point number adjac
53 |java.lang.Math.nextUp(double)|Returns the floating-point value adjacent todin
54 |java.lang.Math.nextUp(float)|Returns the floating-point value adjacent tofin
55 |java.lang.Math.pow(double,double)|Returns the value of the first argument rais
56 |java.lang.Math.random()|Returns a double value with a positive sign, greater
57 |java.lang.Math.rint(double)|Returns the double value that is closest in value
58 |java.lang.Math.round(double)|Returns the closest long to the argument.
59 |java.lang.Math.round(float)|Returns the closest int to the argument.
60 |java.lang.Math.scalb(double,int)|Returnd 2scaleFactor rounded as if performed
61 |java.lang.Math.scalb(float,int)|Returnf 2scaleFactor rounded as if performed
62 |java.lang.Math.signum(double)|Returns the signum function of the argument; zer
63 |java.lang.Math.signum(float)|Returns the signum function of the argument; zero
64 |java.lang.Math.sin(double)|Returns the trigonometric sine of an angle.
65 |java.lang.Math.sinh(double)|Returns the hyperbolic sine of a double value.
66 |java.lang.Math.sqrt(double)|Returns the correctly rounded positive square root
67 |java.lang.Math.tan(double)|Returns the trigonometric tangent of an angle.
68 |java.lang.Math.tanh(double)|Returns the hyperbolic tangent of a double value.
69 |java.lang.Math.toDegrees(double)|Converts an angle measured in radians to an a
70 |java.lang.Math.toRadians(double)|Converts an angle measured in degrees to an a
71 |java.lang.Math.ulp(double)|Returns the size of an ulp of the argument.
72 |java.lang.Math.ulp(float)|Returns the size of an ulp of the argument.
74 *java.lang.Math_Description*
76 The class Math contains methods for performing basic numeric operations such as
77 the elementary exponential, logarithm, square root, and trigonometric
80 Unlike some of the numeric methods of class StrictMath, all implementations of
81 the equivalent functions of class Math are not defined to return the
82 bit-for-bit same results. This relaxation permits better-performing
83 implementations where strict reproducibility is not required.
85 By default many of the Math methods simply call the equivalent method in
86 StrictMath for their implementation. Code generators are encouraged to use
87 platform-specific native libraries or microprocessor instructions, where
88 available, to provide higher-performance implementations of Math methods. Such
89 higher-performance implementations still must conform to the specification for
92 The quality of implementation specifications concern two properties, accuracy
93 of the returned result and monotonicity of the method. Accuracy of the
94 floating-point Math methods is measured in terms of ulps, units in the last
95 place. For a given floating-point format, an ulp of a specific real number
96 value is the distance between the two floating-point values bracketing that
97 numerical value. When discussing the accuracy of a method as a whole rather
98 than at a specific argument, the number of ulps cited is for the worst-case
99 error at any argument. If a method always has an error less than 0.5 ulps, the
100 method always returns the floating-point number nearest the exact result; such
101 a method is correctly rounded. A correctly rounded method is generally the best
102 a floating-point approximation can be; however, it is impractical for many
103 floating-point methods to be correctly rounded. Instead, for the Math class, a
104 larger error bound of 1 or 2 ulps is allowed for certain methods. Informally,
105 with a 1 ulp error bound, when the exact result is a representable number, the
106 exact result should be returned as the computed result; otherwise, either of
107 the two floating-point values which bracket the exact result may be returned.
108 For exact results large in magnitude, one of the endpoints of the bracket may
109 be infinite. Besides accuracy at individual arguments, maintaining proper
110 relations between the method at different arguments is also important.
111 Therefore, most methods with more than 0.5 ulp errors are required to be
112 semi-monotonic: whenever the mathematical function is non-decreasing, so is the
113 floating-point approximation, likewise, whenever the mathematical function is
114 non-increasing, so is the floating-point approximation. Not all approximations
115 that have 1 ulp accuracy will automatically meet the monotonicity requirements.
119 *double_java.lang.Math.E*
121 The double value that is closer than any other to e, the base of the natural
125 *double_java.lang.Math.PI*
127 The double value that is closer than any other to pi, the ratio of the
128 circumference of a circle to its diameter.
132 *java.lang.Math.abs(double)*
134 public static double abs(double a)
136 Returns the absolute value of a double value. If the argument is not negative,
137 the argument is returned. If the argument is negative, the negation of the
138 argument is returned. Special cases: If the argument is positive zero or
139 negative zero, the result is positive zero. If the argument is infinite, the
140 result is positive infinity. If the argument is NaN, the result is NaN. In
141 other words, the result is the same as the value of the expression:
142 Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)
145 a - the argument whose absolute value is to be determined
147 Returns: the absolute value of the argument.
149 *java.lang.Math.abs(float)*
151 public static float abs(float a)
153 Returns the absolute value of a float value. If the argument is not negative,
154 the argument is returned. If the argument is negative, the negation of the
155 argument is returned. Special cases: If the argument is positive zero or
156 negative zero, the result is positive zero. If the argument is infinite, the
157 result is positive infinity. If the argument is NaN, the result is NaN. In
158 other words, the result is the same as the value of the expression:
160 Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))
163 a - the argument whose absolute value is to be determined
165 Returns: the absolute value of the argument.
167 *java.lang.Math.abs(int)*
169 public static int abs(int a)
171 Returns the absolute value of an int value. If the argument is not negative,
172 the argument is returned. If the argument is negative, the negation of the
173 argument is returned.
175 Note that if the argument is equal to the value of Integer.MIN_VALUE, the most
176 negative representable int value, the result is that same value, which is
180 a - the argument whose absolute value is to be determined
182 Returns: the absolute value of the argument.
184 *java.lang.Math.abs(long)*
186 public static long abs(long a)
188 Returns the absolute value of a long value. If the argument is not negative,
189 the argument is returned. If the argument is negative, the negation of the
190 argument is returned.
192 Note that if the argument is equal to the value of Long.MIN_VALUE, the most
193 negative representable long value, the result is that same value, which is
197 a - the argument whose absolute value is to be determined
199 Returns: the absolute value of the argument.
201 *java.lang.Math.acos(double)*
203 public static double acos(double a)
205 Returns the arc cosine of a value; the returned angle is in the range 0.0
206 through pi. Special case: If the argument is NaN or its absolute value is
207 greater than 1, then the result is NaN.
209 The computed result must be within 1 ulp of the exact result. Results must be
213 a - the value whose arc cosine is to be returned.
215 Returns: the arc cosine of the argument.
217 *java.lang.Math.asin(double)*
219 public static double asin(double a)
221 Returns the arc sine of a value; the returned angle is in the range -pi/2
222 through pi/2. Special cases: If the argument is NaN or its absolute value is
223 greater than 1, then the result is NaN. If the argument is zero, then the
224 result is a zero with the same sign as the argument.
226 The computed result must be within 1 ulp of the exact result. Results must be
230 a - the value whose arc sine is to be returned.
232 Returns: the arc sine of the argument.
234 *java.lang.Math.atan(double)*
236 public static double atan(double a)
238 Returns the arc tangent of a value; the returned angle is in the range -pi/2
239 through pi/2. Special cases: If the argument is NaN, then the result is NaN. If
240 the argument is zero, then the result is a zero with the same sign as the
243 The computed result must be within 1 ulp of the exact result. Results must be
247 a - the value whose arc tangent is to be returned.
249 Returns: the arc tangent of the argument.
251 *java.lang.Math.atan2(double,double)*
253 public static double atan2(
257 Returns the angle theta from the conversion of rectangular coordinates (x,y) to
258 polar coordinates (r,theta). This method computes the phase theta by computing
259 an arc tangent of y/x in the range of -pi to pi. Special cases: If either
260 argument is NaN, then the result is NaN. If the first argument is positive zero
261 and the second argument is positive, or the first argument is positive and
262 finite and the second argument is positive infinity, then the result is
263 positive zero. If the first argument is negative zero and the second argument
264 is positive, or the first argument is negative and finite and the second
265 argument is positive infinity, then the result is negative zero. If the first
266 argument is positive zero and the second argument is negative, or the first
267 argument is positive and finite and the second argument is negative infinity,
268 then the result is the double value closest to pi. If the first argument is
269 negative zero and the second argument is negative, or the first argument is
270 negative and finite and the second argument is negative infinity, then the
271 result is the double value closest to -pi. If the first argument is positive
272 and the second argument is positive zero or negative zero, or the first
273 argument is positive infinity and the second argument is finite, then the
274 result is the double value closest to pi/2. If the first argument is negative
275 and the second argument is positive zero or negative zero, or the first
276 argument is negative infinity and the second argument is finite, then the
277 result is the double value closest to -pi/2. If both arguments are positive
278 infinity, then the result is the double value closest to pi/4. If the first
279 argument is positive infinity and the second argument is negative infinity,
280 then the result is the double value closest to 3*pi/4. If the first argument is
281 negative infinity and the second argument is positive infinity, then the result
282 is the double value closest to -pi/4. If both arguments are negative infinity,
283 then the result is the double value closest to -3*pi/4.
285 The computed result must be within 2 ulps of the exact result. Results must be
289 y - the ordinate coordinate
290 x - the abscissa coordinate
292 Returns: the theta component of the point (r,theta) in polar coordinates that
293 corresponds to the point (x,y) in Cartesian coordinates.
295 *java.lang.Math.cbrt(double)*
297 public static double cbrt(double a)
299 Returns the cube root of a double value. For positive finite x, cbrt(-x) ==
300 -cbrt(x); that is, the cube root of a negative value is the negative of the
301 cube root of that value's magnitude.
307 If the argument is NaN, then the result is NaN.
309 If the argument is infinite, then the result is an infinity with the same sign
312 If the argument is zero, then the result is a zero with the same sign as the
317 The computed result must be within 1 ulp of the exact result.
322 Returns: the cube root of a.
324 *java.lang.Math.ceil(double)*
326 public static double ceil(double a)
328 Returns the smallest (closest to negative infinity) double value that is
329 greater than or equal to the argument and is equal to a mathematical integer.
330 Special cases: If the argument value is already equal to a mathematical
331 integer, then the result is the same as the argument. If the argument is NaN or
332 an infinity or positive zero or negative zero, then the result is the same as
333 the argument. If the argument value is less than zero but greater than -1.0,
334 then the result is negative zero. Note that the value of Math.ceil(x) is
335 exactly the value of -Math.floor(-x).
340 Returns: the smallest (closest to negative infinity) floating-point value that is
341 greater than or equal to the argument and is equal to a
342 mathematical integer.
344 *java.lang.Math.copySign(double,double)*
346 public static double copySign(
350 Returns the first floating-point argument with the sign of the second
351 floating-point argument. Note that unlike the
352 StrictMath.copySign(|java.lang.StrictMath|) method, this method does not
353 require NaN sign arguments to be treated as positive values; implementations
354 are permitted to treat some NaN arguments as positive and other NaN arguments
355 as negative to allow greater performance.
358 magnitude - the parameter providing the magnitude of the result
359 sign - the parameter providing the sign of the result
361 Returns: a value with the magnitude of magnitude and the sign of sign.
363 *java.lang.Math.copySign(float,float)*
365 public static float copySign(
369 Returns the first floating-point argument with the sign of the second
370 floating-point argument. Note that unlike the
371 StrictMath.copySign(|java.lang.StrictMath|) method, this method does not
372 require NaN sign arguments to be treated as positive values; implementations
373 are permitted to treat some NaN arguments as positive and other NaN arguments
374 as negative to allow greater performance.
377 magnitude - the parameter providing the magnitude of the result
378 sign - the parameter providing the sign of the result
380 Returns: a value with the magnitude of magnitude and the sign of sign.
382 *java.lang.Math.cos(double)*
384 public static double cos(double a)
386 Returns the trigonometric cosine of an angle. Special cases: If the argument is
387 NaN or an infinity, then the result is NaN.
389 The computed result must be within 1 ulp of the exact result. Results must be
393 a - an angle, in radians.
395 Returns: the cosine of the argument.
397 *java.lang.Math.cosh(double)*
399 public static double cosh(double x)
401 Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is
402 defined to be (ex+e-x)/2 where e is Euler's number(|java.lang.Math|) .
406 If the argument is NaN, then the result is NaN.
408 If the argument is infinite, then the result is positive infinity.
410 If the argument is zero, then the result is 1.0.
414 The computed result must be within 2.5 ulps of the exact result.
417 x - The number whose hyperbolic cosine is to be returned.
419 Returns: The hyperbolic cosine of x.
421 *java.lang.Math.exp(double)*
423 public static double exp(double a)
425 Returns Euler's number e raised to the power of a double value. Special cases:
426 If the argument is NaN, the result is NaN. If the argument is positive
427 infinity, then the result is positive infinity. If the argument is negative
428 infinity, then the result is positive zero.
430 The computed result must be within 1 ulp of the exact result. Results must be
434 a - the exponent to raise e to.
436 Returns: the value ea, where e is the base of the natural logarithms.
438 *java.lang.Math.expm1(double)*
440 public static double expm1(double x)
442 Returns ex-1. Note that for values of x near 0, the exact sum of expm1(x)+1 is
443 much closer to the true result of ex than exp(x).
447 If the argument is NaN, the result is NaN.
449 If the argument is positive infinity, then the result is positive infinity.
451 If the argument is negative infinity, then the result is -1.0.
453 If the argument is zero, then the result is a zero with the same sign as the
458 The computed result must be within 1 ulp of the exact result. Results must be
459 semi-monotonic. The result of expm1 for any finite input must be greater than
460 or equal to -1.0. Note that once the exact result of ex-1 is within 1/2 ulp of
461 the limit value -1, -1.0 should be returned.
464 x - the exponent to raise e to in the computation of ex-1.
466 Returns: the value ex-1.
468 *java.lang.Math.floor(double)*
470 public static double floor(double a)
472 Returns the largest (closest to positive infinity) double value that is less
473 than or equal to the argument and is equal to a mathematical integer. Special
474 cases: If the argument value is already equal to a mathematical integer, then
475 the result is the same as the argument. If the argument is NaN or an infinity
476 or positive zero or negative zero, then the result is the same as the argument.
481 Returns: the largest (closest to positive infinity) floating-point value that less than
482 or equal to the argument and is equal to a mathematical integer.
484 *java.lang.Math.getExponent(double)*
486 public static int getExponent(double d)
488 Returns the unbiased exponent used in the representation of adouble. Special
491 If the argument is NaN or infinite, then the result is (|java.lang.Double|) +
492 1. If the argument is zero or subnormal, then the result is
493 (|java.lang.Double|) -1.
496 d - a {@code double} value
498 Returns: the unbiased exponent of the argument
500 *java.lang.Math.getExponent(float)*
502 public static int getExponent(float f)
504 Returns the unbiased exponent used in the representation of afloat. Special
507 If the argument is NaN or infinite, then the result is (|java.lang.Float|) + 1.
508 If the argument is zero or subnormal, then the result is (|java.lang.Float|)
512 f - a {@code float} value
514 Returns: the unbiased exponent of the argument
516 *java.lang.Math.hypot(double,double)*
518 public static double hypot(
522 Returns sqrt(x2+y2) without intermediate overflow or underflow.
526 If either argument is infinite, then the result is positive infinity.
528 If either argument is NaN and neither argument is infinite, then the result is
533 The computed result must be within 1 ulp of the exact result. If one parameter
534 is held constant, the results must be semi-monotonic in the other parameter.
540 Returns: sqrt(x2+y2) without intermediate overflow or underflow
542 *java.lang.Math.IEEEremainder(double,double)*
544 public static double IEEEremainder(
548 Computes the remainder operation on two arguments as prescribed by the IEEE 754
549 standard. The remainder value is mathematically equal to f1-f2n, where n is the
550 mathematical integer closest to the exact mathematical value of the quotient
551 f1/f2, and if two mathematical integers are equally close to f1/f2, then n is
552 the integer that is even. If the remainder is zero, its sign is the same as the
553 sign of the first argument. Special cases: If either argument is NaN, or the
554 first argument is infinite, or the second argument is positive zero or negative
555 zero, then the result is NaN. If the first argument is finite and the second
556 argument is infinite, then the result is the same as the first argument.
562 Returns: the remainder when f1 is divided by f2.
564 *java.lang.Math.log(double)*
566 public static double log(double a)
568 Returns the natural logarithm (base e) of a double value. Special cases: If the
569 argument is NaN or less than zero, then the result is NaN. If the argument is
570 positive infinity, then the result is positive infinity. If the argument is
571 positive zero or negative zero, then the result is negative infinity.
573 The computed result must be within 1 ulp of the exact result. Results must be
579 Returns: the value lna, the natural logarithm of a.
581 *java.lang.Math.log10(double)*
583 public static double log10(double a)
585 Returns the base 10 logarithm of a double value. Special cases:
587 If the argument is NaN or less than zero, then the result is NaN. If the
588 argument is positive infinity, then the result is positive infinity. If the
589 argument is positive zero or negative zero, then the result is negative
590 infinity. If the argument is equal to 10n for integer n, then the result is n.
592 The computed result must be within 1 ulp of the exact result. Results must be
598 Returns: the base 10 logarithm of a.
600 *java.lang.Math.log1p(double)*
602 public static double log1p(double x)
604 Returns the natural logarithm of the sum of the argument and 1. Note that for
605 small values x, the result of log1p(x) is much closer to the true result of
606 ln(1 + x) than the floating-point evaluation of log(1.0+x).
612 If the argument is NaN or less than -1, then the result is NaN.
614 If the argument is positive infinity, then the result is positive infinity.
616 If the argument is negative one, then the result is negative infinity.
618 If the argument is zero, then the result is a zero with the same sign as the
623 The computed result must be within 1 ulp of the exact result. Results must be
629 Returns: the value ln(x+1), the natural log of x+1
631 *java.lang.Math.max(double,double)*
633 public static double max(
637 Returns the greater of two double values. That is, the result is the argument
638 closer to positive infinity. If the arguments have the same value, the result
639 is that same value. If either value is NaN, then the result is NaN. Unlike the
640 numerical comparison operators, this method considers negative zero to be
641 strictly smaller than positive zero. If one argument is positive zero and the
642 other negative zero, the result is positive zero.
646 b - another argument.
648 Returns: the larger of a and b.
650 *java.lang.Math.max(float,float)*
652 public static float max(
656 Returns the greater of two float values. That is, the result is the argument
657 closer to positive infinity. If the arguments have the same value, the result
658 is that same value. If either value is NaN, then the result is NaN. Unlike the
659 numerical comparison operators, this method considers negative zero to be
660 strictly smaller than positive zero. If one argument is positive zero and the
661 other negative zero, the result is positive zero.
665 b - another argument.
667 Returns: the larger of a and b.
669 *java.lang.Math.max(int,int)*
671 public static int max(
675 Returns the greater of two int values. That is, the result is the argument
676 closer to the value of Integer.MAX_VALUE. If the arguments have the same value,
677 the result is that same value.
681 b - another argument.
683 Returns: the larger of a and b.
685 *java.lang.Math.max(long,long)*
687 public static long max(
691 Returns the greater of two long values. That is, the result is the argument
692 closer to the value of Long.MAX_VALUE. If the arguments have the same value,
693 the result is that same value.
697 b - another argument.
699 Returns: the larger of a and b.
701 *java.lang.Math.min(double,double)*
703 public static double min(
707 Returns the smaller of two double values. That is, the result is the value
708 closer to negative infinity. If the arguments have the same value, the result
709 is that same value. If either value is NaN, then the result is NaN. Unlike the
710 numerical comparison operators, this method considers negative zero to be
711 strictly smaller than positive zero. If one argument is positive zero and the
712 other is negative zero, the result is negative zero.
716 b - another argument.
718 Returns: the smaller of a and b.
720 *java.lang.Math.min(float,float)*
722 public static float min(
726 Returns the smaller of two float values. That is, the result is the value
727 closer to negative infinity. If the arguments have the same value, the result
728 is that same value. If either value is NaN, then the result is NaN. Unlike the
729 numerical comparison operators, this method considers negative zero to be
730 strictly smaller than positive zero. If one argument is positive zero and the
731 other is negative zero, the result is negative zero.
735 b - another argument.
737 Returns: the smaller of a and b.
739 *java.lang.Math.min(int,int)*
741 public static int min(
745 Returns the smaller of two int values. That is, the result the argument closer
746 to the value of Integer.MIN_VALUE. If the arguments have the same value, the
747 result is that same value.
751 b - another argument.
753 Returns: the smaller of a and b.
755 *java.lang.Math.min(long,long)*
757 public static long min(
761 Returns the smaller of two long values. That is, the result is the argument
762 closer to the value of Long.MIN_VALUE. If the arguments have the same value,
763 the result is that same value.
767 b - another argument.
769 Returns: the smaller of a and b.
771 *java.lang.Math.nextAfter(double,double)*
773 public static double nextAfter(
777 Returns the floating-point number adjacent to the first argument in the
778 direction of the second argument. If both arguments compare as equal the second
779 argument is returned.
783 If either argument is a NaN, then NaN is returned.
785 If both arguments are signed zeros,directionis returned unchanged (as implied
786 by the requirement of returning the second argument if the arguments compare as
789 Ifstartis (|java.lang.Double|) anddirectionhas a value such that the result
790 should have a smaller magnitude, then a zero with the same sign asstartis
793 Ifstartis infinite anddirectionhas a value such that the result should have a
794 smaller magnitude, (|java.lang.Double|) with the same sign asstartis returned.
796 Ifstartis equal to (|java.lang.Double|) anddirectionhas a value such that the
797 result should have a larger magnitude, an infinity with same sign asstartis
801 start - starting floating-point value
802 direction - value indicating which of {@code start}'s neighbors or {@code start} should be
805 Returns: The floating-point number adjacent to {@code start} in the direction of {@code
808 *java.lang.Math.nextAfter(float,double)*
810 public static float nextAfter(
814 Returns the floating-point number adjacent to the first argument in the
815 direction of the second argument. If both arguments compare as equal a value
816 equivalent to the second argument is returned.
820 If either argument is a NaN, then NaN is returned.
822 If both arguments are signed zeros, a value equivalent todirectionis returned.
824 Ifstartis (|java.lang.Float|) anddirectionhas a value such that the result
825 should have a smaller magnitude, then a zero with the same sign asstartis
828 Ifstartis infinite anddirectionhas a value such that the result should have a
829 smaller magnitude, (|java.lang.Float|) with the same sign asstartis returned.
831 Ifstartis equal to (|java.lang.Float|) anddirectionhas a value such that the
832 result should have a larger magnitude, an infinity with same sign asstartis
836 start - starting floating-point value
837 direction - value indicating which of {@code start}'s neighbors or {@code start} should be
840 Returns: The floating-point number adjacent to {@code start} in the direction of {@code
843 *java.lang.Math.nextUp(double)*
845 public static double nextUp(double d)
847 Returns the floating-point value adjacent todin the direction of positive
848 infinity. This method is semantically equivalent tonextAfter(d,
849 Double.POSITIVE_INFINITY); however, anextUpimplementation may run faster than
850 its equivalentnextAftercall.
854 If the argument is NaN, the result is NaN.
856 If the argument is positive infinity, the result is positive infinity.
858 If the argument is zero, the result is (|java.lang.Double|)
861 d - starting floating-point value
863 Returns: The adjacent floating-point value closer to positive infinity.
865 *java.lang.Math.nextUp(float)*
867 public static float nextUp(float f)
869 Returns the floating-point value adjacent tofin the direction of positive
870 infinity. This method is semantically equivalent tonextAfter(f,
871 Float.POSITIVE_INFINITY); however, anextUpimplementation may run faster than
872 its equivalentnextAftercall.
876 If the argument is NaN, the result is NaN.
878 If the argument is positive infinity, the result is positive infinity.
880 If the argument is zero, the result is (|java.lang.Float|)
883 f - starting floating-point value
885 Returns: The adjacent floating-point value closer to positive infinity.
887 *java.lang.Math.pow(double,double)*
889 public static double pow(
893 Returns the value of the first argument raised to the power of the second
894 argument. Special cases:
896 If the second argument is positive or negative zero, then the result is 1.0. If
897 the second argument is 1.0, then the result is the same as the first argument.
898 If the second argument is NaN, then the result is NaN. If the first argument is
899 NaN and the second argument is nonzero, then the result is NaN.
903 the absolute value of the first argument is greater than 1 and the second
904 argument is positive infinity, or the absolute value of the first argument is
905 less than 1 and the second argument is negative infinity,
907 then the result is positive infinity.
911 the absolute value of the first argument is greater than 1 and the second
912 argument is negative infinity, or the absolute value of the first argument is
913 less than 1 and the second argument is positive infinity,
915 then the result is positive zero.
917 If the absolute value of the first argument equals 1 and the second argument is
918 infinite, then the result is NaN.
922 the first argument is positive zero and the second argument is greater than
923 zero, or the first argument is positive infinity and the second argument is
926 then the result is positive zero.
930 the first argument is positive zero and the second argument is less than zero,
931 or the first argument is positive infinity and the second argument is greater
934 then the result is positive infinity.
938 the first argument is negative zero and the second argument is greater than
939 zero but not a finite odd integer, or the first argument is negative infinity
940 and the second argument is less than zero but not a finite odd integer,
942 then the result is positive zero.
946 the first argument is negative zero and the second argument is a positive
947 finite odd integer, or the first argument is negative infinity and the second
948 argument is a negative finite odd integer,
950 then the result is negative zero.
954 the first argument is negative zero and the second argument is less than zero
955 but not a finite odd integer, or the first argument is negative infinity and
956 the second argument is greater than zero but not a finite odd integer,
958 then the result is positive infinity.
962 the first argument is negative zero and the second argument is a negative
963 finite odd integer, or the first argument is negative infinity and the second
964 argument is a positive finite odd integer,
966 then the result is negative infinity.
968 If the first argument is finite and less than zero
970 if the second argument is a finite even integer, the result is equal to the
971 result of raising the absolute value of the first argument to the power of the
974 if the second argument is a finite odd integer, the result is equal to the
975 negative of the result of raising the absolute value of the first argument to
976 the power of the second argument
978 if the second argument is finite and not an integer, then the result is NaN.
980 If both arguments are integers, then the result is exactly equal to the
981 mathematical result of raising the first argument to the power of the second
982 argument if that result can in fact be represented exactly as a double value.
984 (In the foregoing descriptions, a floating-point value is considered to be an
985 integer if and only if it is finite and a fixed point of the method
986 <tt>ceil</tt>(|java.lang.Math|) or, equivalently, a fixed point of the method
987 <tt>floor</tt>(|java.lang.Math|) . A value is a fixed point of a one-argument
988 method if and only if the result of applying the method to the value is equal
991 The computed result must be within 1 ulp of the exact result. Results must be
998 Returns: the value ab.
1000 *java.lang.Math.random()*
1002 public static double random()
1004 Returns a double value with a positive sign, greater than or equal to 0.0 and
1005 less than 1.0. Returned values are chosen pseudorandomly with (approximately)
1006 uniform distribution from that range.
1008 When this method is first called, it creates a single new pseudorandom-number
1009 generator, exactly as if by the expression
1011 new java.util.Random This new pseudorandom-number generator is used thereafter
1012 for all calls to this method and is used nowhere else.
1014 This method is properly synchronized to allow correct use by more than one
1015 thread. However, if many threads need to generate pseudorandom numbers at a
1016 great rate, it may reduce contention for each thread to have its own
1017 pseudorandom-number generator.
1021 Returns: a pseudorandom double greater than or equal to 0.0 and less than 1.0.
1023 *java.lang.Math.rint(double)*
1025 public static double rint(double a)
1027 Returns the double value that is closest in value to the argument and is equal
1028 to a mathematical integer. If two double values that are mathematical integers
1029 are equally close, the result is the integer value that is even. Special cases:
1030 If the argument value is already equal to a mathematical integer, then the
1031 result is the same as the argument. If the argument is NaN or an infinity or
1032 positive zero or negative zero, then the result is the same as the argument.
1037 Returns: the closest floating-point value to a that is equal to a mathematical integer.
1039 *java.lang.Math.round(double)*
1041 public static long round(double a)
1043 Returns the closest long to the argument. The result is rounded to an integer
1044 by adding 1/2, taking the floor of the result, and casting the result to type
1045 long. In other words, the result is equal to the value of the expression:
1047 (long)Math.floor(a + 0.5d)
1049 Special cases: If the argument is NaN, the result is 0. If the argument is
1050 negative infinity or any value less than or equal to the value of
1051 Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE. If the
1052 argument is positive infinity or any value greater than or equal to the value
1053 of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.
1056 a - a floating-point value to be rounded to a long.
1058 Returns: the value of the argument rounded to the nearest long value.
1060 *java.lang.Math.round(float)*
1062 public static int round(float a)
1064 Returns the closest int to the argument. The result is rounded to an integer by
1065 adding 1/2, taking the floor of the result, and casting the result to type int.
1066 In other words, the result is equal to the value of the expression:
1068 (int)Math.floor(a + 0.5f)
1070 Special cases: If the argument is NaN, the result is 0. If the argument is
1071 negative infinity or any value less than or equal to the value of
1072 Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE. If
1073 the argument is positive infinity or any value greater than or equal to the
1074 value of Integer.MAX_VALUE, the result is equal to the value of
1078 a - a floating-point value to be rounded to an integer.
1080 Returns: the value of the argument rounded to the nearest int value.
1082 *java.lang.Math.scalb(double,int)*
1084 public static double scalb(
1088 Returnd 2scaleFactor rounded as if performed by a single correctly rounded
1089 floating-point multiply to a member of the double value set. See the Java
1090 Language Specification for a discussion of floating-point value sets. If the
1091 exponent of the result is between (|java.lang.Double|) and (|java.lang.Double|)
1092 , the answer is calculated exactly. If the exponent of the result would be
1093 larger thanDouble.MAX_EXPONENT, an infinity is returned. Note that if the
1094 result is subnormal, precision may be lost; that is, whenscalb(x, n)is
1095 subnormal,scalb(scalb(x, n), -n)may not equal x. When the result is non-NaN,
1096 the result has the same sign asd.
1100 If the first argument is NaN, NaN is returned. If the first argument is
1101 infinite, then an infinity of the same sign is returned. If the first argument
1102 is zero, then a zero of the same sign is returned.
1105 d - number to be scaled by a power of two.
1106 scaleFactor - power of 2 used to scale {@code d}
1108 Returns: {@code d} 2{@code scaleFactor}
1110 *java.lang.Math.scalb(float,int)*
1112 public static float scalb(
1116 Returnf 2scaleFactor rounded as if performed by a single correctly rounded
1117 floating-point multiply to a member of the float value set. See the Java
1118 Language Specification for a discussion of floating-point value sets. If the
1119 exponent of the result is between (|java.lang.Float|) and (|java.lang.Float|) ,
1120 the answer is calculated exactly. If the exponent of the result would be larger
1121 thanFloat.MAX_EXPONENT, an infinity is returned. Note that if the result is
1122 subnormal, precision may be lost; that is, whenscalb(x, n)is
1123 subnormal,scalb(scalb(x, n), -n)may not equal x. When the result is non-NaN,
1124 the result has the same sign asf.
1128 If the first argument is NaN, NaN is returned. If the first argument is
1129 infinite, then an infinity of the same sign is returned. If the first argument
1130 is zero, then a zero of the same sign is returned.
1133 f - number to be scaled by a power of two.
1134 scaleFactor - power of 2 used to scale {@code f}
1136 Returns: {@code f} 2{@code scaleFactor}
1138 *java.lang.Math.signum(double)*
1140 public static double signum(double d)
1142 Returns the signum function of the argument; zero if the argument is zero, 1.0
1143 if the argument is greater than zero, -1.0 if the argument is less than zero.
1147 If the argument is NaN, then the result is NaN. If the argument is positive
1148 zero or negative zero, then the result is the same as the argument.
1151 d - the floating-point value whose signum is to be returned
1153 Returns: the signum function of the argument
1155 *java.lang.Math.signum(float)*
1157 public static float signum(float f)
1159 Returns the signum function of the argument; zero if the argument is zero, 1.0f
1160 if the argument is greater than zero, -1.0f if the argument is less than zero.
1164 If the argument is NaN, then the result is NaN. If the argument is positive
1165 zero or negative zero, then the result is the same as the argument.
1168 f - the floating-point value whose signum is to be returned
1170 Returns: the signum function of the argument
1172 *java.lang.Math.sin(double)*
1174 public static double sin(double a)
1176 Returns the trigonometric sine of an angle. Special cases: If the argument is
1177 NaN or an infinity, then the result is NaN. If the argument is zero, then the
1178 result is a zero with the same sign as the argument.
1180 The computed result must be within 1 ulp of the exact result. Results must be
1184 a - an angle, in radians.
1186 Returns: the sine of the argument.
1188 *java.lang.Math.sinh(double)*
1190 public static double sinh(double x)
1192 Returns the hyperbolic sine of a double value. The hyperbolic sine of x is
1193 defined to be (ex-e-x)/2 where e is Euler's number(|java.lang.Math|) .
1197 If the argument is NaN, then the result is NaN.
1199 If the argument is infinite, then the result is an infinity with the same sign
1202 If the argument is zero, then the result is a zero with the same sign as the
1207 The computed result must be within 2.5 ulps of the exact result.
1210 x - The number whose hyperbolic sine is to be returned.
1212 Returns: The hyperbolic sine of x.
1214 *java.lang.Math.sqrt(double)*
1216 public static double sqrt(double a)
1218 Returns the correctly rounded positive square root of a double value. Special
1219 cases: If the argument is NaN or less than zero, then the result is NaN. If the
1220 argument is positive infinity, then the result is positive infinity. If the
1221 argument is positive zero or negative zero, then the result is the same as the
1222 argument. Otherwise, the result is the double value closest to the true
1223 mathematical square root of the argument value.
1228 Returns: the positive square root of a. If the argument is NaN or less than zero, the
1231 *java.lang.Math.tan(double)*
1233 public static double tan(double a)
1235 Returns the trigonometric tangent of an angle. Special cases: If the argument
1236 is NaN or an infinity, then the result is NaN. If the argument is zero, then
1237 the result is a zero with the same sign as the argument.
1239 The computed result must be within 1 ulp of the exact result. Results must be
1243 a - an angle, in radians.
1245 Returns: the tangent of the argument.
1247 *java.lang.Math.tanh(double)*
1249 public static double tanh(double x)
1251 Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x
1252 is defined to be (ex-e-x)/(ex+e-x), in other words,
1253 sinh(<i>x</i>)(|java.lang.Math|) / cosh(<i>x</i>)(|java.lang.Math|) . Note that
1254 the absolute value of the exact tanh is always less than 1.
1258 If the argument is NaN, then the result is NaN.
1260 If the argument is zero, then the result is a zero with the same sign as the
1263 If the argument is positive infinity, then the result is +1.0.
1265 If the argument is negative infinity, then the result is -1.0.
1269 The computed result must be within 2.5 ulps of the exact result. The result of
1270 tanh for any finite input must have an absolute value less than or equal to 1.
1271 Note that once the exact result of tanh is within 1/2 of an ulp of the limit
1272 value of 1, correctly signed 1.0 should be returned.
1275 x - The number whose hyperbolic tangent is to be returned.
1277 Returns: The hyperbolic tangent of x.
1279 *java.lang.Math.toDegrees(double)*
1281 public static double toDegrees(double angrad)
1283 Converts an angle measured in radians to an approximately equivalent angle
1284 measured in degrees. The conversion from radians to degrees is generally
1285 inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.
1288 angrad - an angle, in radians
1290 Returns: the measurement of the angle angrad in degrees.
1292 *java.lang.Math.toRadians(double)*
1294 public static double toRadians(double angdeg)
1296 Converts an angle measured in degrees to an approximately equivalent angle
1297 measured in radians. The conversion from degrees to radians is generally
1301 angdeg - an angle, in degrees
1303 Returns: the measurement of the angle angdeg in radians.
1305 *java.lang.Math.ulp(double)*
1307 public static double ulp(double d)
1309 Returns the size of an ulp of the argument. An ulp of a double value is the
1310 positive distance between this floating-point value and the double value next
1311 larger in magnitude. Note that for non-NaN x, ulp(-x) == ulp(x).
1315 If the argument is NaN, then the result is NaN. If the argument is positive or
1316 negative infinity, then the result is positive infinity. If the argument is
1317 positive or negative zero, then the result is Double.MIN_VALUE. If the argument
1318 is Double.MAX_VALUE, then the result is equal to 2971.
1321 d - the floating-point value whose ulp is to be returned
1323 Returns: the size of an ulp of the argument
1325 *java.lang.Math.ulp(float)*
1327 public static float ulp(float f)
1329 Returns the size of an ulp of the argument. An ulp of a float value is the
1330 positive distance between this floating-point value and the float value next
1331 larger in magnitude. Note that for non-NaN x, ulp(-x) == ulp(x).
1335 If the argument is NaN, then the result is NaN. If the argument is positive or
1336 negative infinity, then the result is positive infinity. If the argument is
1337 positive or negative zero, then the result is Float.MIN_VALUE. If the argument
1338 is Float.MAX_VALUE, then the result is equal to 2104.
1341 f - the floating-point value whose ulp is to be returned
1343 Returns: the size of an ulp of the argument