FileDocCategorySizeDatePackage
Math.javaAPI DocAndroid 1.5 API37612Wed May 06 22:41:04 BST 2009java.lang

Math

public final class Math extends Object
Class Math provides basic math constants and operations such as trigonometric functions, hyperbolic functions, exponential, logarithms, etc.
since
Android 1.0

Fields Summary
public static final double
E
The double value closest to e, the base of the natural logarithm.
public static final double
PI
The double value closest to pi, the ratio of a circle's circumference to its diameter.
private static Random
random
Constructors Summary
private Math()
Prevents this class from being instantiated.


               
      
    
Methods Summary
public static native doubleIEEEremainder(double x, double y)
Returns the remainder of dividing {@code x} by {@code y} using the IEEE 754 rules. The result is {@code x-round(x/p)*p} where {@code round(x/p)} is the nearest integer (rounded to even), but without numerical cancellation problems.

Special cases:

  • {@code IEEEremainder((anything), 0) = NaN}
  • {@code IEEEremainder(+infinity, (anything)) = NaN}
  • {@code IEEEremainder(-infinity, (anything)) = NaN}
  • {@code IEEEremainder(NaN, (anything)) = NaN}
  • {@code IEEEremainder((anything), NaN) = NaN}
  • {@code IEEEremainder(x, +infinity) = x } where x is anything but +/-infinity
  • {@code IEEEremainder(x, -infinity) = x } where x is anything but +/-infinity

param
x the numerator of the operation.
param
y the denominator of the operation.
return
the IEEE754 floating point reminder of of {@code x/y}.
since
Android 1.0

public static doubleabs(double d)
Returns the absolute value of the argument.

Special cases:

  • {@code abs(-0.0) = +0.0}
  • {@code abs(+infinity) = +infinity}
  • {@code abs(-infinity) = +infinity}
  • {@code abs(NaN) = NaN}

param
d the value whose absolute value has to be computed.
return
the absolute value of the argument.
since
Android 1.0

        long bits = Double.doubleToLongBits(d);
        bits &= 0x7fffffffffffffffL;
        return Double.longBitsToDouble(bits);
    
public static floatabs(float f)
Returns the absolute value of the argument.

Special cases:

  • {@code abs(-0.0) = +0.0}
  • {@code abs(+infinity) = +infinity}
  • {@code abs(-infinity) = +infinity}
  • {@code abs(NaN) = NaN}

param
f the value whose absolute value has to be computed.
return
the argument if it is positive, otherwise the negation of the argument.
since
Android 1.0

        int bits = Float.floatToIntBits(f);
        bits &= 0x7fffffff;
        return Float.intBitsToFloat(bits);
    
public static intabs(int i)
Returns the absolute value of the argument.

If the argument is {@code Integer.MIN_VALUE}, {@code Integer.MIN_VALUE} is returned.

param
i the value whose absolute value has to be computed.
return
the argument if it is positive, otherwise the negation of the argument.
since
Android 1.0

        return i >= 0 ? i : -i;
    
public static longabs(long l)
Returns the absolute value of the argument. If the argument is {@code Long.MIN_VALUE}, {@code Long.MIN_VALUE} is returned.

param
l the value whose absolute value has to be computed.
return
the argument if it is positive, otherwise the negation of the argument.
since
Android 1.0

        return l >= 0 ? l : -l;
    
public static native doubleacos(double d)
Returns the closest double approximation of the arc cosine of the argument within the range {@code [0..pi]}. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code acos((anything > 1) = NaN}
  • {@code acos((anything < -1) = NaN}
  • {@code acos(NaN) = NaN}

param
d the value to compute arc cosine of.
return
the arc cosine of the argument.
since
Android 1.0

public static native doubleasin(double d)
Returns the closest double approximation of the arc sine of the argument within the range {@code [-pi/2..pi/2]}. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code asin((anything > 1)) = NaN}
  • {@code asin((anything < -1)) = NaN}
  • {@code asin(NaN) = NaN}

param
d the value whose arc sine has to be computed.
return
the arc sine of the argument.
since
Android 1.0

public static native doubleatan(double d)
Returns the closest double approximation of the arc tangent of the argument within the range {@code [-pi/2..pi/2]}. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code atan(+0.0) = +0.0}
  • {@code atan(-0.0) = -0.0}
  • {@code atan(+infinity) = +pi/2}
  • {@code atan(-infinity) = -pi/2}
  • {@code atan(NaN) = NaN}

param
d the value whose arc tangent has to be computed.
return
the arc tangent of the argument.
since
Android 1.0

public static native doubleatan2(double y, double x)
Returns the closest double approximation of the arc tangent of {@code y/x} within the range {@code [-pi..pi]}. This is the angle of the polar representation of the rectangular coordinates (x,y). The returned result is within 2 ulps (units in the last place) of the real result.

Special cases:

  • {@code atan2((anything), NaN ) = NaN;}
  • {@code atan2(NaN , (anything) ) = NaN;}
  • {@code atan2(+0.0, +(anything but NaN)) = +0.0}
  • {@code atan2(-0.0, +(anything but NaN)) = -0.0}
  • {@code atan2(+0.0, -(anything but NaN)) = +pi}
  • {@code atan2(-0.0, -(anything but NaN)) = -pi}
  • {@code atan2(+(anything but 0 and NaN), 0) = +pi/2}
  • {@code atan2(-(anything but 0 and NaN), 0) = -pi/2}
  • {@code atan2(+(anything but infinity and NaN), +infinity)} {@code =} {@code +0.0}
  • {@code atan2(-(anything but infinity and NaN), +infinity)} {@code =} {@code -0.0}
  • {@code atan2(+(anything but infinity and NaN), -infinity) = +pi}
  • {@code atan2(-(anything but infinity and NaN), -infinity) = -pi}
  • {@code atan2(+infinity, +infinity ) = +pi/4}
  • {@code atan2(-infinity, +infinity ) = -pi/4}
  • {@code atan2(+infinity, -infinity ) = +3pi/4}
  • {@code atan2(-infinity, -infinity ) = -3pi/4}
  • {@code atan2(+infinity, (anything but,0, NaN, and infinity))} {@code =} {@code +pi/2}
  • {@code atan2(-infinity, (anything but,0, NaN, and infinity))} {@code =} {@code -pi/2}

param
y the numerator of the value whose atan has to be computed.
param
x the denominator of the value whose atan has to be computed.
return
the arc tangent of {@code y/x}.
since
Android 1.0

public static native doublecbrt(double d)
Returns the closest double approximation of the cube root of the argument.

Special cases:

  • {@code cbrt(+0.0) = +0.0}
  • {@code cbrt(-0.0) = -0.0}
  • {@code cbrt(+infinity) = +infinity}
  • {@code cbrt(-infinity) = -infinity}
  • {@code cbrt(NaN) = NaN}

param
d the value whose cube root has to be computed.
return
the cube root of the argument.
since
Android 1.0

public static native doubleceil(double d)
Returns the double conversion of the most negative (closest to negative infinity) integer value which is greater than the argument.

Special cases:

  • {@code ceil(+0.0) = +0.0}
  • {@code ceil(-0.0) = -0.0}
  • {@code ceil((anything in range (-1,0)) = -0.0}
  • {@code ceil(+infinity) = +infinity}
  • {@code ceil(-infinity) = -infinity}
  • {@code ceil(NaN) = NaN}

param
d the value whose closest integer value has to be computed.
return
the ceiling of the argument.
since
Android 1.0

public static native doublecos(double d)
Returns the closest double approximation of the cosine of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code cos(+infinity) = NaN}
  • {@code cos(-infinity) = NaN}
  • {@code cos(NaN) = NaN}

param
d the angle whose cosine has to be computed, in radians.
return
the cosine of the argument.
since
Android 1.0

public static native doublecosh(double d)
Returns the closest double approximation of the hyperbolic cosine of the argument. The returned result is within 2.5 ulps (units in the last place) of the real result.

Special cases:

  • {@code cosh(+infinity) = +infinity}
  • {@code cosh(-infinity) = +infinity}
  • {@code cosh(NaN) = NaN}

