|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jcontrol.lang.Math
public class Math
Provides some simple math functions.
JControl devices are limited in computation rate and precision, so some useful mathematical functions are approximated with tables.
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. |
Method Summary | |
---|---|
static double |
abs(double a)
Returns the absolute value of a double value. |
static float |
abs(float a)
Returns the absolute value of a float 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 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 float |
ceil(float a)
|
static int |
cos(int op)
Look-up table cosine function. |
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 float |
floor(float a)
|
static double |
max(double a,
double b)
Returns the greater of two double values. |
static float |
max(float a,
float b)
Returns the greater of two float 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 double |
min(double a,
double b)
Returns the smaller of two double values. |
static float |
min(float a,
float b)
Returns the smaller of two float 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 double |
pow(double a,
double b)
Returns the value of the first argument raised to the power of the second argument. |
static int |
pow(int op,
int exp)
op raised to the power of exp |
static int |
rnd(int mod)
Returns a pseudo random number. |
static long |
round(double a)
Returns the closest long to the argument. |
static int |
round(float a)
Returns the closest int to the argument. |
static int |
scale(int value,
int source,
int dest)
Rule of proportion. |
static int |
sin(int op)
Look-up table sine function. |
static double |
sqrt(double a)
Returns the correctly rounded positive square root of a double value. |
static int |
sqrt(int op)
Look-up table square root. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, notifyAll, toString, wait |
Field Detail |
---|
public static final double E
double
value that is closer than any other to
e, the base of the natural logarithms.
public static final double PI
double
value that is closer than any other to
pi, the ratio of the circumference of a circle to its
diameter.
Method Detail |
---|
public static int rnd(int mod)
mod
- the range for the random number (1...mod
-1), 0 for full 15 bit range
public static int sin(int op)
op
- function argument in degrees (range 0 ... 360)
public static int cos(int op)
op
- function argument in degrees (range 0 ... 360)
public static int pow(int op, int exp)
public static int scale(int value, int source, int dest)
y=scale(x,a,b)
is equal to y=x*b/a
.
value
- the value to scale (range -32768 ... 32767)source
- the divisor (range -32768 ... 32767)dest
- the multiplicant (range -32768 ... 32767)
public static int sqrt(int op)
op
- value to extract the root from (range: 0 ... 32767)
public static int max(int a, int b)
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.
a
- an int
value.b
- an int
value.
a
and b
.Long.MAX_VALUE
public static int min(int a, int b)
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.
a
- an int
value.b
- an int
value.
a
and b
.Long.MIN_VALUE
public static int abs(int a)
int
value.
If the argument is not negative, the argument is returned.
If the argument is negative, the negation of the argument is returned.
Note that if the argument is equal to the value of
Integer.MIN_VALUE
, the most negative representable
int
value, the result is that same value, which is
negative.
a
- - the argument whose absolute value is to be determined
Integer.MIN_VALUE
public static double sqrt(double a)
double
value.
Special cases:
double
value closest to
the true mathematical square root of the argument value.
a
- a value.
a
.
If the argument is NaN or less than zero, the result is NaN.public static double ceil(double a)
double
value that is not less than the argument and is
equal to a mathematical integer. Special cases:
Math.ceil(x)
is exactly the
value of -Math.floor(-x)
.
a
- a value.
public static float ceil(float a)
a
-
ceil(double)
public static double floor(double a)
double
value that is not greater than the argument and
is equal to a mathematical integer. Special cases:
a
- a value.
public static float floor(float a)
a
-
floor(double)
public static double pow(double a, double b)
double
value.(In the foregoing descriptions, a floating-point value is
considered to be an integer if and only if it is finite and a
fixed point of the method ceil
or,
equivalently, a fixed point of the method floor
. A value is a fixed point of a one-argument
method if and only if the result of applying the method to the
value is equal to the value.)
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
a
- the base.b
- the exponent.
ab
.public static int round(float a)
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
.
In other words, the result is equal to the value of the expression:
(int)Math.floor(a + 0.5f)
Special cases:
Integer.MIN_VALUE
, the result is
equal to the value of Integer.MIN_VALUE
.
Integer.MAX_VALUE
, the result is
equal to the value of Integer.MAX_VALUE
.
a
- a floating-point value to be rounded to an integer.
int
value.Integer.MAX_VALUE
,
Integer.MIN_VALUE
public static long round(double a)
long
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 long
. In other
words, the result is equal to the value of the expression:
(long)Math.floor(a + 0.5d)
Special cases:
Long.MIN_VALUE
, the result is
equal to the value of Long.MIN_VALUE
.
Long.MAX_VALUE
, the result is
equal to the value of Long.MAX_VALUE
.
a
- a floating-point value to be rounded to a
long
.
long
value.Long.MAX_VALUE
,
Long.MIN_VALUE
public static long abs(long 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.
Note that if the argument is equal to the value of
Long.MIN_VALUE
, the most negative representable
long
value, the result is that same value, which is
negative.
a
- the argument whose absolute value is to be determined
Long.MIN_VALUE
public static float abs(float a)
float
value.
If the argument is not negative, the argument is returned.
If the argument is negative, the negation of the argument is returned.
Special cases:
Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))
a
- the argument whose absolute value is to be determined
public static double abs(double a)
double
value.
If the argument is not negative, the argument is returned.
If the argument is negative, the negation of the argument is returned.
Special cases:
Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)
a
- the argument whose absolute value is to be determined
public static long max(long a, long b)
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.
a
- an argument.b
- another argument.
a
and b
.Long.MAX_VALUE
public static float max(float a, float b)
float
values. That is,
the result is the argument closer to positive infinity. If the
arguments have the same value, the result is that same
value. If either value is NaN, then the result is NaN. Unlike
the the numerical comparison operators, this method considers
negative zero to be strictly smaller than positive zero. If one
argument is positive zero and the other negative zero, the
result is positive zero.
a
- an argument.b
- another argument.
a
and b
.public static double max(double a, double b)
double
values. That
is, the result is the argument closer to positive infinity. If
the arguments have the same value, the result is that same
value. If either value is NaN, then the result is NaN. Unlike
the the numerical comparison operators, this method considers
negative zero to be strictly smaller than positive zero. If one
argument is positive zero and the other negative zero, the
result is positive zero.
a
- an argument.b
- another argument.
a
and b
.public static long min(long a, long b)
long
values. That is,
the result is the argument closer to the value of
Long.MIN_VALUE
. If the arguments have the same
value, the result is that same value.
a
- an argument.b
- another argument.
a
and b
.Long.MIN_VALUE
public static float min(float a, float b)
float
values. That is,
the result is the value closer to negative infinity. If the
arguments have the same value, the result is that same
value. If either value is NaN, then the result is NaN. Unlike
the the numerical comparison operators, this method considers
negative zero to be strictly smaller than positive zero. If
one argument is positive zero and the other is negative zero,
the result is negative zero.
a
- an argument.b
- another argument.
a
and b.
public static double min(double a, double b)
double
values. That
is, the result is the value closer to negative infinity. If the
arguments have the same value, the result is that same
value. If either value is NaN, then the result is NaN. Unlike
the the numerical comparison operators, this method considers
negative zero to be strictly smaller than positive zero. If one
argument is positive zero and the other is negative zero, the
result is negative zero.
a
- an argument.b
- another argument.
a
and b
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |