emul/src/main/java/java/lang/Math.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 29 Sep 2012 10:56:23 +0200
branchjdk7-b147
changeset 67 cc0d42d2110a
child 84 d65b3a2fbfaf
permissions -rw-r--r--
Bringing in math & numbers
jaroslav@67
     1
/*
jaroslav@67
     2
 * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
jaroslav@67
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@67
     4
 *
jaroslav@67
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@67
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@67
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@67
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@67
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@67
    10
 *
jaroslav@67
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@67
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@67
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@67
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@67
    15
 * accompanied this code).
jaroslav@67
    16
 *
jaroslav@67
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@67
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@67
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@67
    20
 *
jaroslav@67
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@67
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@67
    23
 * questions.
jaroslav@67
    24
 */
jaroslav@67
    25
jaroslav@67
    26
package java.lang;
jaroslav@67
    27
import java.util.Random;
jaroslav@67
    28
jaroslav@67
    29
jaroslav@67
    30
/**
jaroslav@67
    31
 * The class {@code Math} contains methods for performing basic
jaroslav@67
    32
 * numeric operations such as the elementary exponential, logarithm,
jaroslav@67
    33
 * square root, and trigonometric functions.
jaroslav@67
    34
 *
jaroslav@67
    35
 * <p>Unlike some of the numeric methods of class
jaroslav@67
    36
 * {@code StrictMath}, all implementations of the equivalent
jaroslav@67
    37
 * functions of class {@code Math} are not defined to return the
jaroslav@67
    38
 * bit-for-bit same results.  This relaxation permits
jaroslav@67
    39
 * better-performing implementations where strict reproducibility is
jaroslav@67
    40
 * not required.
jaroslav@67
    41
 *
jaroslav@67
    42
 * <p>By default many of the {@code Math} methods simply call
jaroslav@67
    43
 * the equivalent method in {@code StrictMath} for their
jaroslav@67
    44
 * implementation.  Code generators are encouraged to use
jaroslav@67
    45
 * platform-specific native libraries or microprocessor instructions,
jaroslav@67
    46
 * where available, to provide higher-performance implementations of
jaroslav@67
    47
 * {@code Math} methods.  Such higher-performance
jaroslav@67
    48
 * implementations still must conform to the specification for
jaroslav@67
    49
 * {@code Math}.
jaroslav@67
    50
 *
jaroslav@67
    51
 * <p>The quality of implementation specifications concern two
jaroslav@67
    52
 * properties, accuracy of the returned result and monotonicity of the
jaroslav@67
    53
 * method.  Accuracy of the floating-point {@code Math} methods
jaroslav@67
    54
 * is measured in terms of <i>ulps</i>, units in the last place.  For
jaroslav@67
    55
 * a given floating-point format, an ulp of a specific real number
jaroslav@67
    56
 * value is the distance between the two floating-point values
jaroslav@67
    57
 * bracketing that numerical value.  When discussing the accuracy of a
jaroslav@67
    58
 * method as a whole rather than at a specific argument, the number of
jaroslav@67
    59
 * ulps cited is for the worst-case error at any argument.  If a
jaroslav@67
    60
 * method always has an error less than 0.5 ulps, the method always
jaroslav@67
    61
 * returns the floating-point number nearest the exact result; such a
jaroslav@67
    62
 * method is <i>correctly rounded</i>.  A correctly rounded method is
jaroslav@67
    63
 * generally the best a floating-point approximation can be; however,
jaroslav@67
    64
 * it is impractical for many floating-point methods to be correctly
jaroslav@67
    65
 * rounded.  Instead, for the {@code Math} class, a larger error
jaroslav@67
    66
 * bound of 1 or 2 ulps is allowed for certain methods.  Informally,
jaroslav@67
    67
 * with a 1 ulp error bound, when the exact result is a representable
jaroslav@67
    68
 * number, the exact result should be returned as the computed result;
jaroslav@67
    69
 * otherwise, either of the two floating-point values which bracket
jaroslav@67
    70
 * the exact result may be returned.  For exact results large in
jaroslav@67
    71
 * magnitude, one of the endpoints of the bracket may be infinite.
jaroslav@67
    72
 * Besides accuracy at individual arguments, maintaining proper
jaroslav@67
    73
 * relations between the method at different arguments is also
jaroslav@67
    74
 * important.  Therefore, most methods with more than 0.5 ulp errors
jaroslav@67
    75
 * are required to be <i>semi-monotonic</i>: whenever the mathematical
jaroslav@67
    76
 * function is non-decreasing, so is the floating-point approximation,
jaroslav@67
    77
 * likewise, whenever the mathematical function is non-increasing, so
jaroslav@67
    78
 * is the floating-point approximation.  Not all approximations that
jaroslav@67
    79
 * have 1 ulp accuracy will automatically meet the monotonicity
jaroslav@67
    80
 * requirements.
jaroslav@67
    81
 *
jaroslav@67
    82
 * @author  unascribed
jaroslav@67
    83
 * @author  Joseph D. Darcy
jaroslav@67
    84
 * @since   JDK1.0
jaroslav@67
    85
 */
jaroslav@67
    86
jaroslav@67
    87
