Class ccj.Numeric
All Packages Class Hierarchy This Package Previous Next Index
Class ccj.Numeric
java.lang.Object
|
+----ccj.Numeric
- public class Numeric
- extends Object
-
Numeric()
-
-
compareDoubles(double, double)
- Compares two floating point numbers to see if they are approximately the same
-
parseDouble(String)
- Converts a string to a floating point number.
-
randomDouble(double, double)
- Generates a random floating point number in a range.
-
randomInt(int, int)
- Generates a random integer in a range.
-
round(double)
- Rounds a floating point number to the nearest integer
Numeric
public Numeric()
parseDouble
public static double parseDouble(String s)
- Converts a string to a floating point number. For example, Numeric.parseDouble("0.5") returns 0.5
- Parameters:
- s - the string to parse
- Returns:
- the floating point value represented by the string.
compareDoubles
public static int compareDoubles(double x,
double y)
- Compares two floating point numbers to see if they are approximately the same
- Parameters:
- x - a floating point number
- y - another floating point number
- Returns:
- 0 if x and y are approximately identical, -1 if x < y and 1 if x > y
round
public static int round(double x)
- Rounds a floating point number to the nearest integer
- Parameters:
- x - a floating point number
- Returns:
- the nearest integer
randomInt
public static int randomInt(int a,
int b)
- Generates a random integer in a range. For example, Numeric.randomInt(1, 6) generates a random roll of a die
- Parameters:
- a - the low bound of the range
- b - the high bound of the range
- Returns:
- a random integer r, a <= r && r <= b
randomDouble
public static double randomDouble(double a,
double b)
- Generates a random floating point number in a range.
- Parameters:
- a - the low bound of the range (inclusive)
- b - the high bound of the range (exclusive)
- Returns:
- a random floating point number r, a <= r && r < b
All Packages Class Hierarchy This Package Previous Next Index