MathSupportpublic final class MathSupport extends Object This class is used to provide URL resolution. |
Fields Summary |
---|
public static final float | PIThe double value that is closer than any other to
pi, the ratio of the circumference of a circle to its
diameter. |
Methods Summary |
---|
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.
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.
return (a < 0) ? -a : a;
| public static float | abs(float a)Returns the absolute value of 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:
- If the argument is positive zero or negative zero, the
result is positive zero.
- If the argument is infinite, the result is positive infinity.
- If the argument is NaN, the result is NaN.
In other words, the result is the same as the value of the expression:
Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))
return (a <= 0.0F) ? 0.0F - a : a;
| public static float | atan(float a)Returns the arc tangent of an angle, in the range of -pi/2
through pi/2. Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is zero, then the result is a zero with the
same sign as the argument.
A result must be within 1 ulp of the correctly rounded result. Results
must be semi-monotonic.
//atan(x) = x/(1+ 0.28*x^2) (|x|<=1)
//atan(x) = pi/2 - x/(x^2 + 0.28) (|x| >=1)
if (MathSupport.abs(a) <= 1.0f) {
return (a /(1 + 0.28f*(a*a)));
} else {
float retval = (((float)Math.PI)/2.0f) - (a/((a*a) + 0.28f));
if (a < (-1.0f)){
return (retval - (float)Math.PI);
} else {
//if a > 1.0f
return retval;
}
}
| public static float | atan2(float y, float x)Converts rectangular coordinates (x , y )
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. Special
cases:
- If either argument is NaN, then the result is NaN.
- If the first argument is positive zero and the second argument
is positive, or the first argument is positive and finite and the
second argument is positive infinity, then the result is positive
zero.
- If the first argument is negative zero and the second argument
is positive, or the first argument is negative and finite and the
second argument is positive infinity, then the result is negative zero.
- If the first argument is positive zero and the second argument
is negative, or the first argument is positive and finite and the
second argument is negative infinity, then the result is the
float value closest to pi.
- If the first argument is negative zero and the second argument
is negative, or the first argument is negative and finite and the
second argument is negative infinity, then the result is the
float value closest to -pi.
- If the first argument is positive and the second argument is
positive zero or negative zero, or the first argument is positive
infinity and the second argument is finite, then the result is the
float value closest to pi/2.
- If the first argument is negative and the second argument is
positive zero or negative zero, or the first argument is negative
infinity and the second argument is finite, then the result is the
float value closest to -pi/2.
- If both arguments are positive infinity, then the result is the
float value closest to pi/4.
- If the first argument is positive infinity and the second argument
is negative infinity, then the result is the
float
value closest to 3*pi/4.
- If the first argument is negative infinity and the second argument
is positive infinity, then the result is the
float value
closest to -pi/4.
- If both arguments are negative infinity, then the result is the
float value closest to -3*pi/4.
A result must be within 2 ulps of the correctly rounded result. Results
must be semi-monotonic.
// if x=y=0
if((y == 0.0f) && (x == 0.0f)) {
return 0.0f;
}
// if x>0 atan(y/x)
if(x > 0.0f) {
return atan(y/x);
}
// if x<0 sign(y)*(pi - atan(|y/x|))
if(x < 0.0f) {
if(y < 0.0f) {
return (float)(-(Math.PI - MathSupport.atan(y/x)));
} else {
return (float)(Math.PI - MathSupport.atan(-y/x));
}
}
// if x=0 y!=0 sign(y)*pi/2
if(y<0.0f) {
return (float)(-(Math.PI/2.0f));
} else {
return (float)(Math.PI/2.0f);
}
| public static float | cos(float a)Returns the trigonometric cosine of an angle. Special cases:
- If the argument is NaN or an infinity, then the
result is NaN.
A result must be within 1 ulp of the correctly rounded result. Results
must be semi-monotonic.
return (float) Math.cos(a);
| public static int | round(float 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 .
In other words, the result is equal to the value of the expression:
(int)Math.floor(a + 0.5f)
Special cases:
- If the argument is NaN, the result is 0.
- If the argument is negative infinity or any value less than or
equal to the value of
Integer.MIN_VALUE , the result is
equal to the value of Integer.MIN_VALUE .
- If the argument is positive infinity or any value greater than or
equal to the value of
Integer.MAX_VALUE , the result is
equal to the value of Integer.MAX_VALUE .
return (int) Math.floor(a + 0.5f);
| public static float | sin(float a)Returns the trigonometric sine of an angle. Special cases:
- If the argument is NaN or an infinity, then the
result is NaN.
- If the argument is zero, then the result is a zero with the
same sign as the argument.
A result must be within 1 ulp of the correctly rounded result. Results
must be semi-monotonic.
return (float) Math.sin(a);
| public static float | sqrt(float a)Returns the correctly rounded positive square root of a
float value.
Special cases:
- If the argument is NaN or less than zero, then the result
is NaN.
- If the argument is positive infinity, then the result is positive
infinity.
- If the argument is positive zero or negative zero, then the
result is the same as the argument.
Otherwise, the result is the float value closest to
the true mathematical square root of the argument value.
return (float) Math.sqrt(a);
| public static float | tan(float a)Returns the trigonometric tangent of an angle. Special cases:
- If the argument is NaN or an infinity, then the result
is NaN.
- If the argument is zero, then the result is a zero with the
same sign as the argument.
A result must be within 1 ulp of the correctly rounded result. Results
must be semi-monotonic.
return (float) Math.tan(a);
| public static float | toDegrees(float 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 .
return angrad * 180.0f / PI;
| public static float | toRadians(float angdeg)Converts an angle measured in degrees to an approximately
equivalent angle measured in radians. The conversion from
degrees to radians is generally inexact.
return angdeg / 180.0f * PI;
|
|