public final class Math4D
extends java.lang.Object
The Math class used in the device is not the same one used at Java SE. Be sure to refer to this documentation to see what you can use.
Note that angles are specified in radians. Conversion functions are
provided for your convenience.
IMPORTANT: the totalcross.lang package is the java.lang that will be used in the device.
You CANNOT use nor import totalcross.lang package in desktop. When tc.Deploy is called,
all references to java.lang are replaced by totalcross.lang automatically. Given this,
you must use only the classes and methods that exists BOTH in java.lang and totalcross.lang.
For example, you can't use java.lang.ClassLoader because there are no totalcross.lang.ClassLoader.
Another example, you can't use java.lang.String.indexOfIgnoreCase because there are no
totalcross.lang.String.indexOfIgnoreCase method. Trying to use a class or method from the java.lang package
that has no correspondence with totalcross.lang will make the tc.Deploy program to abort, informing
where the problem occured. A good idea is to always refer to this javadoc to know what is and what isn't
available.
Modifier and Type | Field and Description |
---|---|
static double |
E
The mathematical constant e.
|
static double |
NaN |
static double |
NEGATIVE_INFINITY |
static double |
PI
The mathematical constant pi.
|
static double |
POSITIVE_INFINITY |
Constructor and Description |
---|
Math4D() |
Modifier and Type | Method and Description |
---|---|
static double |
abs(double a)
Take the absolute value of the argument.
|
static int |
abs(int a)
Take the absolute value of the argument.
|
static long |
abs(long a)
Take the absolute value of the argument.
|
static double |
acos(double x)
The trigonometric function arccos.
|
static double |
asin(double x)
The trigonometric function arcsin.
|
static double |
atan(double x)
The trigonometric function arctan.
|
static double |
atan2(double y,
double x)
A special version of the trigonometric function arctan.
|
static double |
ceil(double x)
Take the nearest integer that is that is greater than or equal to the
argument.
|
static double |
cos(double x)
The trigonometric function cos.
|
static double |
exp(double x)
Take ex.
|
static double |
floor(double x)
Take the nearest integer that is that is less than or equal to the
argument.
|
static double |
IEEEremainder(double x,
double y)
Get the floating point remainder on two numbers,
which really does the following:
|
static boolean |
isNaN(double d) |
static double |
log(double x)
Take ln(x) (the natural log).
|
static double |
max(double a,
double b)
Return whichever argument is larger.
|
static int |
max(int a,
int b)
Return whichever argument is larger.
|
static long |
max(long a,
long b)
Return whichever argument is larger.
|
static double |
min(double a,
double b)
Return whichever argument is smaller.
|
static int |
min(int a,
int b)
Return whichever argument is smaller.
|
static long |
min(long a,
long b)
Return whichever argument is smaller.
|
static double |
pow(double x,
double y)
Take a number to a power.
|
static double |
rint(double x)
Take the nearest integer to the argument.
|
static long |
round(double a)
Take the nearest integer to the argument.
|
static double |
sin(double x)
The trigonometric function sin.
|
static double |
sqrt(double x)
Take a square root.
|
static double |
tan(double x)
The trigonometric function tan.
|
static double |
toDegrees(double rads)
Convert from radians to degrees.
|
static double |
toRadians(double degrees)
Convert from degrees to radians.
|
public static final double NaN
public static final double POSITIVE_INFINITY
public static final double NEGATIVE_INFINITY
public static final double E
log(double)
,
exp(double)
,
Constant Field Valuespublic static final double PI
public static int abs(int a)
Note that the largest negative value (Integer.MIN_VALUE) cannot be made positive. In this case, because of the rules of negation in a computer, MIN_VALUE is what will be returned. This is a negative value. You have been warned.
a
- the number to take the absolute value of.public static long abs(long a)
Note that the largest negative value (Long.MIN_VALUE) cannot be made positive. In this case, because of the rules of negation in a computer, MIN_VALUE is what will be returned. This is a negative value. You have been warned.
a
- the number to take the absolute value of.public static double abs(double a)
a
- the number to take the absolute value of.public static int min(int a, int b)
a
- the first numberb
- a second numberpublic static long min(long a, long b)
a
- the first numberb
- a second numberpublic static double min(double a, double b)
a
- the first numberb
- a second numberpublic static int max(int a, int b)
a
- the first numberb
- a second numberpublic static long max(long a, long b)
a
- the first numberb
- a second numberpublic static double max(double a, double b)
a
- the first numberb
- a second numberpublic static double sin(double x)
x
- the angle (in radians).public static double cos(double x)
x
- the angle (in radians).public static double tan(double x)
x
- the angle (in radians).public static double asin(double x)
x
- the sin to turn back into an angle.public static double acos(double x)
x
- the cos to turn back into an angle.public static double atan(double x)
x
- the tan to turn back into an angle.atan2(double,double)
public static double atan2(double y, double x)
atan()
.y
- the y positionx
- the x positionatan(double)
public static double exp(double x)
log()
.x
- the number to raise to the power.log(double)
,
pow(double,double)
public static double log(double x)
exp()
.
Note that the way to get logb(a) is to do this:
ln(a) / ln(b)
.x
- the number to take the natural log of.x
.exp(double)
public static double sqrt(double x)
x
- the numeric argumentpow(double,double)
public static double pow(double x, double y)
x
- the number to raise.y
- the power to raise it to.public static double IEEEremainder(double x, double y)
rint()
function to do this.
x
- the dividend (the top half)y
- the divisor (the bottom half)rint(double)
public static double ceil(double x)
x
- the value to act upon.x
.public static double floor(double x)
x
- the value to act upon.x
.public static double rint(double x)
x
- the value to act upon.x
.public static long round(double a)
a
- the argument to round.public static double toRadians(double degrees)
degrees
- an angle in degreespublic static double toDegrees(double rads)
rads
- an angle in radianspublic static boolean isNaN(double d)