APCS Java Subset

ap.java.lang Class Math

java.lang.Object ap.java.lang.Math

public class Math
extends java.lang.Object

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.

Static fields 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)

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

Math

public Math()
 Method Detail

abs

public static int abs(int x)
Returns the absolute value of an 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.

Parameters:
x - is the value whose absolute value is returned
Returns:
the absolute value of the argument

abs

public static double abs(double x)
Returns the absolute value of a 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.

Parameters:
x - is the value whose absolute value is returned
Returns:
the absolute value of the argument

pow

public static double pow(double base,
double exponent)
Returns the value of baseexponent.

Parameters:
base - is the base of the result
exponent - is the power to which base is raised
Returns:
the value baseexponent.

sqrt

public static double sqrt(double x)
Returns the square root of a number. If the number is non-negative a 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.

Parameters:
x - is the argument whose square root is returned
Returns:
the square root of the argument

unofficial documentation for the APCS Java Subset