param
d the value whose hyperbolic cosine has to be computed.
return
the hyperbolic cosine of the argument.
since
Android 1.0

public static native doubleexp(double d)
Returns the closest double approximation of the raising "e" to the power of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code exp(+infinity) = +infinity}
  • {@code exp(-infinity) = +0.0}
  • {@code exp(NaN) = NaN}

param
d the value whose exponential has to be computed.
return
the exponential of the argument.
since
Android 1.0

public static native doubleexpm1(double d)
Returns the closest double approximation of {@code e} {@code d}{@code - 1}. If the argument is very close to 0, it is much more accurate to use {@code expm1(d)+1} than {@code exp(d)} (due to cancellation of significant digits). The returned result is within 1 ulp (unit in the last place) of the real result.

For any finite input, the result is not less than -1.0. If the real result is within 0.5 ulp of -1, -1.0 is returned.

Special cases:

  • {@code expm1(+0.0) = +0.0}
  • {@code expm1(-0.0) = -0.0}
  • {@code expm1(+infinity) = +infinity}
  • {@code expm1(-infinity) = -1.0}
  • {@code expm1(NaN) = NaN}

param
d the value to compute the {@code e}{@code d} {@code - 1} of.
return
the {@code e}{@code d}{@code - 1} value of the argument.
since
Android 1.0

public static native doublefloor(double d)
Returns the double conversion of the most positive (closest to positive infinity) integer value which is less than the argument.

Special cases:

  • {@code floor(+0.0) = +0.0}
  • {@code floor(-0.0) = -0.0}
  • {@code floor(+infinity) = +infinity}
  • {@code floor(-infinity) = -infinity}
  • {@code floor(NaN) = NaN}

param
d the value whose closest integer value has to be computed.
return
the floor of the argument.
since
Android 1.0

public static native doublehypot(double x, double y)
Returns {@code sqrt(}{@code x}{@code 2}{@code +} {@code y}{@code 2}{@code )}. The final result is without medium underflow or overflow. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code hypot(+infinity, (anything including NaN)) = +infinity}
  • {@code hypot(-infinity, (anything including NaN)) = +infinity}
  • {@code hypot((anything including NaN), +infinity) = +infinity}
  • {@code hypot((anything including NaN), -infinity) = +infinity}
  • {@code hypot(NaN, NaN) = NaN}

param
x a double number.
param
y a double number.
return
the {@code sqrt(}{@code x}{@code 2}{@code +} {@code y}{@code 2}{@code )} value of the arguments.
since
Android 1.0

public static native doublelog(double d)
Returns the closest double approximation of the natural logarithm of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code log(+0.0) = -infinity}
  • {@code log(-0.0) = -infinity}
  • {@code log((anything < 0) = NaN}
  • {@code log(+infinity) = +infinity}
  • {@code log(-infinity) = NaN}
  • {@code log(NaN) = NaN}

param
d the value whose log has to be computed.
return
the natural logarithm of the argument.
since
Android 1.0

public static native doublelog10(double d)
Returns the closest double approximation of the base 10 logarithm of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code log10(+0.0) = -infinity}
  • {@code log10(-0.0) = -infinity}
  • {@code log10((anything < 0) = NaN}
  • {@code log10(+infinity) = +infinity}
  • {@code log10(-infinity) = NaN}
  • {@code log10(NaN) = NaN}

param
d the value whose base 10 log has to be computed.
return
the natural logarithm of the argument.
since
Android 1.0

public static native doublelog1p(double d)
Returns the closest double approximation of the natural logarithm of the sum of the argument and 1. If the argument is very close to 0, it is much more accurate to use {@code log1p(d)} than {@code log(1.0+d)} (due to numerical cancellation). The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code log1p(+0.0) = +0.0}
  • {@code log1p(-0.0) = -0.0}
  • {@code log1p((anything < 1)) = NaN}
  • {@code log1p(-1.0) = -infinity}
  • {@code log1p(+infinity) = +infinity}
  • {@code log1p(-infinity) = NaN}
  • {@code log1p(NaN) = NaN}

param
d the value to compute the {@code ln(1+d)} of.
return
the natural logarithm of the sum of the argument and 1.
since
Android 1.0

public static doublemax(double d1, double d2)
Returns the most positive (closest to positive infinity) of the two arguments.

Special cases:

  • {@code max(NaN, (anything)) = NaN}
  • {@code max((anything), NaN) = NaN}
  • {@code max(+0.0, -0.0) = +0.0}
  • {@code max(-0.0, +0.0) = +0.0}

param
d1 the first argument.
param
d2 the second argument.
return
the larger of {@code d1} and {@code d2}.
since
Android 1.0

        if (d1 > d2)
            return d1;
        if (d1 < d2)
            return d2;
        /* if either arg is NaN, return NaN */
        if (d1 != d2)
            return Double.NaN;
        /* max( +0.0,-0.0) == +0.0 */
        if (d1 == 0.0
                && ((Double.doubleToLongBits(d1) & Double.doubleToLongBits(d2)) & 0x8000000000000000L) == 0)
            return 0.0;
        return d1;
    
public static floatmax(float f1, float f2)
Returns the most positive (closest to positive infinity) of the two arguments.

Special cases:

  • {@code max(NaN, (anything)) = NaN}
  • {@code max((anything), NaN) = NaN}
  • {@code max(+0.0, -0.0) = +0.0}
  • {@code max(-0.0, +0.0) = +0.0}

param
f1 the first argument.
param
f2 the second argument.
return
the larger of {@code f1} and {@code f2}.
since
Android 1.0

        if (f1 > f2)
            return f1;
        if (f1 < f2)
            return f2;
        /* if either arg is NaN, return NaN */
        if (f1 != f2)
            return Float.NaN;
        /* max( +0.0,-0.0) == +0.0 */
        if (f1 == 0.0f
                && ((Float.floatToIntBits(f1) & Float.floatToIntBits(f2)) & 0x80000000) == 0)
            return 0.0f;
        return f1;
    
public static intmax(int i1, int i2)
Returns the most positive (closest to positive infinity) of the two arguments.

param
i1 the first argument.
param
i2 the second argument.
return
the larger of {@code i1} and {@code i2}.
since
Android 1.0

        return i1 > i2 ? i1 : i2;
    
public static longmax(long l1, long l2)
Returns the most positive (closest to positive infinity) of the two arguments.

param
l1 the first argument.
param
l2 the second argument.
return
the larger of {@code l1} and {@code l2}.
since
Android 1.0

        return l1 > l2 ? l1 : l2;
    
public static doublemin(double d1, double d2)
Returns the most negative (closest to negative infinity) of the two arguments.

Special cases:

  • {@code min(NaN, (anything)) = NaN}
  • {@code min((anything), NaN) = NaN}
  • {@code min(+0.0, -0.0) = -0.0}
  • {@code min(-0.0, +0.0) = -0.0}

param
d1 the first argument.
param
d2 the second argument.
return
the smaller of {@code d1} and {@code d2}.
since
Android 1.0

        if (d1 > d2)
            return d2;
        if (d1 < d2)
            return d1;
        /* if either arg is NaN, return NaN */
        if (d1 != d2)
            return Double.NaN;
        /* min( +0.0,-0.0) == -0.0 */
        if (d1 == 0.0
                && ((Double.doubleToLongBits(d1) | Double.doubleToLongBits(d2)) & 0x8000000000000000l) != 0)
            return 0.0 * (-1.0);
        return d1;
    
public static floatmin(float f1, float f2)
Returns the most negative (closest to negative infinity) of the two arguments.

Special cases:

  • {@code min(NaN, (anything)) = NaN}
  • {@code min((anything), NaN) = NaN}
  • {@code min(+0.0, -0.0) = -0.0}
  • {@code min(-0.0, +0.0) = -0.0}

param
f1 the first argument.
param
f2 the second argument.
return
the smaller of {@code f1} and {@code f2}.
since
Android 1.0

        if (f1 > f2)
            return f2;
        if (f1 < f2)
            return f1;
        /* if either arg is NaN, return NaN */
        if (f1 != f2)
            return Float.NaN;
        /* min( +0.0,-0.0) == -0.0 */
        if (f1 == 0.0f
                && ((Float.floatToIntBits(f1) | Float.floatToIntBits(f2)) & 0x80000000) != 0)
            return 0.0f * (-1.0f);
        return f1;
    
public static intmin(int i1, int i2)
Returns the most negative (closest to negative infinity) of the two arguments.

param
i1 the first argument.
param
i2 the second argument.
return
the smaller of {@code i1} and {@code i2}.
since
Android 1.0

        return i1 < i2 ? i1 : i2;
    
public static longmin(long l1, long l2)
Returns the most negative (closest to negative infinity) of the two arguments.

param
l1 the first argument.
param
l2 the second argument.
return
the smaller of {@code l1} and {@code l2}.
since
Android 1.0

        return l1 < l2 ? l1 : l2;
    
private static native doublenextafter(double x, double y)

private static native floatnextafterf(float x, float y)

public static native doublepow(double x, double y)
Returns the closest double approximation of the result of raising {@code x} to the power of {@code y}.

Special cases:

  • {@code pow((anything), +0.0) = 1.0}
  • {@code pow((anything), -0.0) = 1.0}
  • {@code pow(x, 1.0) = x}
  • {@code pow((anything), NaN) = NaN}
  • {@code pow(NaN, (anything except 0)) = NaN}
  • {@code pow(+/-(|x| > 1), +infinity) = +infinity}
  • {@code pow(+/-(|x| > 1), -infinity) = +0.0}
  • {@code pow(+/-(|x| < 1), +infinity) = +0.0}
  • {@code pow(+/-(|x| < 1), -infinity) = +infinity}
  • {@code pow(+/-1.0 , +infinity) = NaN}
  • {@code pow(+/-1.0 , -infinity) = NaN}
  • {@code pow(+0.0, (+anything except 0, NaN)) = +0.0}
  • {@code pow(-0.0, (+anything except 0, NaN, odd integer)) = +0.0}
  • {@code pow(+0.0, (-anything except 0, NaN)) = +infinity}
  • {@code pow(-0.0, (-anything except 0, NAN, odd integer))} {@code =} {@code +infinity}
  • {@code pow(-0.0, (odd integer)) = -pow( +0 , (odd integer) )}
  • {@code pow(+infinity, (+anything except 0, NaN)) = +infinity}
  • {@code pow(+infinity, (-anything except 0, NaN)) = +0.0}
  • {@code pow(-infinity, (anything)) = -pow(0, (-anything))}
  • {@code pow((-anything), (integer))} {@code =} {@code pow(-1,(integer))*pow(+anything,integer) }
  • {@code pow((-anything except 0 and inf), (non-integer)) = NAN}

param
x the base of the operation.
param
y the exponent of the operation.
return
{@code x} to the power of {@code y}.
since
Android 1.0

public static doublerandom()
Returns a pseudo-random number between 0.0 (inclusive) and 1.0 (exclusive).

return
a pseudo-random number.
since
Android 1.0

        if (random == null) {
            random = new java.util.Random();
        }
        return random.nextDouble();
    
public static native doublerint(double d)
Returns the double conversion of the result of rounding the argument to an integer. Tie breaks are rounded towards even.

Special cases:

  • {@code rint(+0.0) = +0.0}
  • {@code rint(-0.0) = -0.0}
  • {@code rint(+infinity) = +infinity}
  • {@code rint(-infinity) = -infinity}
  • {@code rint(NaN) = NaN}

param
d the value to be rounded.
return
the closest integer to the argument (as a double).
since
Android 1.0

public static longround(double d)
Returns the result of rounding the argument to an integer. The result is equivalent to {@code (long) Math.floor(d+0.5)}.

