moka.lang
Class Math

java.lang.Object
  |
  +--moka.lang.Object
        |
        +--moka.lang.Math

public final class Math
extends Object

The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.

Since:
MDK1.01a

Field Summary
static double E
          The double value that is closer than any other to e, the base of the natural logarithms.
static double PI
          The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
 
Constructor Summary
Math()
           
 
Method Summary
static byte abs(byte a)
          Returns the absolute value of a byte value.
static double abs(double a)
          Returns the absolute value of an int value.
static int abs(int a)
          Returns the absolute value of an int value.
static long abs(long a)
          Returns the absolute value of a long value.
static short abs(short a)
          Returns the absolute value of a short value.
static double acos(double a)
          Returns the arc cosine of an angle.
static double asin(double a)
          Returns the arc sine of an angle.
static double atan(double a)
          Returns the arc tangent of an angle.
static double atan2(double y, double x)
          Converts rectangular coordinates (xy) to polar (r, theta).
static double ceil(double a)
          Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.
static double cos(double a)
          Returns the trigonometric cosine of an angle.
static double exp(double a)
          Returns Euler's number e raised to the power of a double value.
static double floor(double a)
          Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
static double log(double a)
          Returns the natural logarithm (base e) of a double value.
static byte max(byte a, byte b)
          Returns the greater of two byte values.
static double max(double a, double b)
          Returns the greater of two double values.
static int max(int a, int b)
          Returns the greater of two int values.
static long max(long a, long b)
          Returns the greater of two long values.
static short max(short a, short b)
          Returns the greater of two short values.
static byte min(byte a, byte b)
          Returns the smaller of two byte values.
static double min(double a, double b)
          Returns the smaller of two double values.
static int min(int a, int b)
          Returns the smaller of two int values.
static long min(long a, long b)
          Returns the smaller of two long values.
static short min(short a, short b)
          Returns the smaller of two short values.
static double pow(double a, double b)
          Returns of value of the first argument raised to the power of the second argument.
static short rand()
          Returns a short value with a positive sign, greater than or equal to 0 and less than 32767.
static short rand(short num)
          Returns a short value with a positive sign, greater than or equal to 0 and less than the specified number.
static double random()
          Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
static void randomize()
          Initializes the random number generator with a random value (picked from the timer).
static int round(double a)
          Returns the closest int to the argument.
static double sin(double a)
          Returns the trigonometric sine of an angle.
static double sqrt(double a)
          Returns the correctly rounded positive square root of a double value.
static double tan(double a)
          Returns the trigonometric tangent of an angle.
static double toDegrees(double angrad)
          Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
static double toRadians(double angdeg)
          Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
 
Methods inherited from class moka.lang.Object
equals, finalize, getClassName, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

E

public static final double E
The double value that is closer than any other to e, the base of the natural logarithms.

See Also:
Constant Field Values

PI

public static final double PI
The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Constructor Detail

Math

public Math()
Method Detail

abs

public static byte abs(byte a)
Returns the absolute value of a byte value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Parameters:
a - the argument whose absolute value is to be determined
Returns:
the absolute value of the argument.

abs

public static short abs(short a)
Returns the absolute value of a short value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Parameters:
a - the argument whose absolute value is to be determined
Returns:
the absolute value of the argument.

abs

public static int abs(int a)
Returns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Parameters:
a - the argument whose absolute value is to be determined
Returns:
the absolute value of the argument.

abs

public static long abs(long a)
Returns the absolute value of a long value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Parameters:
a - the argument whose absolute value is to be determined
Returns:
the absolute value of the argument.

abs

public static double abs(double a)
Returns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Parameters:
a - the argument whose absolute value is to be determined
Returns:
the absolute value of the argument.

acos

public static double acos(double a)
Returns the arc cosine of an angle.

Parameters:
a - the value whose arc cosine is to be returned.
Returns:
the arc cosine of the argument.

asin

public static double asin(double a)
Returns the arc sine of an angle.

Parameters:
a - the value whose arc sine is to be returned.
Returns:
the arc sine of the argument.

atan

public static double atan(double a)
Returns the arc tangent of an angle.

Parameters:
a - the value whose arc tangent is to be returned.
Returns:
the arc tangent of the argument.

atan2

public static double atan2(double y,
                           double x)
