THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
asin(v) arcsine(v), with v in the range [1.0, 1.0]

acos(v) arccosine(v), with v in the range [1.0, 1.0]

atan(v) arctangent(v), returned in the range [π/2,π/2]

atan2(x,y) arctangent(x/y), returned in the range [π,π]

toRadians(d) Given d in degrees, returns equivalent angle in radians

toDegrees(r) given r in radians, returns equivalent angle in degrees

exp(x) e x

sinh(x) hyperbolic sine of x

cosh(x) hyperbolic cosine of x

tanh(x) hyperbolic tangent of x

pow(y,x) y x

log(x) ln x (natural log of x)

log10(x) base 10 logarithm of x

sqrt(x) Square root of x

cbrt(x) Cubic root of x

signum(x) signum function: 1 if x is positive; 1 if x is negative; 0 if x is zero. There are double
and float versions

ceil(x) Smallest whole number x

floor(x) Largest whole number x

rint(x) x rounded to the nearest integer; if neither integer is nearer, rounds to the even integer

round(x) (int) floor(x + 0.5) for float x (long) floor(x + 0.5) for
double x

abs(x) | x | for any numeric type. (the absolute value of the most negative value of an int or
long is itself and therefore negative; that's how two's complement integers work)

max(x,y) Larger of x and y for any numeric type

min(x,y) Smaller of x and y for any numeric type

hypot(x,y) Calculates the length of the hypotenuse of a right-angled triangle with sides of length x
and y; that is, it calculates with no intermediate overflow or underflow

The static method IEEEremainder calculates remainder as defined by the IEEE 754 standard. The
remainder operator %, as described in "Floating-Point Arithmetic" on page 202, obeys the rule


(x/y)*y + x%y == x


This preserves one kind of symmetry: Symmetry around zero. That is, if x%y is z, then changing the sign of
either x or y will change only the sign of z, never its absolute value. For example, 7%2.5 is 2.0, and

Free download pdf