public final class Math {
jaroslav@67
    88
jaroslav@67
    89
    /**
jaroslav@67
    90
     * Don't let anyone instantiate this class.
jaroslav@67
    91
     */
jaroslav@67
    92
    private Math() {}
jaroslav@67
    93
jaroslav@67
    94
    /**
jaroslav@67
    95
     * The {@code double} value that is closer than any other to
jaroslav@67
    96
     * <i>e</i>, the base of the natural logarithms.
jaroslav@67
    97
     */
jaroslav@67
    98
    public static final double E = 2.7182818284590452354;
jaroslav@67
    99
jaroslav@67
   100
    /**
jaroslav@67
   101
     * The {@code double} value that is closer than any other to
jaroslav@67
   102
     * <i>pi</i>, the ratio of the circumference of a circle to its
jaroslav@67
   103
     * diameter.
jaroslav@67
   104
     */
jaroslav@67
   105
    public static final double PI = 3.14159265358979323846;
jaroslav@67
   106
jaroslav@67
   107
    /**
jaroslav@67
   108
     * Returns the trigonometric sine of an angle.  Special cases:
jaroslav@67
   109
     * <ul><li>If the argument is NaN or an infinity, then the
jaroslav@67
   110
     * result is NaN.
jaroslav@67
   111
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
   112
     * same sign as the argument.</ul>
jaroslav@67
   113
     *
jaroslav@67
   114
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   115
     * Results must be semi-monotonic.
jaroslav@67
   116
     *
jaroslav@67
   117
     * @param   a   an angle, in radians.
jaroslav@67
   118
     * @return  the sine of the argument.
jaroslav@67
   119
     */
jaroslav@67
   120
    public static double sin(double a) {
jaroslav@67
   121
        return StrictMath.sin(a); // default impl. delegates to StrictMath
jaroslav@67
   122
    }
jaroslav@67
   123
jaroslav@67
   124
    /**
jaroslav@67
   125
     * Returns the trigonometric cosine of an angle. Special cases:
jaroslav@67
   126
     * <ul><li>If the argument is NaN or an infinity, then the
jaroslav@67
   127
     * result is NaN.</ul>
jaroslav@67
   128
     *
jaroslav@67
   129
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   130
     * Results must be semi-monotonic.
jaroslav@67
   131
     *
jaroslav@67
   132
     * @param   a   an angle, in radians.
jaroslav@67
   133
     * @return  the cosine of the argument.
jaroslav@67
   134
     */
jaroslav@67
   135
    public static double cos(double a) {
jaroslav@67
   136
        return StrictMath.cos(a); // default impl. delegates to StrictMath
jaroslav@67
   137
    }
jaroslav@67
   138
jaroslav@67
   139
    /**
jaroslav@67
   140
     * Returns the trigonometric tangent of an angle.  Special cases:
jaroslav@67
   141
     * <ul><li>If the argument is NaN or an infinity, then the result
jaroslav@67
   142
     * is NaN.
jaroslav@67
   143
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
   144
     * same sign as the argument.</ul>
jaroslav@67
   145
     *
jaroslav@67
   146
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   147
     * Results must be semi-monotonic.
jaroslav@67
   148
     *
jaroslav@67
   149
     * @param   a   an angle, in radians.
jaroslav@67
   150
     * @return  the tangent of the argument.
jaroslav@67
   151
     */
jaroslav@67
   152
    public static double tan(double a) {
jaroslav@67
   153
        return StrictMath.tan(a); // default impl. delegates to StrictMath
jaroslav@67
   154
    }
jaroslav@67
   155
jaroslav@67
   156
    /**
jaroslav@67
   157
     * Returns the arc sine of a value; the returned angle is in the
jaroslav@67
   158
     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
jaroslav@67
   159
     * <ul><li>If the argument is NaN or its absolute value is greater
jaroslav@67
   160
     * than 1, then the result is NaN.
jaroslav@67
   161
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
   162
     * same sign as the argument.</ul>
jaroslav@67
   163
     *
jaroslav@67
   164
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   165
     * Results must be semi-monotonic.
jaroslav@67
   166
     *
jaroslav@67
   167
     * @param   a   the value whose arc sine is to be returned.
jaroslav@67
   168
     * @return  the arc sine of the argument.
jaroslav@67
   169
     */
jaroslav@67
   170
    public static double asin(double a) {
jaroslav@67
   171
        return StrictMath.asin(a); // default impl. delegates to StrictMath
jaroslav@67
   172
    }
jaroslav@67
   173
jaroslav@67
   174
    /**
jaroslav@67
   175
     * Returns the arc cosine of a value; the returned angle is in the
jaroslav@67
   176
     * range 0.0 through <i>pi</i>.  Special case:
jaroslav@67
   177
     * <ul><li>If the argument is NaN or its absolute value is greater
jaroslav@67
   178
     * than 1, then the result is NaN.</ul>
jaroslav@67
   179
     *
jaroslav@67
   180
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   181
     * Results must be semi-monotonic.
jaroslav@67
   182
     *
jaroslav@67
   183
     * @param   a   the value whose arc cosine is to be returned.
jaroslav@67
   184
     * @return  the arc cosine of the argument.
jaroslav@67
   185
     */
jaroslav@67
   186
    public static double acos(double a) {
jaroslav@67
   187
        return StrictMath.acos(a); // default impl. delegates to StrictMath
jaroslav@67
   188
    }
jaroslav@67
   189
jaroslav@67
   190
    /**
jaroslav@67
   191
     * Returns the arc tangent of a value; the returned angle is in the
jaroslav@67
   192
     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
jaroslav@67
   193
     * <ul><li>If the argument is NaN, then the result is NaN.
jaroslav@67
   194
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
   195
     * same sign as the argument.</ul>
jaroslav@67
   196
     *
jaroslav@67
   197
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   198
     * Results must be semi-monotonic.
jaroslav@67
   199
     *
jaroslav@67
   200
     * @param   a   the value whose arc tangent is to be returned.
jaroslav@67
   201
     * @return  the arc tangent of the argument.
jaroslav@67
   202
     */
jaroslav@67
   203
    public static double atan(double a) {
jaroslav@67
   204
        return StrictMath.atan(a); // default impl. delegates to StrictMath
jaroslav@67
   205
    }
jaroslav@67
   206
jaroslav@67
   207
    /**
jaroslav@67
   208
     * Converts an angle measured in degrees to an approximately
jaroslav@67
   209
     * equivalent angle measured in radians.  The conversion from
jaroslav@67
   210
     * degrees to radians is generally inexact.
jaroslav@67
   211
     *
jaroslav@67
   212
     * @param   angdeg   an angle, in degrees
jaroslav@67
   213
     * @return  the measurement of the angle {@code angdeg}
jaroslav@67
   214
     *          in radians.
jaroslav@67
   215
     * @since   1.2
jaroslav@67
   216
     */
jaroslav@67
   217
    public static double toRadians(double angdeg) {
jaroslav@67
   218
        return angdeg / 180.0 * PI;
jaroslav@67
   219
    }
jaroslav@67
   220
jaroslav@67
   221
    /**
jaroslav@67
   222
     * Converts an angle measured in radians to an approximately
jaroslav@67
   223
     * equivalent angle measured in degrees.  The conversion from
jaroslav@67
   224
     * radians to degrees is generally inexact; users should
jaroslav@67
   225
     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
jaroslav@67
   226
     * equal {@code 0.0}.
jaroslav@67
   227
     *
jaroslav@67
   228
     * @param   angrad   an angle, in radians
jaroslav@67
   229
     * @return  the measurement of the angle {@code angrad}
jaroslav@67
   230
     *          in degrees.
jaroslav@67
   231
     * @since   1.2
jaroslav@67
   232
     */
jaroslav@67
   233
    public static double toDegrees(double angrad) {
jaroslav@67
   234
        return angrad * 180.0 / PI;
jaroslav@67
   235
    }
jaroslav@67
   236
jaroslav@67
   237
    /**
jaroslav@67
   238
     * Returns Euler's number <i>e</i> raised to the power of a
jaroslav@67
   239
     * {@code double} value.  Special cases:
jaroslav@67
   240
     * <ul><li>If the argument is NaN, the result is NaN.
jaroslav@67
   241
     * <li>If the argument is positive infinity, then the result is
jaroslav@67
   242
     * positive infinity.
jaroslav@67
   243
     * <li>If the argument is negative infinity, then the result is
jaroslav@67
   244
     * positive zero.</ul>
jaroslav@67
   245
     *
jaroslav@67
   246
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   247
     * Results must be semi-monotonic.
jaroslav@67
   248
     *
jaroslav@67
   249
     * @param   a   the exponent to raise <i>e</i> to.
jaroslav@67
   250
     * @return  the value <i>e</i><sup>{@code a}</sup>,
jaroslav@67
   251
     *          where <i>e</i> is the base of the natural logarithms.
jaroslav@67
   252
     */
jaroslav@67
   253
    public static double exp(double a) {
jaroslav@67
   254
        return StrictMath.exp(a); // default impl. delegates to StrictMath
jaroslav@67
   255
    }
jaroslav@67
   256
jaroslav@67
   257
    /**
jaroslav@67
   258
     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
jaroslav@67
   259
     * value.  Special cases:
jaroslav@67
   260
     * <ul><li>If the argument is NaN or less than zero, then the result
jaroslav@67
   261
     * is NaN.
jaroslav@67
   262
     * <li>If the argument is positive infinity, then the result is
jaroslav@67
   263
     * positive infinity.
jaroslav@67
   264
     * <li>If the argument is positive zero or negative zero, then the
jaroslav@67
   265
     * result is negative infinity.</ul>
jaroslav@67
   266
     *
jaroslav@67
   267
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   268
     * Results must be semi-monotonic.
jaroslav@67
   269
     *
jaroslav@67
   270
     * @param   a   a value
jaroslav@67
   271
     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
jaroslav@67
   272
     *          {@code a}.
jaroslav@67
   273
     */
jaroslav@67
   274
    public static double log(double a) {
jaroslav@67
   275
        return StrictMath.log(a); // default impl. delegates to StrictMath
jaroslav@67
   276
    }
jaroslav@67
   277
jaroslav@67
   278
    /**
jaroslav@67
   279
     * Returns the base 10 logarithm of a {@code double} value.
jaroslav@67
   280
     * Special cases:
jaroslav@67
   281
     *
jaroslav@67
   282
     * <ul><li>If the argument is NaN or less than zero, then the result
jaroslav@67
   283
     * is NaN.
jaroslav@67
   284
     * <li>If the argument is positive infinity, then the result is
jaroslav@67
   285
     * positive infinity.
jaroslav@67
   286
     * <li>If the argument is positive zero or negative zero, then the
jaroslav@67
   287
     * result is negative infinity.
jaroslav@67
   288
     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
jaroslav@67
   289
     * integer <i>n</i>, then the result is <i>n</i>.
jaroslav@67
   290
     * </ul>
jaroslav@67
   291
     *
jaroslav@67
   292
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   293
     * Results must be semi-monotonic.
jaroslav@67
   294
     *
jaroslav@67
   295
     * @param   a   a value
jaroslav@67
   296
     * @return  the base 10 logarithm of  {@code a}.
jaroslav@67
   297
     * @since 1.5
jaroslav@67
   298
     */
jaroslav@67
   299
    public static double log10(double a) {
jaroslav@67
   300
        return StrictMath.log10(a); // default impl. delegates to StrictMath
jaroslav@67
   301
    }
jaroslav@67
   302
jaroslav@67
   303
    /**
jaroslav@67
   304
     * Returns the correctly rounded positive square root of a
jaroslav@67
   305
     * {@code double} value.
jaroslav@67
   306
     * Special cases:
jaroslav@67
   307
     * <ul><li>If the argument is NaN or less than zero, then the result
jaroslav@67
   308
     * is NaN.
jaroslav@67
   309
     * <li>If the argument is positive infinity, then the result is positive
jaroslav@67
   310
     * infinity.
jaroslav@67
   311
     * <li>If the argument is positive zero or negative zero, then the
jaroslav@67
   312
     * result is the same as the argument.</ul>
jaroslav@67
   313
     * Otherwise, the result is the {@code double} value closest to
jaroslav@67
   314
     * the true mathematical square root of the argument value.
jaroslav@67
   315
     *
jaroslav@67
   316
     * @param   a   a value.
jaroslav@67
   317
     * @return  the positive square root of {@code a}.
jaroslav@67
   318
     *          If the argument is NaN or less than zero, the result is NaN.
jaroslav@67
   319
     */
jaroslav@67
   320
    public static double sqrt(double a) {
jaroslav@67
   321
        return StrictMath.sqrt(a); // default impl. delegates to StrictMath
jaroslav@67
   322
                                   // Note that hardware sqrt instructions
jaroslav@67
   323
                                   // frequently can be directly used by JITs
jaroslav@67
   324
                                   // and should be much faster than doing
jaroslav@67
   325
                                   // Math.sqrt in software.
jaroslav@67
   326
    }
jaroslav@67
   327
jaroslav@67
   328
jaroslav@67
   329
    /**
jaroslav@67
   330
     * Returns the cube root of a {@code double} value.  For
jaroslav@67
   331
     * positive finite {@code x}, {@code cbrt(-x) ==
jaroslav@67
   332
     * -cbrt(x)}; that is, the cube root of a negative value is
jaroslav@67
   333
     * the negative of the cube root of that value's magnitude.
jaroslav@67
   334
     *
jaroslav@67
   335
     * Special cases:
jaroslav@67
   336
     *
jaroslav@67
   337
     * <ul>
jaroslav@67
   338
     *
jaroslav@67
   339
     * <li>If the argument is NaN, then the result is NaN.
jaroslav@67
   340
     *
jaroslav@67
   341
     * <li>If the argument is infinite, then the result is an infinity
jaroslav@67
   342
     * with the same sign as the argument.
jaroslav@67
   343
     *
jaroslav@67
   344
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
   345
     * same sign as the argument.
jaroslav@67
   346
     *
jaroslav@67
   347
     * </ul>
jaroslav@67
   348
     *
jaroslav@67
   349
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   350
     *
jaroslav@67
   351
     * @param   a   a value.
jaroslav@67
   352
     * @return  the cube root of {@code a}.
jaroslav@67
   353
     * @since 1.5
jaroslav@67
   354
     */
jaroslav@67
   355
    public static double cbrt(double a) {
jaroslav@67
   356
        return StrictMath.cbrt(a);
jaroslav@67
   357
    }
jaroslav@67
   358
jaroslav@67
   359
    /**
jaroslav@67
   360
     * Computes the remainder operation on two arguments as prescribed
jaroslav@67
   361
     * by the IEEE 754 standard.
jaroslav@67
   362
     * The remainder value is mathematically equal to
jaroslav@67
   363
     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
jaroslav@67
   364
     * where <i>n</i> is the mathematical integer closest to the exact
jaroslav@67
   365
     * mathematical value of the quotient {@code f1/f2}, and if two
jaroslav@67
   366
     * mathematical integers are equally close to {@code f1/f2},
jaroslav@67
   367
     * then <i>n</i> is the integer that is even. If the remainder is
jaroslav@67
   368
     * zero, its sign is the same as the sign of the first argument.
jaroslav@67
   369
     * Special cases:
jaroslav@67
   370
     * <ul><li>If either argument is NaN, or the first argument is infinite,
jaroslav@67
   371
     * or the second argument is positive zero or negative zero, then the
jaroslav@67
   372
     * result is NaN.
jaroslav@67
   373
     * <li>If the first argument is finite and the second argument is
jaroslav@67
   374
     * infinite, then the result is the same as the first argument.</ul>
jaroslav@67
   375
     *
jaroslav@67
   376
     * @param   f1   the dividend.
jaroslav@67
   377
     * @param   f2   the divisor.
jaroslav@67
   378
     * @return  the remainder when {@code f1} is divided by
jaroslav@67
   379
     *          {@code f2}.
jaroslav@67
   380
     */
jaroslav@67
   381
    public static double IEEEremainder(double f1, double f2) {
jaroslav@67
   382
        return StrictMath.IEEEremainder(f1, f2); // delegate to StrictMath
jaroslav@67
   383
    }
jaroslav@67
   384
jaroslav@67
   385
    /**
jaroslav@67
   386
     * Returns the smallest (closest to negative infinity)
jaroslav@67
   387
     * {@code double} value that is greater than or equal to the
jaroslav@67
   388
     * argument and is equal to a mathematical integer. Special cases:
jaroslav@67
   389
     * <ul><li>If the argument value is already equal to a
jaroslav@67
   390
     * mathematical integer, then the result is the same as the
jaroslav@67
   391
     * argument.  <li>If the argument is NaN or an infinity or
jaroslav@67
   392
     * positive zero or negative zero, then the result is the same as
jaroslav@67
   393
     * the argument.  <li>If the argument value is less than zero but
jaroslav@67
   394
     * greater than -1.0, then the result is negative zero.</ul> Note
jaroslav@67
   395
     * that the value of {@code Math.ceil(x)} is exactly the
jaroslav@67
   396
     * value of {@code -Math.floor(-x)}.
jaroslav@67
   397
     *
jaroslav@67
   398
     *
jaroslav@67
   399
     * @param   a   a value.
jaroslav@67
   400
     * @return  the smallest (closest to negative infinity)
jaroslav@67
   401
     *          floating-point value that is greater than or equal to
jaroslav@67
   402
     *          the argument and is equal to a mathematical integer.
jaroslav@67
   403
     */
jaroslav@67
   404
    public static double ceil(double a) {
jaroslav@67
   405
        return StrictMath.ceil(a); // default impl. delegates to StrictMath
jaroslav@67
   406
    }
jaroslav@67
   407
jaroslav@67
   408
    /**
jaroslav@67
   409
     * Returns the largest (closest to positive infinity)
jaroslav@67
   410
     * {@code double} value that is less than or equal to the
jaroslav@67
   411
     * argument and is equal to a mathematical integer. Special cases:
jaroslav@67
   412
     * <ul><li>If the argument value is already equal to a
jaroslav@67
   413
     * mathematical integer, then the result is the same as the
jaroslav@67
   414
     * argument.  <li>If the argument is NaN or an infinity or
jaroslav@67
   415
     * positive zero or negative zero, then the result is the same as
jaroslav@67
   416
     * the argument.</ul>
jaroslav@67
   417
     *
jaroslav@67
   418
     * @param   a   a value.
jaroslav@67
   419
     * @return  the largest (closest to positive infinity)
jaroslav@67
   420
     *          floating-point value that less than or equal to the argument
jaroslav@67
   421
     *          and is equal to a mathematical integer.
jaroslav@67
   422
     */
jaroslav@67
   423
    public static double floor(double a) {
jaroslav@67
   424
        return StrictMath.floor(a); // default impl. delegates to StrictMath
jaroslav@67
   425
    }
jaroslav@67
   426
jaroslav@67
   427
    /**
jaroslav@67
   428
     * Returns the {@code double} value that is closest in value
jaroslav@67
   429
     * to the argument and is equal to a mathematical integer. If two
jaroslav@67
   430
     * {@code double} values that are mathematical integers are
jaroslav@67
   431
     * equally close, the result is the integer value that is
jaroslav@67
   432
     * even. Special cases:
jaroslav@67
   433
     * <ul><li>If the argument value is already equal to a mathematical
jaroslav@67
   434
     * integer, then the result is the same as the argument.
jaroslav@67
   435
     * <li>If the argument is NaN or an infinity or positive zero or negative
jaroslav@67
   436
     * zero, then the result is the same as the argument.</ul>
jaroslav@67
   437
     *
jaroslav@67
   438
     * @param   a   a {@code double} value.
jaroslav@67
   439
     * @return  the closest floating-point value to {@code a} that is
jaroslav@67
   440
     *          equal to a mathematical integer.
jaroslav@67
   441
     */
jaroslav@67
   442
    public static double rint(double a) {
jaroslav@67
   443
        return StrictMath.rint(a); // default impl. delegates to StrictMath
jaroslav@67
   444
    }
jaroslav@67
   445
jaroslav@67
   446
    /**
jaroslav@67
   447
     * Returns the angle <i>theta</i> from the conversion of rectangular
jaroslav@67
   448
     * coordinates ({@code x},&nbsp;{@code y}) to polar
jaroslav@67
   449
     * coordinates (r,&nbsp;<i>theta</i>).
jaroslav@67
   450
     * This method computes the phase <i>theta</i> by computing an arc tangent
jaroslav@67
   451
     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
jaroslav@67
   452
     * cases:
jaroslav@67
   453
     * <ul><li>If either argument is NaN, then the result is NaN.
jaroslav@67
   454
     * <li>If the first argument is positive zero and the second argument
jaroslav@67
   455
     * is positive, or the first argument is positive and finite and the
jaroslav@67
   456
     * second argument is positive infinity, then the result is positive
jaroslav@67
   457
     * zero.
jaroslav@67
   458
     * <li>If the first argument is negative zero and the second argument
jaroslav@67
   459
     * is positive, or the first argument is negative and finite and the
jaroslav@67
   460
     * second argument is positive infinity, then the result is negative zero.
jaroslav@67
   461
     * <li>If the first argument is positive zero and the second argument
jaroslav@67
   462
     * is negative, or the first argument is positive and finite and the
jaroslav@67
   463
     * second argument is negative infinity, then the result is the
jaroslav@67
   464
     * {@code double} value closest to <i>pi</i>.
jaroslav@67
   465
     * <li>If the first argument is negative zero and the second argument
jaroslav@67
   466
     * is negative, or the first argument is negative and finite and the
jaroslav@67
   467
     * second argument is negative infinity, then the result is the
jaroslav@67
   468
     * {@code double} value closest to -<i>pi</i>.
jaroslav@67
   469
     * <li>If the first argument is positive and the second argument is
jaroslav@67
   470
     * positive zero or negative zero, or the first argument is positive
jaroslav@67
   471
     * infinity and the second argument is finite, then the result is the
jaroslav@67
   472
     * {@code double} value closest to <i>pi</i>/2.
jaroslav@67
   473
     * <li>If the first argument is negative and the second argument is
jaroslav@67
   474
     * positive zero or negative zero, or the first argument is negative
jaroslav@67
   475
     * infinity and the second argument is finite, then the result is the
jaroslav@67
   476
     * {@code double} value closest to -<i>pi</i>/2.
jaroslav@67
   477
     * <li>If both arguments are positive infinity, then the result is the
jaroslav@67
   478
     * {@code double} value closest to <i>pi</i>/4.
jaroslav@67
   479
     * <li>If the first argument is positive infinity and the second argument
jaroslav@67
   480
     * is negative infinity, then the result is the {@code double}
jaroslav@67
   481
     * value closest to 3*<i>pi</i>/4.
jaroslav@67
   482
     * <li>If the first argument is negative infinity and the second argument
jaroslav@67
   483
     * is positive infinity, then the result is the {@code double} value
jaroslav@67
   484
     * closest to -<i>pi</i>/4.
jaroslav@67
   485
     * <li>If both arguments are negative infinity, then the result is the
jaroslav@67
   486
     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
jaroslav@67
   487
     *
jaroslav@67
   488
     * <p>The computed result must be within 2 ulps of the exact result.
jaroslav@67
   489
     * Results must be semi-monotonic.
jaroslav@67
   490
     *
jaroslav@67
   491
     * @param   y   the ordinate coordinate
jaroslav@67
   492
     * @param   x   the abscissa coordinate
jaroslav@67
   493
     * @return  the <i>theta</i> component of the point
jaroslav@67
   494
     *          (<i>r</i>,&nbsp;<i>theta</i>)
jaroslav@67
   495
     *          in polar coordinates that corresponds to the point
jaroslav@67
   496
     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
jaroslav@67
   497
     */
jaroslav@67
   498
    public static double atan2(double y, double x) {
jaroslav@67
   499
        return StrictMath.atan2(y, x); // default impl. delegates to StrictMath
jaroslav@67
   500
    }
jaroslav@67
   501
jaroslav@67
   502
    /**
jaroslav@67
   503
     * Returns the value of the first argument raised to the power of the
jaroslav@67
   504
     * second argument. Special cases:
jaroslav@67
   505
     *
jaroslav@67
   506
     * <ul><li>If the second argument is positive or negative zero, then the
jaroslav@67
   507
     * result is 1.0.
jaroslav@67
   508
     * <li>If the second argument is 1.0, then the result is the same as the
jaroslav@67
   509
     * first argument.
jaroslav@67
   510
     * <li>If the second argument is NaN, then the result is NaN.
jaroslav@67
   511
     * <li>If the first argument is NaN and the second argument is nonzero,
jaroslav@67
   512
     * then the result is NaN.
jaroslav@67
   513
     *
jaroslav@67
   514
     * <li>If
jaroslav@67
   515
     * <ul>
jaroslav@67
   516
     * <li>the absolute value of the first argument is greater than 1
jaroslav@67
   517
     * and the second argument is positive infinity, or
jaroslav@67
   518
     * <li>the absolute value of the first argument is less than 1 and
jaroslav@67
   519
     * the second argument is negative infinity,
jaroslav@67
   520
     * </ul>
jaroslav@67
   521
     * then the result is positive infinity.
jaroslav@67
   522
     *
jaroslav@67
   523
     * <li>If
jaroslav@67
   524
     * <ul>
jaroslav@67
   525
     * <li>the absolute value of the first argument is greater than 1 and
jaroslav@67
   526
     * the second argument is negative infinity, or
jaroslav@67
   527
     * <li>the absolute value of the
jaroslav@67
   528
     * first argument is less than 1 and the second argument is positive
jaroslav@67
   529
     * infinity,
jaroslav@67
   530
     * </ul>
jaroslav@67
   531
     * then the result is positive zero.
jaroslav@67
   532
     *
jaroslav@67
   533
     * <li>If the absolute value of the first argument equals 1 and the
jaroslav@67
   534
     * second argument is infinite, then the result is NaN.
jaroslav@67
   535
     *
jaroslav@67
   536
     * <li>If
jaroslav@67
   537
     * <ul>
jaroslav@67
   538
     * <li>the first argument is positive zero and the second argument
jaroslav@67
   539
     * is greater than zero, or
jaroslav@67
   540
     * <li>the first argument is positive infinity and the second
jaroslav@67
   541
     * argument is less than zero,
jaroslav@67
   542
     * </ul>
jaroslav@67
   543
     * then the result is positive zero.
jaroslav@67
   544
     *
jaroslav@67
   545
     * <li>If
jaroslav@67
   546
     * <ul>
jaroslav@67
   547
     * <li>the first argument is positive zero and the second argument
jaroslav@67
   548
     * is less than zero, or
jaroslav@67
   549
     * <li>the first argument is positive infinity and the second
jaroslav@67
   550
     * argument is greater than zero,
jaroslav@67
   551
     * </ul>
jaroslav@67
   552
     * then the result is positive infinity.
jaroslav@67
   553
     *
jaroslav@67
   554
     * <li>If
jaroslav@67
   555
     * <ul>
jaroslav@67
   556
     * <li>the first argument is negative zero and the second argument
jaroslav@67
   557
     * is greater than zero but not a finite odd integer, or
jaroslav@67
   558
     * <li>the first argument is negative infinity and the second
jaroslav@67
   559
     * argument is less than zero but not a finite odd integer,
jaroslav@67
   560
     * </ul>
jaroslav@67
   561
     * then the result is positive zero.
jaroslav@67
   562
     *
jaroslav@67
   563
     * <li>If
jaroslav@67
   564
     * <ul>
jaroslav@67
   565
     * <li>the first argument is negative zero and the second argument
jaroslav@67
   566
     * is a positive finite odd integer, or
jaroslav@67
   567
     * <li>the first argument is negative infinity and the second
jaroslav@67
   568
     * argument is a negative finite odd integer,
jaroslav@67
   569
     * </ul>
jaroslav@67
   570
     * then the result is negative zero.
jaroslav@67
   571
     *
jaroslav@67
   572
     * <li>If
jaroslav@67
   573
     * <ul>
jaroslav@67
   574
     * <li>the first argument is negative zero and the second argument
jaroslav@67
   575
     * is less than zero but not a finite odd integer, or
jaroslav@67
   576
     * <li>the first argument is negative infinity and the second
jaroslav@67
   577
     * argument is greater than zero but not a finite odd integer,
jaroslav@67
   578
     * </ul>
jaroslav@67
   579
     * then the result is positive infinity.
jaroslav@67
   580
     *
jaroslav@67
   581
     * <li>If
jaroslav@67
   582
     * <ul>
jaroslav@67
   583
     * <li>the first argument is negative zero and the second argument
jaroslav@67
   584
     * is a negative finite odd integer, or
jaroslav@67
   585
     * <li>the first argument is negative infinity and the second
jaroslav@67
   586
     * argument is a positive finite odd integer,
jaroslav@67
   587
     * </ul>
jaroslav@67
   588
     * then the result is negative infinity.
jaroslav@67
   589
     *
jaroslav@67
   590
     * <li>If the first argument is finite and less than zero
jaroslav@67
   591
     * <ul>
jaroslav@67
   592
     * <li> if the second argument is a finite even integer, the
jaroslav@67
   593
     * result is equal to the result of raising the absolute value of
jaroslav@67
   594
     * the first argument to the power of the second argument
jaroslav@67
   595
     *
jaroslav@67
   596
     * <li>if the second argument is a finite odd integer, the result
jaroslav@67
   597
     * is equal to the negative of the result of raising the absolute
jaroslav@67
   598
     * value of the first argument to the power of the second
jaroslav@67
   599
     * argument
jaroslav@67
   600
     *
jaroslav@67
   601
     * <li>if the second argument is finite and not an integer, then
jaroslav@67
   602
     * the result is NaN.
jaroslav@67
   603
     * </ul>
jaroslav@67
   604
     *
jaroslav@67
   605
     * <li>If both arguments are integers, then the result is exactly equal
jaroslav@67
   606
     * to the mathematical result of raising the first argument to the power
jaroslav@67
   607
     * of the second argument if that result can in fact be represented
jaroslav@67
   608
     * exactly as a {@code double} value.</ul>
jaroslav@67
   609
     *
jaroslav@67
   610
     * <p>(In the foregoing descriptions, a floating-point value is
jaroslav@67
   611
     * considered to be an integer if and only if it is finite and a
jaroslav@67
   612
     * fixed point of the method {@link #ceil ceil} or,
jaroslav@67
   613
     * equivalently, a fixed point of the method {@link #floor
jaroslav@67
   614
     * floor}. A value is a fixed point of a one-argument
jaroslav@67
   615
     * method if and only if the result of applying the method to the
jaroslav@67
   616
     * value is equal to the value.)
jaroslav@67
   617
     *
jaroslav@67
   618
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
   619
     * Results must be semi-monotonic.
jaroslav@67
   620
     *
jaroslav@67
   621
     * @param   a   the base.
jaroslav@67
   622
     * @param   b   the exponent.
jaroslav@67
   623
     * @return  the value {@code a}<sup>{@code b}</sup>.
jaroslav@67
   624
     */
jaroslav@67
   625
    public static double pow(double a, double b) {
jaroslav@67
   626
        return StrictMath.pow(a, b); // default impl. delegates to StrictMath
jaroslav@67
   627
    }
jaroslav@67
   628
jaroslav@67
   629
    /**
jaroslav@67
   630
     * Returns the closest {@code int} to the argument, with ties
jaroslav@67
   631
     * rounding up.
jaroslav@67
   632
     *
jaroslav@67
   633
     * <p>
jaroslav@67
   634
     * Special cases:
jaroslav@67
   635
     * <ul><li>If the argument is NaN, the result is 0.
jaroslav@67
   636
     * <li>If the argument is negative infinity or any value less than or
jaroslav@67
   637
     * equal to the value of {@code Integer.MIN_VALUE}, the result is
jaroslav@67
   638
     * equal to the value of {@code Integer.MIN_VALUE}.
jaroslav@67
   639
     * <li>If the argument is positive infinity or any value greater than or
jaroslav@67
   640
     * equal to the value of {@code Integer.MAX_VALUE}, the result is
jaroslav@67
   641
     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
jaroslav@67
   642
     *
jaroslav@67
   643
     * @param   a   a floating-point value to be rounded to an integer.
jaroslav@67
   644
     * @return  the value of the argument rounded to the nearest
jaroslav@67
   645
     *          {@code int} value.
jaroslav@67
   646
     * @see     java.lang.Integer#MAX_VALUE
jaroslav@67
   647
     * @see     java.lang.Integer#MIN_VALUE
jaroslav@67
   648
     */
jaroslav@67
   649
    public static int round(float a) {
jaroslav@67
   650
        if (a != 0x1.fffffep-2f) // greatest float value less than 0.5
jaroslav@67
   651
            return (int)floor(a + 0.5f);
jaroslav@67
   652
        else
jaroslav@67
   653
            return 0;
jaroslav@67
   654
    }
jaroslav@67
   655
jaroslav@67
   656
    /**
jaroslav@67
   657
     * Returns the closest {@code long} to the argument, with ties
jaroslav@67
   658
     * rounding up.
jaroslav@67
   659
     *
jaroslav@67
   660
     * <p>Special cases:
jaroslav@67
   661
     * <ul><li>If the argument is NaN, the result is 0.
jaroslav@67
   662
     * <li>If the argument is negative infinity or any value less than or
jaroslav@67
   663
     * equal to the value of {@code Long.MIN_VALUE}, the result is
jaroslav@67
   664
     * equal to the value of {@code Long.MIN_VALUE}.
jaroslav@67
   665
     * <li>If the argument is positive infinity or any value greater than or
jaroslav@67
   666
     * equal to the value of {@code Long.MAX_VALUE}, the result is
jaroslav@67
   667
     * equal to the value of {@code Long.MAX_VALUE}.</ul>
jaroslav@67
   668
     *
jaroslav@67
   669
     * @param   a   a floating-point value to be rounded to a
jaroslav@67
   670
     *          {@code long}.
jaroslav@67
   671
     * @return  the value of the argument rounded to the nearest
jaroslav@67
   672
     *          {@code long} value.
jaroslav@67
   673
     * @see     java.lang.Long#MAX_VALUE
jaroslav@67
   674
     * @see     java.lang.Long#MIN_VALUE
jaroslav@67
   675
     */
jaroslav@67
   676
    public static long round(double a) {
jaroslav@67
   677
        if (a != 0x1.fffffffffffffp-2) // greatest double value less than 0.5
jaroslav@67
   678
            return (long)floor(a + 0.5d);
jaroslav@67
   679
        else
jaroslav@67
   680
            return 0;
jaroslav@67
   681
    }
jaroslav@67
   682
jaroslav@67
   683
    private static Random randomNumberGenerator;
jaroslav@67
   684
jaroslav@67
   685
    private static synchronized Random initRNG() {
jaroslav@67
   686
        Random rnd = randomNumberGenerator;
jaroslav@67
   687
        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
jaroslav@67
   688
    }
jaroslav@67
   689
jaroslav@67
   690
    /**
jaroslav@67
   691
     * Returns a {@code double} value with a positive sign, greater
jaroslav@67
   692
     * than or equal to {@code 0.0} and less than {@code 1.0}.
jaroslav@67
   693
     * Returned values are chosen pseudorandomly with (approximately)
jaroslav@67
   694
     * uniform distribution from that range.
jaroslav@67
   695
     *
jaroslav@67
   696
     * <p>When this method is first called, it creates a single new
jaroslav@67
   697
     * pseudorandom-number generator, exactly as if by the expression
jaroslav@67
   698
     *
jaroslav@67
   699
     * <blockquote>{@code new java.util.Random()}</blockquote>
jaroslav@67
   700
     *
jaroslav@67
   701
     * This new pseudorandom-number generator is used thereafter for
jaroslav@67
   702
     * all calls to this method and is used nowhere else.
jaroslav@67
   703
     *
jaroslav@67
   704
     * <p>This method is properly synchronized to allow correct use by
jaroslav@67
   705
     * more than one thread. However, if many threads need to generate
jaroslav@67
   706
     * pseudorandom numbers at a great rate, it may reduce contention
jaroslav@67
   707
     * for each thread to have its own pseudorandom-number generator.
jaroslav@67
   708
     *
jaroslav@67
   709
     * @return  a pseudorandom {@code double} greater than or equal
jaroslav@67
   710
     * to {@code 0.0} and less than {@code 1.0}.
jaroslav@67
   711
     * @see Random#nextDouble()
jaroslav@67
   712
     */
jaroslav@67
   713
    public static double random() {
jaroslav@67
   714
        Random rnd = randomNumberGenerator;
jaroslav@67
   715
        if (rnd == null) rnd = initRNG();
jaroslav@67
   716
        return rnd.nextDouble();
jaroslav@67
   717
    }
jaroslav@67
   718
jaroslav@67
   719
    /**
jaroslav@67
   720
     * Returns the absolute value of an {@code int} value.
jaroslav@67
   721
     * If the argument is not negative, the argument is returned.
jaroslav@67
   722
     * If the argument is negative, the negation of the argument is returned.
jaroslav@67
   723
     *
jaroslav@67
   724
     * <p>Note that if the argument is equal to the value of
jaroslav@67
   725
     * {@link Integer#MIN_VALUE}, the most negative representable
jaroslav@67
   726
     * {@code int} value, the result is that same value, which is
jaroslav@67
   727
     * negative.
jaroslav@67
   728
     *
jaroslav@67
   729
     * @param   a   the argument whose absolute value is to be determined
jaroslav@67
   730
     * @return  the absolute value of the argument.
jaroslav@67
   731
     */
jaroslav@67
   732
    public static int abs(int a) {
jaroslav@67
   733
        return (a < 0) ? -a : a;
jaroslav@67
   734
    }
jaroslav@67
   735
jaroslav@67
   736
    /**
jaroslav@67
   737
     * Returns the absolute value of a {@code long} value.
jaroslav@67
   738
     * If the argument is not negative, the argument is returned.
jaroslav@67
   739
     * If the argument is negative, the negation of the argument is returned.
jaroslav@67
   740
     *
jaroslav@67
   741
     * <p>Note that if the argument is equal to the value of
jaroslav@67
   742
     * {@link Long#MIN_VALUE}, the most negative representable
jaroslav@67
   743
     * {@code long} value, the result is that same value, which
jaroslav@67
   744
     * is negative.
jaroslav@67
   745
     *
jaroslav@67
   746
     * @param   a   the argument whose absolute value is to be determined
jaroslav@67
   747
     * @return  the absolute value of the argument.
jaroslav@67
   748
     */
jaroslav@67
   749
    public static long abs(long a) {
jaroslav@67
   750
        return (a < 0) ? -a : a;
jaroslav@67
   751
    }
jaroslav@67
   752
jaroslav@67
   753
    /**
jaroslav@67
   754
     * Returns the absolute value of a {@code float} value.
jaroslav@67
   755
     * If the argument is not negative, the argument is returned.
jaroslav@67
   756
     * If the argument is negative, the negation of the argument is returned.
jaroslav@67
   757
     * Special cases:
jaroslav@67
   758
     * <ul><li>If the argument is positive zero or negative zero, the
jaroslav@67
   759
     * result is positive zero.
jaroslav@67
   760
     * <li>If the argument is infinite, the result is positive infinity.
jaroslav@67
   761
     * <li>If the argument is NaN, the result is NaN.</ul>
jaroslav@67
   762
     * In other words, the result is the same as the value of the expression:
jaroslav@67
   763
     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
jaroslav@67
   764
     *
jaroslav@67
   765
     * @param   a   the argument whose absolute value is to be determined
jaroslav@67
   766
     * @return  the absolute value of the argument.
jaroslav@67
   767
     */
jaroslav@67
   768
    public static float abs(float a) {
jaroslav@67
   769
        return (a <= 0.0F) ? 0.0F - a : a;
jaroslav@67
   770
    }
jaroslav@67
   771
jaroslav@67
   772
    /**
jaroslav@67
   773
     * Returns the absolute value of a {@code double} value.
jaroslav@67
   774
     * If the argument is not negative, the argument is returned.
jaroslav@67
   775
     * If the argument is negative, the negation of the argument is returned.
jaroslav@67
   776
     * Special cases:
jaroslav@67
   777
     * <ul><li>If the argument is positive zero or negative zero, the result
jaroslav@67
   778
     * is positive zero.
jaroslav@67
   779
     * <li>If the argument is infinite, the result is positive infinity.
jaroslav@67
   780
     * <li>If the argument is NaN, the result is NaN.</ul>
jaroslav@67
   781
     * In other words, the result is the same as the value of the expression:
jaroslav@67
   782
     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
jaroslav@67
   783
     *
jaroslav@67
   784
     * @param   a   the argument whose absolute value is to be determined
jaroslav@67
   785
     * @return  the absolute value of the argument.
jaroslav@67
   786
     */
jaroslav@67
   787
    public static double abs(double a) {
jaroslav@67
   788
        return (a <= 0.0D) ? 0.0D - a : a;
jaroslav@67
   789
    }
jaroslav@67
   790
jaroslav@67
   791
    /**
jaroslav@67
   792
     * Returns the greater of two {@code int} values. That is, the
jaroslav@67
   793
     * result is the argument closer to the value of
jaroslav@67
   794
     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
jaroslav@67
   795
     * the result is that same value.
jaroslav@67
   796
     *
jaroslav@67
   797
     * @param   a   an argument.
jaroslav@67
   798
     * @param   b   another argument.
jaroslav@67
   799
     * @return  the larger of {@code a} and {@code b}.
jaroslav@67
   800
     */
jaroslav@67
   801
    public static int max(int a, int b) {
jaroslav@67
   802
        return (a >= b) ? a : b;
jaroslav@67
   803
    }
jaroslav@67
   804
jaroslav@67
   805
    /**
jaroslav@67
   806
     * Returns the greater of two {@code long} values. That is, the
jaroslav@67
   807
     * result is the argument closer to the value of
jaroslav@67
   808
     * {@link Long#MAX_VALUE}. If the arguments have the same value,
jaroslav@67
   809
     * the result is that same value.
jaroslav@67
   810
     *
jaroslav@67
   811
     * @param   a   an argument.
jaroslav@67
   812
     * @param   b   another argument.
jaroslav@67
   813
     * @return  the larger of {@code a} and {@code b}.
jaroslav@67
   814
     */
jaroslav@67
   815
    public static long max(long a, long b) {
jaroslav@67
   816
        return (a >= b) ? a : b;
jaroslav@67
   817
    }
jaroslav@67
   818
jaroslav@67
   819
    private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f);