Special cases:

  • {@code round(+0.0) = +0.0}
  • {@code round(-0.0) = +0.0}
  • {@code round((anything > Long.MAX_VALUE) = Long.MAX_VALUE}
  • {@code round((anything < Long.MIN_VALUE) = Long.MIN_VALUE}
  • {@code round(+infintiy) = Long.MAX_VALUE}
  • {@code round(-infintiy) = Long.MIN_VALUE}
  • {@code round(NaN) = +0.0}

param
d the value to be rounded.
return
the closest integer to the argument.
since
Android 1.0

        // check for NaN
        if (d != d)
            return 0L;
        return (long) floor(d + 0.5d);
    
public static intround(float f)
Returns the result of rounding the argument to an integer. The result is equivalent to {@code (int) Math.floor(f+0.5)}.

Special cases:

  • {@code round(+0.0) = +0.0}
  • {@code round(-0.0) = +0.0}
  • {@code round((anything > Integer.MAX_VALUE) = Integer.MAX_VALUE}
  • {@code round((anything < Integer.MIN_VALUE) = Integer.MIN_VALUE}
  • {@code round(+infintiy) = Integer.MAX_VALUE}
  • {@code round(-infintiy) = Integer.MIN_VALUE}
  • {@code round(NaN) = +0.0}

param
f the value to be rounded.
return
the closest integer to the argument.
since
Android 1.0

        // check for NaN
        if (f != f)
            return 0;
        return (int) floor(f + 0.5f);
    
public static doublesignum(double d)
Returns the signum function of the argument. If the argument is less than zero, it returns -1.0. If the argument is greater than zero, 1.0 is returned. If the argument is either positive or negative zero, the argument is returned as result.

Special cases:

  • {@code signum(+0.0) = +0.0}
  • {@code signum(-0.0) = -0.0}
  • {@code signum(+infinity) = +1.0}
  • {@code signum(-infinity) = -1.0}
  • {@code signum(NaN) = NaN}

param
d the value whose signum has to be computed.
return
the value of the signum function.
since
Android 1.0

        return StrictMath.signum(d);
    
public static floatsignum(float f)
Returns the signum function of the argument. If the argument is less than zero, it returns -1.0. If the argument is greater than zero, 1.0 is returned. If the argument is either positive or negative zero, the argument is returned as result.

Special cases:

  • {@code signum(+0.0) = +0.0}
  • {@code signum(-0.0) = -0.0}
  • {@code signum(+infinity) = +1.0}
  • {@code signum(-infinity) = -1.0}
  • {@code signum(NaN) = NaN}

param
f the value whose signum has to be computed.
return
the value of the signum function.
since
Android 1.0

        return StrictMath.signum(f);
    
public static native doublesin(double d)
Returns the closest double approximation of the sine of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code sin(+0.0) = +0.0}
  • {@code sin(-0.0) = -0.0}
  • {@code sin(+infinity) = NaN}
  • {@code sin(-infinity) = NaN}
  • {@code sin(NaN) = NaN}

param
d the angle whose sin has to be computed, in radians.
return
the sine of the argument.
since
Android 1.0

public static native doublesinh(double d)
Returns the closest double approximation of the hyperbolic sine of the argument. The returned result is within 2.5 ulps (units in the last place) of the real result.

Special cases:

  • {@code sinh(+0.0) = +0.0}
  • {@code sinh(-0.0) = -0.0}
  • {@code sinh(+infinity) = +infinity}
  • {@code sinh(-infinity) = -infinity}
  • {@code sinh(NaN) = NaN}

param
d the value whose hyperbolic sine has to be computed.
return
the hyperbolic sine of the argument.
since
Android 1.0

public static native doublesqrt(double d)
Returns the closest double approximation of the square root of the argument.

Special cases:

  • {@code sqrt(+0.0) = +0.0}
  • {@code sqrt(-0.0) = -0.0}
  • {@code sqrt( (anything < 0) ) = NaN}
  • {@code sqrt(+infinity) = +infinity}
  • {@code sqrt(NaN) = NaN}

param
d the value whose square root has to be computed.
return
the square root of the argument.
since
Android 1.0

public static native doubletan(double d)
Returns the closest double approximation of the tangent of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • {@code tan(+0.0) = +0.0}
  • {@code tan(-0.0) = -0.0}
  • {@code tan(+infinity) = NaN}
  • {@code tan(-infinity) = NaN}
  • {@code tan(NaN) = NaN}

param
d the angle whose tangens has to be computed, in radians.
return
the tangent of the argument.
since
Android 1.0

public static native doubletanh(double d)
Returns the closest double approximation of the hyperbolic tangent of the argument. The absolute value is always less than 1. The returned result is within 2.5 ulps (units in the last place) of the real result. If the real result is within 0.5ulp of 1 or -1, it should return exactly +1 or -1.

Special cases:

  • {@code tanh(+0.0) = +0.0}
  • {@code tanh(-0.0) = -0.0}
  • {@code tanh(+infinity) = +1.0}
  • {@code tanh(-infinity) = -1.0}
  • {@code tanh(NaN) = NaN}

param
d the value whose hyperbolic tangent has to be computed.
return
the hyperbolic tangent of the argument.
since
Android 1.0

public static doubletoDegrees(double angrad)
Returns the measure in degrees of the supplied radian angle. The result is {@code angrad * 180 / pi}.

Special cases:

  • {@code toDegrees(+0.0) = +0.0}
  • {@code toDegrees(-0.0) = -0.0}
  • {@code toDegrees(+infinity) = +infinity}
  • {@code toDegrees(-infinity) = -infinity}
  • {@code toDegrees(NaN) = NaN}

param
angrad an angle in radians.
return
the degree measure of the angle.
since
Android 1.0

        return angrad * 180d / PI;
    
public static doubletoRadians(double angdeg)
Returns the measure in radians of the supplied degree angle. The result is {@code angdeg / 180 * pi}.

Special cases:

  • {@code toRadians(+0.0) = +0.0}
  • {@code toRadians(-0.0) = -0.0}
  • {@code toRadians(+infinity) = +infinity}
  • {@code toRadians(-infinity) = -infinity}
  • {@code toRadians(NaN) = NaN}

param
angdeg an angle in degrees.
return
the radian measure of the angle.
since
Android 1.0

        return angdeg / 180d * PI;
    
public static doubleulp(double d)
Returns the argument's ulp (unit in the last place). The size of a ulp of a double value is the positive distance between this value and the double value next larger in magnitude. For non-NaN {@code x}, {@code ulp(-x) == ulp(x)}.

Special cases:

  • {@code ulp(+0.0) = Double.MIN_VALUE}
  • {@code ulp(-0.0) = Double.MIN_VALUE}
  • {@code ulp(+infintiy) = infinity}
  • {@code ulp(-infintiy) = infinity}
  • {@code ulp(NaN) = NaN}

param
d the floating-point value to compute ulp of.
return
the size of a ulp of the argument.
since
Android 1.0

        // special cases
        if (Double.isInfinite(d)) {
            return Double.POSITIVE_INFINITY;
        } else if (d == Double.MAX_VALUE || d == -Double.MAX_VALUE) {
            return pow(2, 971);
        }
        d = abs(d);
        return nextafter(d, Double.MAX_VALUE) - d;
    
public static floatulp(float f)
Returns the argument's ulp (unit in the last place). The size of a ulp of a float value is the positive distance between this value and the float value next larger in magnitude. For non-NaN {@code x}, {@code ulp(-x) == ulp(x)}.

Special cases:

  • {@code ulp(+0.0) = Float.MIN_VALUE}
  • {@code ulp(-0.0) = Float.MIN_VALUE}
  • {@code ulp(+infintiy) = infinity}
  • {@code ulp(-infintiy) = infinity}
  • {@code ulp(NaN) = NaN}

param
f the floating-point value to compute ulp of.
return
the size of a ulp of the argument.
since
Android 1.0

        // special cases
        if (Float.isNaN(f)) {
            return Float.NaN;
        } else if (Float.isInfinite(f)) {
            return Float.POSITIVE_INFINITY;
        } else if (f == Float.MAX_VALUE || f == -Float.MAX_VALUE) {
            return (float) pow(2, 104);
        }
        f = abs(f);
        return nextafterf(f, Float.MAX_VALUE) - f;