1
1
/*
2
- * Copyright (c) 1994, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1994, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
37
37
* square root, and trigonometric functions.
38
38
*
39
39
* <p>Unlike some of the numeric methods of class
40
- * {@code StrictMath}, all implementations of the equivalent
40
+ * {@link java.lang.StrictMath StrictMath}, all implementations of the equivalent
41
41
* functions of class {@code Math} are not defined to return the
42
42
* bit-for-bit same results. This relaxation permits
43
43
* better-performing implementations where strict reproducibility is
99
99
* occurs only with a specific minimum or maximum value and
100
100
* should be checked against the minimum or maximum as appropriate.
101
101
*
102
+ * <h2><a id=Ieee754RecommendedOps>IEEE 754 Recommended
103
+ * Operations</a></h2>
104
+ *
105
+ * The 2019 revision of the IEEE 754 floating-point standard includes
106
+ * a section of recommended operations and the semantics of those
107
+ * operations if they are included in a programming environment. The
108
+ * recommended operations present in this class include {@link sin
109
+ * sin}, {@link cos cos}, {@link tan tan}, {@link asin asin}, {@link
110
+ * acos acos}, {@link atan atan}, {@link exp exp}, {@link expm1
111
+ * expm1}, {@link log log}, {@link log10 log10}, {@link log1p log1p},
112
+ * {@link sinh sinh}, {@link cosh cosh}, {@link tanh tanh}, {@link
113
+ * hypot hypot}, and {@link pow pow}. (The {@link sqrt sqrt}
114
+ * operation is a required part of IEEE 754 from a different section
115
+ * of the standard.) The special case behavior of the recommended
116
+ * operations generally follows the guidance of the IEEE 754
117
+ * standard. However, the {@code pow} method defines different
118
+ * behavior for some arguments, as noted in its {@linkplain pow
119
+ * specification}. The IEEE 754 standard defines its operations to be
120
+ * correctly rounded, which is a more stringent quality of
121
+ * implementation condition than required for most of the methods in
122
+ * question that are also included in this class.
123
+ *
102
124
* @author Joseph D. Darcy
103
125
* @since 1.0
104
126
*/
@@ -156,7 +178,9 @@ public static double sin(double a) {
156
178
/**
157
179
* Returns the trigonometric cosine of an angle. Special cases:
158
180
* <ul><li>If the argument is NaN or an infinity, then the
159
- * result is NaN.</ul>
181
+ * result is NaN.
182
+ * <li>If the argument is zero, then the result is {@code 1.0}.
183
+ *</ul>
160
184
*
161
185
* <p>The computed result must be within 1 ulp of the exact result.
162
186
* Results must be semi-monotonic.
@@ -209,7 +233,9 @@ public static double asin(double a) {
209
233
* Returns the arc cosine of a value; the returned angle is in the
210
234
* range 0.0 through <i>pi</i>. Special case:
211
235
* <ul><li>If the argument is NaN or its absolute value is greater
212
- * than 1, then the result is NaN.</ul>
236
+ * than 1, then the result is NaN.
237
+ * <li>If the argument is {@code 1.0}, the result is positive zero.
238
+ * </ul>
213
239
*
214
240
* <p>The computed result must be within 1 ulp of the exact result.
215
241
* Results must be semi-monotonic.
@@ -226,7 +252,11 @@ public static double acos(double a) {
226
252
* range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
227
253
* <ul><li>If the argument is NaN, then the result is NaN.
228
254
* <li>If the argument is zero, then the result is a zero with the
229
- * same sign as the argument.</ul>
255
+ * same sign as the argument.
256
+ * <li>If the argument is {@linkplain Double#isInfinite infinite},
257
+ * then the result is the closest value to <i>pi</i>/2 with the
258
+ * same sign as the input.
259
+ * </ul>
230
260
*
231
261
* <p>The computed result must be within 1 ulp of the exact result.
232
262
* Results must be semi-monotonic.
@@ -275,7 +305,9 @@ public static double toDegrees(double angrad) {
275
305
* <li>If the argument is positive infinity, then the result is
276
306
* positive infinity.
277
307
* <li>If the argument is negative infinity, then the result is
278
- * positive zero.</ul>
308
+ * positive zero.
309
+ * <li>If the argument is zero, then the result is {@code 1.0}.
310
+ * </ul>
279
311
*
280
312
* <p>The computed result must be within 1 ulp of the exact result.
281
313
* Results must be semi-monotonic.
@@ -297,7 +329,10 @@ public static double exp(double a) {
297
329
* <li>If the argument is positive infinity, then the result is
298
330
* positive infinity.
299
331
* <li>If the argument is positive zero or negative zero, then the
300
- * result is negative infinity.</ul>
332
+ * result is negative infinity.
333
+ * <li>If the argument is {@code 1.0}, then the result is positive
334
+ * zero.
335
+ * </ul>
301
336
*
302
337
* <p>The computed result must be within 1 ulp of the exact result.
303
338
* Results must be semi-monotonic.
@@ -321,8 +356,10 @@ public static double log(double a) {
321
356
* positive infinity.
322
357
* <li>If the argument is positive zero or negative zero, then the
323
358
* result is negative infinity.
324
- * <li> If the argument is equal to 10<sup><i>n</i></sup> for
325
- * integer <i>n</i>, then the result is <i>n</i>.
359
+ * <li>If the argument is equal to 10<sup><i>n</i></sup> for
360
+ * integer <i>n</i>, then the result is <i>n</i>. In particular,
361
+ * if the argument is {@code 1.0} (10<sup>0</sup>), then the
362
+ * result is positive zero.
326
363
* </ul>
327
364
*
328
365
* <p>The computed result must be within 1 ulp of the exact result.
@@ -529,6 +566,15 @@ public static double rint(double a) {
529
566
* <p>The computed result must be within 2 ulps of the exact result.
530
567
* Results must be semi-monotonic.
531
568
*
569
+ * @apiNote
570
+ * For <i>y</i> with a positive sign and finite nonzero
571
+ * <i>x</i>, the exact mathematical value of {@code atan2} is
572
+ * equal to:
573
+ * <ul>
574
+ * <li>If <i>x</i> {@literal >} 0, atan(abs(<i>y</i>/<i>x</i>))
575
+ * <li>If <i>x</i> {@literal <} 0, π - atan(abs(<i>y</i>/<i>x</i>))
576
+ * </ul>
577
+ *
532
578
* @param y the ordinate coordinate
533
579
* @param x the abscissa coordinate
534
580
* @return the <i>theta</i> component of the point
@@ -660,6 +706,16 @@ public static double atan2(double y, double x) {
660
706
* <p>The computed result must be within 1 ulp of the exact result.
661
707
* Results must be semi-monotonic.
662
708
*
709
+ * @apiNote
710
+ * The special cases definitions of this method differ from the
711
+ * special case definitions of the IEEE 754 recommended {@code
712
+ * pow} operation for ±{@code 1.0} raised to an infinite
713
+ * power. This method treats such cases as indeterminate and
714
+ * specifies a NaN is returned. The IEEE 754 specification treats
715
+ * the infinite power as a large integer (large-magnitude
716
+ * floating-point numbers are numerically integers, specifically
717
+ * even integers) and therefore specifies {@code 1.0} be returned.
718
+ *
663
719
* @param a the base.
664
720
* @param b the exponent.
665
721
* @return the value {@code a}<sup>{@code b}</sup>.
@@ -2113,6 +2169,7 @@ public static double tanh(double x) {
2113
2169
* <li> If either argument is NaN and neither argument is infinite,
2114
2170
* then the result is NaN.
2115
2171
*
2172
+ * <li> If both arguments are zero, the result is positive zero.
2116
2173
* </ul>
2117
2174
*
2118
2175
* <p>The computed result must be within 1 ulp of the exact
0 commit comments