jaroslav@67
   820
    private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d);
jaroslav@67
   821
jaroslav@67
   822
    /**
jaroslav@67
   823
     * Returns the greater of two {@code float} values.  That is,
jaroslav@67
   824
     * the result is the argument closer to positive infinity. If the
jaroslav@67
   825
     * arguments have the same value, the result is that same
jaroslav@67
   826
     * value. If either value is NaN, then the result is NaN.  Unlike
jaroslav@67
   827
     * the numerical comparison operators, this method considers
jaroslav@67
   828
     * negative zero to be strictly smaller than positive zero. If one
jaroslav@67
   829
     * argument is positive zero and the other negative zero, the
jaroslav@67
   830
     * result is positive zero.
jaroslav@67
   831
     *
jaroslav@67
   832
     * @param   a   an argument.
jaroslav@67
   833
     * @param   b   another argument.
jaroslav@67
   834
     * @return  the larger of {@code a} and {@code b}.
jaroslav@67
   835
     */
jaroslav@67
   836
    public static float max(float a, float b) {
jaroslav@67
   837
        if (a != a) return a;   // a is NaN
jaroslav@67
   838
        if ((a == 0.0f) && (b == 0.0f)
jaroslav@67
   839
            && (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
jaroslav@67
   840
            return b;
jaroslav@67
   841
        }
jaroslav@67
   842
        return (a >= b) ? a : b;
jaroslav@67
   843
    }
jaroslav@67
   844
jaroslav@67
   845
    /**
jaroslav@67
   846
     * Returns the greater of two {@code double} values.  That
jaroslav@67
   847
     * is, the result is the argument closer to positive infinity. If
jaroslav@67
   848
     * the arguments have the same value, the result is that same
jaroslav@67
   849
     * value. If either value is NaN, then the result is NaN.  Unlike
jaroslav@67
   850
     * the numerical comparison operators, this method considers
jaroslav@67
   851
     * negative zero to be strictly smaller than positive zero. If one
jaroslav@67
   852
     * argument is positive zero and the other negative zero, the
jaroslav@67
   853
     * result is positive zero.
jaroslav@67
   854
     *
jaroslav@67
   855
     * @param   a   an argument.
jaroslav@67
   856
     * @param   b   another argument.
jaroslav@67
   857
     * @return  the larger of {@code a} and {@code b}.
jaroslav@67
   858
     */
jaroslav@67
   859
    public static double max(double a, double b) {
jaroslav@67
   860
        if (a != a) return a;   // a is NaN
jaroslav@67
   861
        if ((a == 0.0d) && (b == 0.0d)
jaroslav@67
   862
            && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
jaroslav@67
   863
            return b;
jaroslav@67
   864
        }
jaroslav@67
   865
        return (a >= b) ? a : b;
jaroslav@67
   866
    }
jaroslav@67
   867
jaroslav@67
   868
    /**
jaroslav@67
   869
     * Returns the smaller of two {@code int} values. That is,
jaroslav@67
   870
     * the result the argument closer to the value of
jaroslav@67
   871
     * {@link Integer#MIN_VALUE}.  If the arguments have the same
jaroslav@67
   872
     * value, the result is that same value.
jaroslav@67
   873
     *
jaroslav@67
   874
     * @param   a   an argument.
jaroslav@67
   875
     * @param   b   another argument.
jaroslav@67
   876
     * @return  the smaller of {@code a} and {@code b}.
jaroslav@67
   877
     */
jaroslav@67
   878
    public static int min(int a, int b) {
jaroslav@67
   879
        return (a <= b) ? a : b;
jaroslav@67
   880
    }
jaroslav@67
   881
jaroslav@67
   882
    /**
jaroslav@67
   883
     * Returns the smaller of two {@code long} values. That is,
jaroslav@67
   884
     * the result is the argument closer to the value of
jaroslav@67
   885
     * {@link Long#MIN_VALUE}. If the arguments have the same
jaroslav@67
   886
     * value, the result is that same value.
jaroslav@67
   887
     *
jaroslav@67
   888
     * @param   a   an argument.
jaroslav@67
   889
     * @param   b   another argument.
jaroslav@67
   890
     * @return  the smaller of {@code a} and {@code b}.
jaroslav@67
   891
     */
jaroslav@67
   892
    public static long min(long a, long b) {
jaroslav@67
   893
        return (a <= b) ? a : b;
jaroslav@67
   894
    }
jaroslav@67
   895
jaroslav@67
   896
    /**
jaroslav@67
   897
     * Returns the smaller of two {@code float} values.  That is,
jaroslav@67
   898
     * the result is the value closer to negative infinity. If the
jaroslav@67
   899
     * arguments have the same value, the result is that same
jaroslav@67
   900
     * value. If either value is NaN, then the result is NaN.  Unlike
jaroslav@67
   901
     * the numerical comparison operators, this method considers
jaroslav@67
   902
     * negative zero to be strictly smaller than positive zero.  If
jaroslav@67
   903
     * one argument is positive zero and the other is negative zero,
jaroslav@67
   904
     * the result is negative zero.
jaroslav@67
   905
     *
jaroslav@67
   906
     * @param   a   an argument.
jaroslav@67
   907
     * @param   b   another argument.
jaroslav@67
   908
     * @return  the smaller of {@code a} and {@code b}.
jaroslav@67
   909
     */
jaroslav@67
   910
    public static float min(float a, float b) {
jaroslav@67
   911
        if (a != a) return a;   // a is NaN
jaroslav@67
   912
        if ((a == 0.0f) && (b == 0.0f)
jaroslav@67
   913
            && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
jaroslav@67
   914
            return b;
jaroslav@67
   915
        }
jaroslav@67
   916
        return (a <= b) ? a : b;
jaroslav@67
   917
    }
jaroslav@67
   918
jaroslav@67
   919
    /**
jaroslav@67
   920
     * Returns the smaller of two {@code double} values.  That
jaroslav@67
   921
     * is, the result is the value closer to negative infinity. If the
jaroslav@67
   922
     * arguments have the same value, the result is that same
jaroslav@67
   923
     * value. If either value is NaN, then the result is NaN.  Unlike
jaroslav@67
   924
     * the numerical comparison operators, this method considers
jaroslav@67
   925
     * negative zero to be strictly smaller than positive zero. If one
jaroslav@67
   926
     * argument is positive zero and the other is negative zero, the
jaroslav@67
   927
     * result is negative zero.
jaroslav@67
   928
     *
jaroslav@67
   929
     * @param   a   an argument.
jaroslav@67
   930
     * @param   b   another argument.
jaroslav@67
   931
     * @return  the smaller of {@code a} and {@code b}.
jaroslav@67
   932
     */
jaroslav@67
   933
    public static double min(double a, double b) {
jaroslav@67
   934
        if (a != a) return a;   // a is NaN
jaroslav@67
   935
        if ((a == 0.0d) && (b == 0.0d)
jaroslav@67
   936
            && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
jaroslav@67
   937
            return b;
jaroslav@67
   938
        }
jaroslav@67
   939
        return (a <= b) ? a : b;
jaroslav@67
   940
    }
jaroslav@67
   941
jaroslav@67
   942
    /**
jaroslav@67
   943
     * Returns the size of an ulp of the argument.  An ulp of a
jaroslav@67
   944
     * {@code double} value is the positive distance between this
jaroslav@67
   945
     * floating-point value and the {@code double} value next
jaroslav@67
   946
     * larger in magnitude.  Note that for non-NaN <i>x</i>,
jaroslav@67
   947
     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
jaroslav@67
   948
     *
jaroslav@67
   949
     * <p>Special Cases:
jaroslav@67
   950
     * <ul>
jaroslav@67
   951
     * <li> If the argument is NaN, then the result is NaN.
jaroslav@67
   952
     * <li> If the argument is positive or negative infinity, then the
jaroslav@67
   953
     * result is positive infinity.
jaroslav@67
   954
     * <li> If the argument is positive or negative zero, then the result is
jaroslav@67
   955
     * {@code Double.MIN_VALUE}.
jaroslav@67
   956
     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
jaroslav@67
   957
     * the result is equal to 2<sup>971</sup>.
jaroslav@67
   958
     * </ul>
jaroslav@67
   959
     *
jaroslav@67
   960
     * @param d the floating-point value whose ulp is to be returned
jaroslav@67
   961
     * @return the size of an ulp of the argument
jaroslav@67
   962
     * @author Joseph D. Darcy
jaroslav@67
   963
     * @since 1.5
jaroslav@67
   964
     */
jaroslav@67
   965
    public static double ulp(double d) {
jaroslav@67
   966
        return sun.misc.FpUtils.ulp(d);
jaroslav@67
   967
    }
jaroslav@67
   968
jaroslav@67
   969
    /**
jaroslav@67
   970
     * Returns the size of an ulp of the argument.  An ulp of a
jaroslav@67
   971
     * {@code float} value is the positive distance between this
jaroslav@67
   972
     * floating-point value and the {@code float} value next
jaroslav@67
   973
     * larger in magnitude.  Note that for non-NaN <i>x</i>,
jaroslav@67
   974
     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
jaroslav@67
   975
     *
jaroslav@67
   976
     * <p>Special Cases:
jaroslav@67
   977
     * <ul>
jaroslav@67
   978
     * <li> If the argument is NaN, then the result is NaN.
jaroslav@67
   979
     * <li> If the argument is positive or negative infinity, then the
jaroslav@67
   980
     * result is positive infinity.
jaroslav@67
   981
     * <li> If the argument is positive or negative zero, then the result is
jaroslav@67
   982
     * {@code Float.MIN_VALUE}.
jaroslav@67
   983
     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
jaroslav@67
   984
     * the result is equal to 2<sup>104</sup>.
jaroslav@67
   985
     * </ul>
jaroslav@67
   986
     *
jaroslav@67
   987
     * @param f the floating-point value whose ulp is to be returned
jaroslav@67
   988
     * @return the size of an ulp of the argument
jaroslav@67
   989
     * @author Joseph D. Darcy
jaroslav@67
   990
     * @since 1.5
jaroslav@67
   991
     */
jaroslav@67
   992
    public static float ulp(float f) {
jaroslav@67
   993
        return sun.misc.FpUtils.ulp(f);
jaroslav@67
   994
    }
jaroslav@67
   995
jaroslav@67
   996
    /**
jaroslav@67
   997
     * Returns the signum function of the argument; zero if the argument
jaroslav@67
   998
     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
jaroslav@67
   999
     * argument is less than zero.
jaroslav@67
  1000
     *
jaroslav@67
  1001
     * <p>Special Cases:
jaroslav@67
  1002
     * <ul>
jaroslav@67
  1003
     * <li> If the argument is NaN, then the result is NaN.
jaroslav@67
  1004
     * <li> If the argument is positive zero or negative zero, then the
jaroslav@67
  1005
     *      result is the same as the argument.
jaroslav@67
  1006
     * </ul>
jaroslav@67
  1007
     *
jaroslav@67
  1008
     * @param d the floating-point value whose signum is to be returned
jaroslav@67
  1009
     * @return the signum function of the argument
jaroslav@67
  1010
     * @author Joseph D. Darcy
jaroslav@67
  1011
     * @since 1.5
jaroslav@67
  1012
     */
jaroslav@67
  1013
    public static double signum(double d) {
jaroslav@67
  1014
        return sun.misc.FpUtils.signum(d);
jaroslav@67
  1015
    }
jaroslav@67
  1016
jaroslav@67
  1017
    /**
jaroslav@67
  1018
     * Returns the signum function of the argument; zero if the argument
jaroslav@67
  1019
     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
jaroslav@67
  1020
     * argument is less than zero.
jaroslav@67
  1021
     *
jaroslav@67
  1022
     * <p>Special Cases:
jaroslav@67
  1023
     * <ul>
jaroslav@67
  1024
     * <li> If the argument is NaN, then the result is NaN.
jaroslav@67
  1025
     * <li> If the argument is positive zero or negative zero, then the
jaroslav@67
  1026
     *      result is the same as the argument.
jaroslav@67
  1027
     * </ul>
jaroslav@67
  1028
     *
jaroslav@67
  1029
     * @param f the floating-point value whose signum is to be returned
jaroslav@67
  1030
     * @return the signum function of the argument
jaroslav@67
  1031
     * @author Joseph D. Darcy
jaroslav@67
  1032
     * @since 1.5
jaroslav@67
  1033
     */
jaroslav@67
  1034
    public static float signum(float f) {
jaroslav@67
  1035
        return sun.misc.FpUtils.signum(f);
jaroslav@67
  1036
    }
jaroslav@67
  1037
jaroslav@67
  1038
    /**
jaroslav@67
  1039
     * Returns the hyperbolic sine of a {@code double} value.
jaroslav@67
  1040
     * The hyperbolic sine of <i>x</i> is defined to be
jaroslav@67
  1041
     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
jaroslav@67
  1042
     * where <i>e</i> is {@linkplain Math#E Euler's number}.
jaroslav@67
  1043
     *
jaroslav@67
  1044
     * <p>Special cases:
jaroslav@67
  1045
     * <ul>
jaroslav@67
  1046
     *
jaroslav@67
  1047
     * <li>If the argument is NaN, then the result is NaN.
jaroslav@67
  1048
     *
jaroslav@67
  1049
     * <li>If the argument is infinite, then the result is an infinity
jaroslav@67
  1050
     * with the same sign as the argument.
jaroslav@67
  1051
     *
jaroslav@67
  1052
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
  1053
     * same sign as the argument.
jaroslav@67
  1054
     *
jaroslav@67
  1055
     * </ul>
jaroslav@67
  1056
     *
jaroslav@67
  1057
     * <p>The computed result must be within 2.5 ulps of the exact result.
jaroslav@67
  1058
     *
jaroslav@67
  1059
     * @param   x The number whose hyperbolic sine is to be returned.
jaroslav@67
  1060
     * @return  The hyperbolic sine of {@code x}.
jaroslav@67
  1061
     * @since 1.5
jaroslav@67
  1062
     */
jaroslav@67
  1063
    public static double sinh(double x) {
jaroslav@67
  1064
        return StrictMath.sinh(x);
jaroslav@67
  1065
    }
jaroslav@67
  1066
jaroslav@67
  1067
    /**
jaroslav@67
  1068
     * Returns the hyperbolic cosine of a {@code double} value.
jaroslav@67
  1069
     * The hyperbolic cosine of <i>x</i> is defined to be
jaroslav@67
  1070
     * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
jaroslav@67
  1071
     * where <i>e</i> is {@linkplain Math#E Euler's number}.
jaroslav@67
  1072
     *
jaroslav@67
  1073
     * <p>Special cases:
jaroslav@67
  1074
     * <ul>
jaroslav@67
  1075
     *
jaroslav@67
  1076
     * <li>If the argument is NaN, then the result is NaN.
jaroslav@67
  1077
     *
jaroslav@67
  1078
     * <li>If the argument is infinite, then the result is positive
jaroslav@67
  1079
     * infinity.
jaroslav@67
  1080
     *
jaroslav@67
  1081
     * <li>If the argument is zero, then the result is {@code 1.0}.
jaroslav@67
  1082
     *
jaroslav@67
  1083
     * </ul>
jaroslav@67
  1084
     *
jaroslav@67
  1085
     * <p>The computed result must be within 2.5 ulps of the exact result.
jaroslav@67
  1086
     *
jaroslav@67
  1087
     * @param   x The number whose hyperbolic cosine is to be returned.
jaroslav@67
  1088
     * @return  The hyperbolic cosine of {@code x}.
jaroslav@67
  1089
     * @since 1.5
jaroslav@67
  1090
     */
jaroslav@67
  1091
    public static double cosh(double x) {
jaroslav@67
  1092
        return StrictMath.cosh(x);
jaroslav@67
  1093
    }
jaroslav@67
  1094
jaroslav@67
  1095
    /**
jaroslav@67
  1096
     * Returns the hyperbolic tangent of a {@code double} value.
jaroslav@67
  1097
     * The hyperbolic tangent of <i>x</i> is defined to be
jaroslav@67
  1098
     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/(<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>),
jaroslav@67
  1099
     * in other words, {@linkplain Math#sinh
jaroslav@67
  1100
     * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
jaroslav@67
  1101
     * that the absolute value of the exact tanh is always less than
jaroslav@67
  1102
     * 1.
jaroslav@67
  1103
     *
jaroslav@67
  1104
     * <p>Special cases:
jaroslav@67
  1105
     * <ul>
jaroslav@67
  1106
     *
jaroslav@67
  1107
     * <li>If the argument is NaN, then the result is NaN.
jaroslav@67
  1108
     *
jaroslav@67
  1109
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
  1110
     * same sign as the argument.
jaroslav@67
  1111
     *
jaroslav@67
  1112
     * <li>If the argument is positive infinity, then the result is
jaroslav@67
  1113
     * {@code +1.0}.
jaroslav@67
  1114
     *
jaroslav@67
  1115
     * <li>If the argument is negative infinity, then the result is
jaroslav@67
  1116
     * {@code -1.0}.
jaroslav@67
  1117
     *
jaroslav@67
  1118
     * </ul>
jaroslav@67
  1119
     *
jaroslav@67
  1120
     * <p>The computed result must be within 2.5 ulps of the exact result.
jaroslav@67
  1121
     * The result of {@code tanh} for any finite input must have
jaroslav@67
  1122
     * an absolute value less than or equal to 1.  Note that once the
jaroslav@67
  1123
     * exact result of tanh is within 1/2 of an ulp of the limit value
jaroslav@67
  1124
     * of &plusmn;1, correctly signed &plusmn;{@code 1.0} should
jaroslav@67
  1125
     * be returned.
jaroslav@67
  1126
     *
jaroslav@67
  1127
     * @param   x The number whose hyperbolic tangent is to be returned.
jaroslav@67
  1128
     * @return  The hyperbolic tangent of {@code x}.
jaroslav@67
  1129
     * @since 1.5
jaroslav@67
  1130
     */
jaroslav@67
  1131
    public static double tanh(double x) {
jaroslav@67
  1132
        return StrictMath.tanh(x);
jaroslav@67
  1133
    }
jaroslav@67
  1134
jaroslav@67
  1135
    /**
jaroslav@67
  1136
     * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
jaroslav@67
  1137
     * without intermediate overflow or underflow.
jaroslav@67
  1138
     *
jaroslav@67
  1139
     * <p>Special cases:
jaroslav@67
  1140
     * <ul>
jaroslav@67
  1141
     *
jaroslav@67
  1142
     * <li> If either argument is infinite, then the result
jaroslav@67
  1143
     * is positive infinity.
jaroslav@67
  1144
     *
jaroslav@67
  1145
     * <li> If either argument is NaN and neither argument is infinite,
jaroslav@67
  1146
     * then the result is NaN.
jaroslav@67
  1147
     *
jaroslav@67
  1148
     * </ul>
jaroslav@67
  1149
     *
jaroslav@67
  1150
     * <p>The computed result must be within 1 ulp of the exact
jaroslav@67
  1151
     * result.  If one parameter is held constant, the results must be
jaroslav@67
  1152
     * semi-monotonic in the other parameter.
jaroslav@67
  1153
     *
jaroslav@67
  1154
     * @param x a value
jaroslav@67
  1155
     * @param y a value
jaroslav@67
  1156
     * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
jaroslav@67
  1157
     * without intermediate overflow or underflow
jaroslav@67
  1158
     * @since 1.5
jaroslav@67
  1159
     */
jaroslav@67
  1160
    public static double hypot(double x, double y) {
jaroslav@67
  1161
        return StrictMath.hypot(x, y);
jaroslav@67
  1162
    }
jaroslav@67
  1163
jaroslav@67
  1164
    /**
jaroslav@67
  1165
     * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
jaroslav@67
  1166
     * <i>x</i> near 0, the exact sum of
jaroslav@67
  1167
     * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
jaroslav@67
  1168
     * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
jaroslav@67
  1169
     *
jaroslav@67
  1170
     * <p>Special cases:
jaroslav@67
  1171
     * <ul>
jaroslav@67
  1172
     * <li>If the argument is NaN, the result is NaN.
jaroslav@67
  1173
     *
jaroslav@67
  1174
     * <li>If the argument is positive infinity, then the result is
jaroslav@67
  1175
     * positive infinity.
jaroslav@67
  1176
     *
jaroslav@67
  1177
     * <li>If the argument is negative infinity, then the result is
jaroslav@67
  1178
     * -1.0.
jaroslav@67
  1179
     *
jaroslav@67
  1180
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
  1181
     * same sign as the argument.
jaroslav@67
  1182
     *
jaroslav@67
  1183
     * </ul>
jaroslav@67
  1184
     *
jaroslav@67
  1185
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
  1186
     * Results must be semi-monotonic.  The result of
jaroslav@67
  1187
     * {@code expm1} for any finite input must be greater than or
jaroslav@67
  1188
     * equal to {@code -1.0}.  Note that once the exact result of
jaroslav@67
  1189
     * <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1 is within 1/2
jaroslav@67
  1190
     * ulp of the limit value -1, {@code -1.0} should be
jaroslav@67
  1191
     * returned.
jaroslav@67
  1192
     *
jaroslav@67
  1193
     * @param   x   the exponent to raise <i>e</i> to in the computation of
jaroslav@67
  1194
     *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
jaroslav@67
  1195
     * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
jaroslav@67
  1196
     * @since 1.5
jaroslav@67
  1197
     */
jaroslav@67
  1198
    public static double expm1(double x) {
jaroslav@67
  1199
        return StrictMath.expm1(x);
jaroslav@67
  1200
    }
jaroslav@67
  1201
jaroslav@67
  1202
    /**
jaroslav@67
  1203
     * Returns the natural logarithm of the sum of the argument and 1.
jaroslav@67
  1204
     * Note that for small values {@code x}, the result of
jaroslav@67
  1205
     * {@code log1p(x)} is much closer to the true result of ln(1
jaroslav@67
  1206
     * + {@code x}) than the floating-point evaluation of
jaroslav@67
  1207
     * {@code log(1.0+x)}.
jaroslav@67
  1208
     *
jaroslav@67
  1209
     * <p>Special cases:
jaroslav@67
  1210
     *
jaroslav@67
  1211
     * <ul>
jaroslav@67
  1212
     *
jaroslav@67
  1213
     * <li>If the argument is NaN or less than -1, then the result is
jaroslav@67
  1214
     * NaN.
jaroslav@67
  1215
     *
jaroslav@67
  1216
     * <li>If the argument is positive infinity, then the result is
jaroslav@67
  1217
     * positive infinity.
jaroslav@67
  1218
     *
jaroslav@67
  1219
     * <li>If the argument is negative one, then the result is
jaroslav@67
  1220
     * negative infinity.
jaroslav@67
  1221
     *
jaroslav@67
  1222
     * <li>If the argument is zero, then the result is a zero with the
jaroslav@67
  1223
     * same sign as the argument.
jaroslav@67
  1224
     *
jaroslav@67
  1225
     * </ul>
jaroslav@67
  1226
     *
jaroslav@67
  1227
     * <p>The computed result must be within 1 ulp of the exact result.
jaroslav@67
  1228
     * Results must be semi-monotonic.
jaroslav@67
  1229
     *
jaroslav@67
  1230
     * @param   x   a value
jaroslav@67
  1231
     * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
jaroslav@67
  1232
     * log of {@code x}&nbsp;+&nbsp;1
jaroslav@67
  1233
     * @since 1.5
jaroslav@67
  1234
     */
jaroslav@67
  1235
    public static double log1p(double x) {
jaroslav@67
  1236
        return StrictMath.log1p(x);
jaroslav@67
  1237
    }
jaroslav@67
  1238
jaroslav@67
  1239
    /**
jaroslav@67
  1240
     * Returns the first floating-point argument with the sign of the
jaroslav@67
  1241
     * second floating-point argument.  Note that unlike the {@link
jaroslav@67
  1242
     * StrictMath#copySign(double, double) StrictMath.copySign}
jaroslav@67
  1243
     * method, this method does not require NaN {@code sign}
jaroslav@67
  1244
     * arguments to be treated as positive values; implementations are
jaroslav@67
  1245
     * permitted to treat some NaN arguments as positive and other NaN
jaroslav@67
  1246
     * arguments as negative to allow greater performance.
jaroslav@67
  1247
     *
jaroslav@67
  1248
     * @param magnitude  the parameter providing the magnitude of the result
jaroslav@67
  1249
     * @param sign   the parameter providing the sign of the result
jaroslav@67
  1250
     * @return a value with the magnitude of {@code magnitude}
jaroslav@67
  1251
     * and the sign of {@code sign}.
jaroslav@67
  1252
     * @since 1.6
jaroslav@67
  1253
     */
jaroslav@67
  1254
    public static double copySign(double magnitude, double sign) {
jaroslav@67
  1255
        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
jaroslav@67
  1256
    }
jaroslav@67
  1257
jaroslav@67
  1258
    /**
jaroslav@67
  1259
     * Returns the first floating-point argument with the sign of the
jaroslav@67
  1260
     * second floating-point argument.  Note that unlike the {@link
jaroslav@67
  1261
     * StrictMath#copySign(float, float) StrictMath.copySign}
jaroslav@67
  1262
     * method, this method does not require NaN {@code sign}
jaroslav@67
  1263
     * arguments to be treated as positive values; implementations are
jaroslav@67
  1264
     * permitted to treat some NaN arguments as positive and other NaN
jaroslav@67
  1265
     * arguments as negative to allow greater performance.
jaroslav@67
  1266
     *
jaroslav@67
  1267
     * @param magnitude  the parameter providing the magnitude of the result
jaroslav@67
  1268
     * @param sign   the parameter providing the sign of the result
jaroslav@67
  1269
     * @return a value with the magnitude of {@code magnitude}
jaroslav@67
  1270
     * and the sign of {@code sign}.
jaroslav@67
  1271
     * @since 1.6
jaroslav@67
  1272
     */
jaroslav@67
  1273
    public static float copySign(float magnitude, float sign) {
jaroslav@67
  1274
        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
jaroslav@67
  1275
    }
jaroslav@67
  1276
jaroslav@67
  1277
    /**
jaroslav@67
  1278
     * Returns the unbiased exponent used in the representation of a
jaroslav@67
  1279
     * {@code float}.  Special cases:
jaroslav@67
  1280
     *
jaroslav@67
  1281
     * <ul>
jaroslav@67
  1282
     * <li>If the argument is NaN or infinite, then the result is
jaroslav@67
  1283
     * {@link Float#MAX_EXPONENT} + 1.
jaroslav@67
  1284
     * <li>If the argument is zero or subnormal, then the result is
jaroslav@67
  1285
     * {@link Float#MIN_EXPONENT} -1.
jaroslav@67
  1286
     * </ul>
jaroslav@67
  1287
     * @param f a {@code float} value
jaroslav@67
  1288
     * @return the unbiased exponent of the argument
jaroslav@67
  1289
     * @since 1.6
jaroslav@67
  1290
     */
jaroslav@67
  1291
    public static int getExponent(float f) {
jaroslav@67
  1292
        return sun.misc.FpUtils.getExponent(f);
jaroslav@67
  1293
    }
jaroslav@67
  1294
jaroslav@67
  1295
    /**
jaroslav@67
  1296
     * Returns the unbiased exponent used in the representation of a
jaroslav@67
  1297
     * {@code double}.  Special cases:
jaroslav@67
  1298
     *
jaroslav@67
  1299
     * <ul>
jaroslav@67
  1300
     * <li>If the argument is NaN or infinite, then the result is
jaroslav@67
  1301
     * {@link Double#MAX_EXPONENT} + 1.
jaroslav@67
  1302
     * <li>If the argument is zero or subnormal, then the result is
jaroslav@67
  1303
     * {@link Double#MIN_EXPONENT} -1.
jaroslav@67
  1304
     * </ul>
jaroslav@67
  1305
     * @param d a {@code double} value
jaroslav@67
  1306
     * @return the unbiased exponent of the argument
jaroslav@67
  1307
     * @since 1.6
jaroslav@67
  1308
     */
jaroslav@67
  1309
    public static int getExponent(double d) {
jaroslav@67
  1310
        return sun.misc.FpUtils.getExponent(d);
jaroslav@67
  1311
    }
jaroslav@67
  1312
jaroslav@67
  1313
    /**
jaroslav@67
  1314
     * Returns the floating-point number adjacent to the first
jaroslav@67
  1315
     * argument in the direction of the second argument.  If both
jaroslav@67
  1316
     * arguments compare as equal the second argument is returned.
jaroslav@67
  1317
     *
jaroslav@67
  1318
     * <p>
jaroslav@67
  1319
     * Special cases:
jaroslav@67
  1320
     * <ul>
jaroslav@67
  1321
     * <li> If either argument is a NaN, then NaN is returned.
jaroslav@67
  1322
     *
jaroslav@67
  1323
     * <li> If both arguments are signed zeros, {@code direction}
jaroslav@67
  1324
     * is returned unchanged (as implied by the requirement of
jaroslav@67
  1325
     * returning the second argument if the arguments compare as
jaroslav@67
  1326
     * equal).
jaroslav@67
  1327
     *
jaroslav@67
  1328
     * <li> If {@code start} is
jaroslav@67
  1329
     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
jaroslav@67
  1330
     * has a value such that the result should have a smaller
jaroslav@67
  1331
     * magnitude, then a zero with the same sign as {@code start}
jaroslav@67
  1332
     * is returned.
jaroslav@67
  1333
     *
jaroslav@67
  1334
     * <li> If {@code start} is infinite and
jaroslav@67
  1335
     * {@code direction} has a value such that the result should
jaroslav@67
  1336
     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
jaroslav@67
  1337
     * same sign as {@code start} is returned.
jaroslav@67
  1338
     *
jaroslav@67
  1339
     * <li> If {@code start} is equal to &plusmn;
jaroslav@67
  1340
     * {@link Double#MAX_VALUE} and {@code direction} has a
jaroslav@67
  1341
     * value such that the result should have a larger magnitude, an
jaroslav@67
  1342
     * infinity with same sign as {@code start} is returned.
jaroslav@67
  1343
     * </ul>
jaroslav@67
  1344
     *
jaroslav@67
  1345
     * @param start  starting floating-point value
jaroslav@67
  1346
     * @param direction value indicating which of
jaroslav@67
  1347
     * {@code start}'s neighbors or {@code start} should
jaroslav@67
  1348
     * be returned
jaroslav@67
  1349
     * @return The floating-point number adjacent to {@code start} in the
jaroslav@67
  1350
     * direction of {@code direction}.
jaroslav@67
  1351
     * @since 1.6
jaroslav@67
  1352
     */
jaroslav@67
  1353
    public static double nextAfter(double start, double direction) {
jaroslav@67
  1354
        return sun.misc.FpUtils.nextAfter(start, direction);
jaroslav@67
  1355
    }
jaroslav@67
  1356
jaroslav@67
  1357
    /**
jaroslav@67
  1358
     * Returns the floating-point number adjacent to the first
jaroslav@67
  1359
     * argument in the direction of the second argument.  If both
jaroslav@67
  1360
     * arguments compare as equal a value equivalent to the second argument
jaroslav@67
  1361
     * is returned.
jaroslav@67
  1362
     *
jaroslav@67
  1363
     * <p>
jaroslav@67
  1364
     * Special cases:
jaroslav@67
  1365
     * <ul>
jaroslav@67
  1366
     * <li> If either argument is a NaN, then NaN is returned.
jaroslav@67
  1367
     *
jaroslav@67
  1368
     * <li> If both arguments are signed zeros, a value equivalent
jaroslav@67
  1369
     * to {@code direction} is returned.
jaroslav@67
  1370
     *
jaroslav@67
  1371
     * <li> If {@code start} is
jaroslav@67
  1372
     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
jaroslav@67
  1373
     * has a value such that the result should have a smaller
jaroslav@67
  1374
     * magnitude, then a zero with the same sign as {@code start}
jaroslav@67
  1375
     * is returned.
jaroslav@67
  1376
     *
jaroslav@67
  1377
     * <li> If {@code start} is infinite and
jaroslav@67
  1378
     * {@code direction} has a value such that the result should
jaroslav@67
  1379
     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
jaroslav@67
  1380
     * same sign as {@code start} is returned.
jaroslav@67
  1381
     *
jaroslav@67
  1382
     * <li> If {@code start} is equal to &plusmn;
jaroslav@67
  1383
     * {@link Float#MAX_VALUE} and {@code direction} has a
jaroslav@67
  1384
     * value such that the result should have a larger magnitude, an
jaroslav@67
  1385
     * infinity with same sign as {@code start} is returned.
jaroslav@67
  1386
     * </ul>
jaroslav@67
  1387
     *
jaroslav@67
  1388
     * @param start  starting floating-point value
jaroslav@67
  1389
     * @param direction value indicating which of
jaroslav@67
  1390
     * {@code start}'s neighbors or {@code start} should
jaroslav@67
  1391
     * be returned
jaroslav@67
  1392
     * @return The floating-point number adjacent to {@code start} in the
jaroslav@67
  1393
     * direction of {@code direction}.
jaroslav@67
  1394
     * @since 1.6
jaroslav@67
  1395
     */
jaroslav@67
  1396
    public static float nextAfter(float start, double direction) {
jaroslav@67
  1397
        return sun.misc.FpUtils.nextAfter(start, direction);
jaroslav@67
  1398
    }
jaroslav@67
  1399
jaroslav@67
  1400
    /**
jaroslav@67
  1401
     * Returns the floating-point value adjacent to {@code d} in
jaroslav@67
  1402
     * the direction of positive infinity.  This method is
jaroslav@67
  1403
     * semantically equivalent to {@code nextAfter(d,
jaroslav@67
  1404
     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
jaroslav@67
  1405
     * implementation may run faster than its equivalent
jaroslav@67
  1406
     * {@code nextAfter} call.
jaroslav@67
  1407
     *
jaroslav@67
  1408
     * <p>Special Cases:
jaroslav@67
  1409
     * <ul>
jaroslav@67
  1410
     * <li> If the argument is NaN, the result is NaN.
jaroslav@67
  1411
     *
jaroslav@67
  1412
     * <li> If the argument is positive infinity, the result is
jaroslav@67
  1413
     * positive infinity.
jaroslav@67
  1414
     *
jaroslav@67
  1415
     * <li> If the argument is zero, the result is
jaroslav@67
  1416
     * {@link Double#MIN_VALUE}
jaroslav@67
  1417
     *
jaroslav@67
  1418
     * </ul>
jaroslav@67
  1419
     *
jaroslav@67
  1420
     * @param d starting floating-point value
jaroslav@67
  1421
     * @return The adjacent floating-point value closer to positive
jaroslav@67
  1422
     * infinity.
jaroslav@67
  1423
     * @since 1.6
jaroslav@67
  1424
     */
jaroslav@67
  1425
    public static double nextUp(double d) {
jaroslav@67
  1426
        return sun.misc.FpUtils.nextUp(d);
jaroslav@67
  1427
    }
jaroslav@67
  1428
jaroslav@67
  1429
    /**
jaroslav@67
  1430
     * Returns the floating-point value adjacent to {@code f} in
jaroslav@67
  1431
     * the direction of positive infinity.  This method is
jaroslav@67
  1432
     * semantically equivalent to {@code nextAfter(f,
jaroslav@67
  1433
     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
jaroslav@67
  1434
     * implementation may run faster than its equivalent
jaroslav@67
  1435
     * {@code nextAfter} call.
jaroslav@67
  1436
     *
jaroslav@67
  1437
     * <p>Special Cases:
jaroslav@67
  1438
     * <ul>
jaroslav@67
  1439
     * <li> If the argument is NaN, the result is NaN.
jaroslav@67
  1440
     *
jaroslav@67
  1441
     * <li> If the argument is positive infinity, the result is
jaroslav@67
  1442
     * positive infinity.
jaroslav@67
  1443
     *
jaroslav@67
  1444
     * <li> If the argument is zero, the result is
jaroslav@67
  1445
     * {@link Float#MIN_VALUE}
jaroslav@67
  1446
     *
jaroslav@67
  1447
     * </ul>
jaroslav@67
  1448
     *
jaroslav@67
  1449
     * @param f starting floating-point value
jaroslav@67
  1450
     * @return The adjacent floating-point value closer to positive
jaroslav@67
  1451
     * infinity.
jaroslav@67
  1452
     * @since 1.6
jaroslav@67
  1453
     */
jaroslav@67
  1454
    public static float nextUp(float f) {
jaroslav@67
  1455
        return sun.misc.FpUtils.nextUp(f);
jaroslav@67
  1456
    }
jaroslav@67
  1457
jaroslav@67
  1458
jaroslav@67
  1459
    /**
jaroslav@67
  1460
     * Return {@code d} &times;
jaroslav@67
  1461
     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
jaroslav@67
  1462
     * by a single correctly rounded floating-point multiply to a
jaroslav@67
  1463
     * member of the double value set.  See the Java
jaroslav@67
  1464
     * Language Specification for a discussion of floating-point
jaroslav@67
  1465
     * value sets.  If the exponent of the result is between {@link
jaroslav@67
  1466
     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
jaroslav@67
  1467
     * answer is calculated exactly.  If the exponent of the result
jaroslav@67
  1468
     * would be larger than {@code Double.MAX_EXPONENT}, an
jaroslav@67
  1469
     * infinity is returned.  Note that if the result is subnormal,
jaroslav@67
  1470
     * precision may be lost; that is, when {@code scalb(x, n)}
jaroslav@67
  1471
     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
jaroslav@67
  1472
     * <i>x</i>.  When the result is non-NaN, the result has the same
jaroslav@67
  1473
     * sign as {@code d}.
jaroslav@67
  1474
     *
jaroslav@67
  1475
     * <p>Special cases:
jaroslav@67
  1476
     * <ul>
jaroslav@67
  1477
     * <li> If the first argument is NaN, NaN is returned.
jaroslav@67
  1478
     * <li> If the first argument is infinite, then an infinity of the
jaroslav@67
  1479
     * same sign is returned.
jaroslav@67
  1480
     * <li> If the first argument is zero, then a zero of the same
jaroslav@67
  1481
     * sign is returned.
jaroslav@67
  1482
     * </ul>
jaroslav@67
  1483
     *
jaroslav@67
  1484
     * @param d number to be scaled by a power of two.
jaroslav@67
  1485
     * @param scaleFactor power of 2 used to scale {@code d}
jaroslav@67
  1486
     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
jaroslav@67
  1487
     * @since 1.6
jaroslav@67
  1488
     */
jaroslav@67
  1489
    public static double scalb(double d, int scaleFactor) {
jaroslav@67
  1490
        return sun.misc.FpUtils.scalb(d, scaleFactor);
jaroslav@67
  1491
    }
jaroslav@67
  1492
jaroslav@67
  1493
    /**
jaroslav@67
  1494
     * Return {@code f} &times;
jaroslav@67
  1495
     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
jaroslav@67
  1496
     * by a single correctly rounded floating-point multiply to a
jaroslav@67
  1497
     * member of the float value set.  See the Java
jaroslav@67
  1498
     * Language Specification for a discussion of floating-point
jaroslav@67
  1499
     * value sets.  If the exponent of the result is between {@link
jaroslav@67
  1500
     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
jaroslav@67
  1501
     * answer is calculated exactly.  If the exponent of the result
jaroslav@67
  1502
     * would be larger than {@code Float.MAX_EXPONENT}, an
jaroslav@67
  1503
     * infinity is returned.  Note that if the result is subnormal,
jaroslav@67
  1504
     * precision may be lost; that is, when {@code scalb(x, n)}
jaroslav@67
  1505
     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
jaroslav@67
  1506
     * <i>x</i>.  When the result is non-NaN, the result has the same
jaroslav@67
  1507
     * sign as {@code f}.
jaroslav@67
  1508
     *
jaroslav@67
  1509
     * <p>Special cases:
jaroslav@67
  1510
     * <ul>
jaroslav@67
  1511
     * <li> If the first argument is NaN, NaN is returned.
jaroslav@67
  1512
     * <li> If the first argument is infinite, then an infinity of the
jaroslav@67
  1513
     * same sign is returned.
jaroslav@67
  1514
     * <li> If the first argument is zero, then a zero of the same
jaroslav@67
  1515
     * sign is returned.
jaroslav@67
  1516
     * </ul>
jaroslav@67
  1517
     *
jaroslav@67
  1518
     * @param f number to be scaled by a power of two.
jaroslav@67
  1519
     * @param scaleFactor power of 2 used to scale {@code f}
jaroslav@67
  1520
     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
jaroslav@67
  1521
     * @since 1.6
jaroslav@67
  1522
     */
jaroslav@67
  1523
    public static float scalb(float f, int scaleFactor) {
jaroslav@67
  1524
        return sun.misc.FpUtils.scalb(f, scaleFactor);
jaroslav@67
  1525
    }
jaroslav@67
  1526
}