Converts rectangular coordinates (xy) to polar (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.

Parameters:
y - the ordinate coordinate
x - the abscissa coordinate
Returns:
the theta component of the point (rtheta) in polar coordinates that corresponds to the point (xy) in Cartesian coordinates.

ceil

public static double ceil(double a)
Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.

Parameters:
a - a value.
Returns:
the smallest (closest to negative infinity) floating-point value that is not less than the argument and is equal to a mathematical integer.

cos

public static double cos(double a)
Returns the trigonometric cosine of an angle.

Parameters:
a - an angle, in radians.
Returns:
the cosine of the argument.

exp

public static double exp(double a)
Returns Euler's number e raised to the power of a double value.

Parameters:
a - the exponent to raise e to.
Returns:
the value ea, where e is the base of the natural logarithms.

floor

public static double floor(double a)
Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.

Parameters:
a - a value
Returns:
the largest (closest to positive infinity) floating-point value that is not greater than the argument and is equal to a mathematical integer.

log

public static double log(double a)
Returns the natural logarithm (base e) of a double value.

Parameters:
a - a number greater than 0.0.
Returns:
the value ln a, the natural logarithm of a.

max

public static byte max(byte a,
                       byte b)
Returns the greater of two byte values. That is, the result is the argument closer to the value of Byte.MAX_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the larger of a and b.

max

public static short max(short a,
                        short b)
Returns the greater of two short values. That is, the result is the argument closer to the value of Short.MAX_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the larger of a and b.

max

public static int max(int a,
                      int b)
Returns the greater of two int values. That is, the result is the argument closer to the value of Integer.MAX_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the larger of a and b.

max

public static long max(long a,
                       long b)
Returns the greater of two long values. That is, the result is the argument closer to the value of Long.MAX_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the larger of a and b.

max

public static double max(double a,
                         double b)
Returns the greater of two double values. That is, the result is the argument closer to the value of Double.MAX_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the larger of a and b.

min

public static byte min(byte a,
                       byte b)
Returns the smaller of two byte values. That is, the result the argument closer to the value of Byte.MIN_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the smaller of a and b.

min

public static short min(short a,
                        short b)
Returns the smaller of two short values. That is, the result the argument closer to the value of Short.MIN_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the smaller of a and b.

min

public static int min(int a,
                      int b)
Returns the smaller of two int values. That is, the result the argument closer to the value of Integer.MIN_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the smaller of a and b.

min

public static long min(long a,
                       long b)
Returns the smaller of two long values. That is, the result the argument closer to the value of Long.MIN_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the smaller of a and b.

min

public static double min(double a,
                         double b)
Returns the smaller of two double values. That is, the result the argument closer to the value of Double.MIN_VALUE. If the arguments have the same value, the result is that same value.

Parameters:
a - an argument.
b - another argument.
Returns:
the smaller of a and b.

pow

public static double pow(double a,
                         double b)
Returns of value of the first argument raised to the power of the second argument.

Parameters:
a - the base.
b - the exponent.
Returns:
the value ab.

randomize

public static void randomize()
Initializes the random number generator with a random value (picked from the timer).


random

public static double random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.

Returns:
a pseudorandom double greater than or equal to 0.0 and less than 1.0.

rand

public static short rand()
Returns a short value with a positive sign, greater than or equal to 0 and less than 32767. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.

Returns:
a pseudorandom short greater than or equal to 0 and less than 32767.

rand

public static short rand(short num)
Returns a short value with a positive sign, greater than or equal to 0 and less than the specified number. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.

Parameters:
num - the number to be specified
Returns:
a pseudorandom short greater than or equal to 0 and less than the specified number.

round

public static int round(double a)
Returns the closest int to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int.

Parameters:
a - a floating-point value to be rounded to a int.
Returns:
the value of the argument rounded to the nearest int value.

sin

public static double sin(double a)
Returns the trigonometric sine of an angle.

Parameters:
a - an angle, in radians.
Returns:
the sine of the argument.

sqrt

public static double sqrt(double a)
Returns the correctly rounded positive square root of a double value.

Parameters:
a - a value.
Returns:
the positive square root of a.

tan

public static double tan(double a)
Returns the trigonometric tangent of an angle.

Parameters:
a - an angle, in radians.
Returns:
the tangent of the argument.

toRadians

public static double toRadians(double angdeg)
Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.

Parameters:
angdeg - an angle, in degrees
Returns:
the measurement of the angle angdeg in radians.

toDegrees

public static double toDegrees(double angrad)
Converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.

Parameters:
angrad - an angle, in radians
Returns:
the measurement of the angle angrad in degrees.