|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ap.java.lang.Math
The Math
class contains static methods for performing
basic numeric operations like square root, exponentiation,
logarithm, and so on. Four methods are specified as part of the
AP Java subset, other useful methods include those given below, see
the Java API for complete details.
Math.PI
and Math.E
are
useful when programs need these constants.
Standard trigonometric functions include the following, all arguments are specified in radians. Inverse trigonometric functions are available too as are functions to convert between degrees and radians.
double Math.sin(double angle)
double Math.cos(double angle)
double Math.tan(double angle)
double Math.asin(double a)
double Math.acos(double a)
double Math.atan(double a)
double Math.toDegrees(double rad)
double Math.toRadians(double deg)
Functions to truncate and round are also available, typically
the floor
and ceil
return results
are cast to int
or long
values.
long Math.round(double d)
double Math.ceil(double d)
double Math.floor(double d)
Constructor Summary | |
Math()
|
Method Summary | |
static double |
abs(double x)
Returns the absolute value of a double value. |
static int |
abs(int x)
Returns the absolute value of an int value. |
static double |
pow(double base,
double exponent)
Returns the value of baseexponent . |
static double |
sqrt(double x)
Returns the square root of a number. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Math()
Method Detail |
public static int abs(int x)
int
value.
Except for Integer.MIN_VALUE
, this function behaves
as it does in mathematics, i.e., for non-negative arguments
the same value is returned, and for negative arguments
the negation of the argument is returned.
For Integer.MIN_VALUE
the same value is returned.
The behavior for Integer.MIN_VALUE
will
not be tested since this isn't in the AP Java subset.
x
- is the value whose absolute value is returned
public static double abs(double x)
double
value.
Basically, for a non-negative argument, the argument is returned
while for a negative argument the negation is returned.
Special cases occur when the argument is
Double.NaN
(for which the same value returned) and
Double.NEGATIVE_INFINITY
(for which Double.POSITIVE_INFINITY
is returned);
these are not in the AP Java subset so
the exceptional behavior will not be tested.
x
- is the value whose absolute value is returned
public static double pow(double base, double exponent)
baseexponent
.
base
- is the base of the resultexponent
- is the power to which base
is
raised
baseexponent
.public static double sqrt(double x)
double
value closest to the
true mathematical square root is returned. Otherwise,
Double.NaN
is returned, but this behavior
is not part of the AP Java subset.
x
- is the argument whose square root is returned
|
unofficial documentation for the APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |