edu.mines.jtk.util
Class MathPlus

java.lang.Object
  extended by edu.mines.jtk.util.MathPlus

public class MathPlus
extends java.lang.Object

Basic math functions. Like the standard class Math, but with overloaded methods that return floats when passed float arguments. (This eliminates ugly casts when using floats.) This class also defines useful additional constants, such as FLT_PI.

Version:
2004.12.04
Author:
Dave Hale, Colorado School of Mines
See Also:
Math

Field Summary
static double DBL_E
          The double value that is closer than any other to e, the base of the natural logarithm.
static double DBL_EPSILON
          The smallest double value e such that (1+e) does not equal 1.
static double DBL_MAX
          The maximum positive double value.
static double DBL_MIN
          The minimum positive double value.
static double DBL_PI
          The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
static double E
          The double value that is closer than any other to e, the base of the natural logarithm.
static float FLT_E
          The float value that is closer than any other to e, the base of the natural logarithm.
static float FLT_EPSILON
          The smallest float value e such that (1+e) does not equal 1.
static float FLT_MAX
          The maximum positive float value.
static float FLT_MIN
          The minimum positive float value.
static float FLT_PI
          The float value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
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 x)
          Returns the absolute value of the specified value.
static float abs(float x)
          Returns the absolute value of the specified value.
static int abs(int x)
          Returns the absolute value of the specified value.
static long abs(long x)
          Returns the absolute value of the specified value.
static double acos(double x)
          Returns the arc cosine of the specified value, in the range 0.0 through pi.
static float acos(float x)
          Returns the arc cosine of the specified value, in the range 0.0 through pi.
static double asin(double x)
          Returns the arc sine of the specified value, in the range -pi/2 through pi/2.
static float asin(float x)
          Returns the arc sine of the specified value, in the range -pi/2 through pi/2.
static double atan(double x)
          Returns the arc tangent of the specified value, in the range -pi/2 through pi/2.
static float atan(float x)
          Returns the arc tangent of the specified value, in the range -pi/2 through pi/2.
static double atan2(double y, double x)
          Computes the arc tangent of the specified y/x, in the range -pi to pi.
static float atan2(float y, float x)
          Computes the arc tangent of the specified y/x, in the range -pi to pi.
static double ceil(double x)
          Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.
static float ceil(float x)
          Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.
static double cos(double x)
          Returns the trigonometric cosine of an angle.
static float cos(float x)
          Returns the trigonometric cosine of an angle.
static double cosh(double x)
          Returns the hyperbolic cosine of the specified value.
static float cosh(float x)
          Returns the hyperbolic cosine of the specified value.
static double exp(double x)
          Returns the value of e raised to the specified power.
static float exp(float x)
          Returns the value of e raised to the specified power.
static double floor(double x)
          Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal to a mathematical integer.
static float floor(float x)
          Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal to a mathematical integer.
static double log(double x)
          Returns the natural logarithm (base e) of the specified value.
static float log(float x)
          Returns the natural logarithm (base e) of the specified value.
static double log10(double x)
          Returns the logarithm base 10 of the specified value.
static float log10(float x)
          Returns the logarithm base 10 of the specified value.
static double max(double a, double b)
          Returns the maximum of the specified values.
static double max(double a, double b, double c)
          Returns the maximum of the specified values.
static double max(double a, double b, double c, double d)
          Returns the maximum of the specified values.
static float max(float a, float b)
          Returns the maximum of the specified values.
static float max(float a, float b, float c)
          Returns the maximum of the specified values.
static float max(float a, float b, float c, float d)
          Returns the maximum of the specified values.
static int max(int a, int b)
          Returns the maximum of the specified values.
static int max(int a, int b, int c)
          Returns the maximum of the specified values.
static int max(int a, int b, int c, int d)
          Returns the maximum of the specified values.
static long max(long a, long b)
          Returns the maximum of the specified values.
static long max(long a, long b, long c)
          Returns the maximum of the specified values.
static long max(long a, long b, long c, long d)
          Returns the maximum of the specified values.
static double min(double a, double b)
          Returns the minimum of the specified values.
static double min(double a, double b, double c)
          Returns the minimum of the specified values.
static double min(double a, double b, double c, double d)
          Returns the minimum of the specified values.
static float min(float a, float b)
          Returns the minimum of the specified values.
static float min(float a, float b, float c)
          Returns the minimum of the specified values.
static float min(float a, float b, float c, float d)
          Returns the minimum of the specified values.
static int min(int a, int b)
          Returns the minimum of the specified values.
static int min(int a, int b, int c)
          Returns the minimum of the specified values.
static int min(int a, int b, int c, int d)
          Returns the minimum of the specified values.
static long min(long a, long b)
          Returns the minimum of the specified values.
static long min(long a, long b, long c)
          Returns the minimum of the specified values.
static long min(long a, long b, long c, long d)
          Returns the minimum of the specified values.
static double pow(double x, double y)
          Returns the value of x raised to the y'th power.
static float pow(float x, float y)
          Returns the value of x raised to the y'th power.
static double rint(double x)
          Returns the value that is closest to the specified value and is equal to a mathematical integer.
static float rint(float x)
          Returns the value that is closest to the specified value and is equal to a mathematical integer.
static long round(double x)
          Returns the closest long to the specified value.
static int round(float x)
          Returns the closest int to the specified value.
static double signum(double x)
          Returns the signum of the specified value.
static float signum(float x)
          Returns the signum of the specified value.
static double sin(double x)
          Returns the trigonometric sine of an angle.
static float sin(float x)
          Returns the trigonometric sine of an angle.
static double sinh(double x)
          Returns the hyperbolic sine of the specified value.
static float sinh(float x)
          Returns the hyperbolic sine of the specified value.
static double sqrt(double x)
          Returns the positive square root of a the specified value.
static float sqrt(float x)
          Returns the positive square root of a the specified value.
static double tan(double x)
          Returns the trigonometric tangent of an angle.
static float tan(float x)
          Returns the trigonometric tangent of an angle.
static double tanh(double x)
          Returns the hyperbolic tangent of the specified value.
static float tanh(float x)
          Returns the hyperbolic tangent of the specified value.
static double toDegrees(double angrad)
          Converts an angle measured in radians to degrees.
static float toDegrees(float angrad)
          Converts an angle measured in radians to degrees.
static double toRadians(double angdeg)
          Converts an angle measured in degrees to radians.
static float toRadians(float angdeg)
          Converts an angle measured in degrees to radians.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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 logarithm.

See Also:
Constant Field Values

FLT_E

public static final float FLT_E
The float value that is closer than any other to e, the base of the natural logarithm.

See Also:
Constant Field Values

DBL_E

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

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.

See Also:
Constant Field Values

FLT_PI

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

See Also:
Constant Field Values

DBL_PI

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

See Also:
Constant Field Values

FLT_MAX

public static final float FLT_MAX
The maximum positive float value.

See Also:
Constant Field Values

FLT_MIN

public static final float FLT_MIN
The minimum positive float value.

See Also:
Constant Field Values

FLT_EPSILON

public static final float FLT_EPSILON
The smallest float value e such that (1+e) does not equal 1.

See Also:
Constant Field Values

DBL_MAX

public static final double DBL_MAX
The maximum positive double value.

See Also:
Constant Field Values

DBL_MIN

public static final double DBL_MIN
The minimum positive double value.

See Also:
Constant Field Values

DBL_EPSILON

public static final double DBL_EPSILON
The smallest double value e such that (1+e) does not equal 1.

See Also:
Constant Field Values
Method Detail

sin

public static float sin(float x)
Returns the trigonometric sine of an angle.

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

sin

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

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

cos

public static float cos(float x)
Returns the trigonometric cosine of an angle.

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

cos

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

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

tan

public static float tan(float x)
Returns the trigonometric tangent of an angle.

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

tan

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

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

asin

public static float asin(float x)
Returns the arc sine of the specified value, in the range -pi/2 through pi/2.

Parameters:
x - the value.
Returns:
the arc sine.

asin

public static double asin(double x)
Returns the arc sine of the specified value, in the range -pi/2 through pi/2.

Parameters:
x - the value.
Returns:
the arc sine.

acos

public static float acos(float x)
Returns the arc cosine of the specified value, in the range 0.0 through pi.

Parameters:
x - the value.
Returns:
the arc cosine.

acos

public static double acos(double x)
Returns the arc cosine of the specified value, in the range 0.0 through pi.

Parameters:
x - the value.
Returns:
the arc cosine.

atan

public static float atan(float x)
Returns the arc tangent of the specified value, in the range -pi/2 through pi/2.

Parameters:
x - the value.
Returns:
the arc tangent.

atan

public static double atan(double x)
Returns the arc tangent of the specified value, in the range -pi/2 through pi/2.

Parameters:
x - the value.
Returns:
the arc tangent.

atan2

public static float atan2(float y,
                          float x)
Computes the arc tangent of the specified y/x, in the range -pi to pi.

Parameters:
y - the ordinate coordinate y.
x - the abscissa coordinate x.
Returns:
the arc tangent.

atan2

public static double atan2(double y,
                           double x)
Computes the arc tangent of the specified y/x, in the range -pi to pi.

Parameters:
y - the ordinate coordinate y.
x - the abscissa coordinate x.
Returns:
the arc tangent.

toRadians

public static float toRadians(float angdeg)
Converts an angle measured in degrees to radians.

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

toRadians

public static double toRadians(double angdeg)
Converts an angle measured in degrees to radians.

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

toDegrees

public static float toDegrees(float angrad)
Converts an angle measured in radians to degrees.

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

toDegrees

public static double toDegrees(double angrad)
Converts an angle measured in radians to degrees.

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

exp

public static float exp(float x)
Returns the value of e raised to the specified power.

Parameters:
x - the exponent.
Returns:
the value.

exp

public static double exp(double x)
Returns the value of e raised to the specified power.

Parameters:
x - the exponent.
Returns:
the value.

log

public static float log(float x)
Returns the natural logarithm (base e) of the specified value.

Parameters:
x - the value.
Returns:
the natural logarithm.

log

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

Parameters:
x - the value.
Returns:
the natural logarithm.

log10

public static float log10(float x)
Returns the logarithm base 10 of the specified value.

Parameters:
x - the value.
Returns:
the logarithm base 10.

log10

public static double log10(double x)
Returns the logarithm base 10 of the specified value.

Parameters:
x - the value.
Returns:
the logarithm base 10.

sqrt

public static float sqrt(float x)
Returns the positive square root of a the specified value.

Parameters:
x - the value.
Returns:
the positive square root.

sqrt

public static double sqrt(double x)
Returns the positive square root of a the specified value.

Parameters:
x - the value.
Returns:
the positive square root.

pow

public static float pow(float x,
                        float y)
Returns the value of x raised to the y'th power.

Parameters:
x - the base.
y - the exponent.
Returns:
the value.

pow

public static double pow(double x,
                         double y)
Returns the value of x raised to the y'th power.

Parameters:
x - the base.
y - the exponent.
Returns:
the value.

sinh

public static float sinh(float x)
Returns the hyperbolic sine of the specified value.

Parameters:
x - the value.
Returns:
the hyperbolic sine.

sinh

public static double sinh(double x)
Returns the hyperbolic sine of the specified value.

Parameters:
x - the value.
Returns:
the hyperbolic sine.

cosh

public static float cosh(float x)
Returns the hyperbolic cosine of the specified value.

Parameters:
x - the value.
Returns:
the hyperbolic cosine.

cosh

public static double cosh(double x)
Returns the hyperbolic cosine of the specified value.

Parameters:
x - the value.
Returns:
the hyperbolic cosine.

tanh

public static float tanh(float x)
Returns the hyperbolic tangent of the specified value.

Parameters:
x - the value.
Returns:
the hyperbolic cosine.

tanh

public static double tanh(double x)
Returns the hyperbolic tangent of the specified value.

Parameters:
x - the value.
Returns:
the hyperbolic cosine.

ceil

public static float ceil(float x)
Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.

Parameters:
x - a value.
Returns:
the smallest value.

ceil

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

Parameters:
x - a value.
Returns:
the smallest value.

floor

public static float floor(float x)
Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal to a mathematical integer.

Parameters:
x - a value.
Returns:
the largest value.

floor

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

Parameters:
x - a value.
Returns:
the largest value.

rint

public static float rint(float x)
Returns the value that is closest to the specified value and is equal to a mathematical integer.

Parameters:
x - the value.
Returns:
the closest value.

rint

public static double rint(double x)
Returns the value that is closest to the specified value and is equal to a mathematical integer.

Parameters:
x - the value.
Returns:
the closest value.

round

public static int round(float x)
Returns the closest int to the specified value. The result is the value of the expression (int)Math.floor(a+0.5f).

Parameters:
x - the value.
Returns:
the value rounded to the nearest int.

round

public static long round(double x)
Returns the closest long to the specified value. The result is the value of the expression (long)Math.floor(a+0.5).

Parameters:
x - the value.
Returns:
the value rounded to the nearest long.

signum

public static float signum(float x)
Returns the signum of the specified value. The signum is zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

Parameters:
x - the value.
Returns:
the signum.

signum

public static double signum(double x)
Returns the signum of the specified value. The signum is zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

Parameters:
x - the value.
Returns:
the signum.

abs

public static int abs(int x)
Returns the absolute value of the specified value.

Parameters:
x - the value.
Returns:
the absolute value.

abs

public static long abs(long x)
Returns the absolute value of the specified value.

Parameters:
x - the value.
Returns:
the absolute value.

abs

public static float abs(float x)
Returns the absolute value of the specified value.

Parameters:
x - the value.
Returns:
the absolute value.

abs

public static double abs(double x)
Returns the absolute value of the specified value.

Parameters:
x - the value.
Returns:
the absolute value.

max

public static int max(int a,
                      int b)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the maximum value.

max

public static int max(int a,
                      int b,
                      int c)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the maximum value.

max

public static int max(int a,
                      int b,
                      int c,
                      int d)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the maximum value.

max

public static long max(long a,
                       long b)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the maximum value.

max

public static long max(long a,
                       long b,
                       long c)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the maximum value.

max

public static long max(long a,
                       long b,
                       long c,
                       long d)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the maximum value.

max

public static float max(float a,
                        float b)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the maximum value.

max

public static float max(float a,
                        float b,
                        float c)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the maximum value.

max

public static float max(float a,
                        float b,
                        float c,
                        float d)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the maximum value.

max

public static double max(double a,
                         double b)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the maximum value.

max

public static double max(double a,
                         double b,
                         double c)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the maximum value.

max

public static double max(double a,
                         double b,
                         double c,
                         double d)
Returns the maximum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the maximum value.

min

public static int min(int a,
                      int b)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the minimum value.

min

public static int min(int a,
                      int b,
                      int c)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the minimum value.

min

public static int min(int a,
                      int b,
                      int c,
                      int d)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the minimum value.

min

public static long min(long a,
                       long b)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the minimum value.

min

public static long min(long a,
                       long b,
                       long c)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the minimum value.

min

public static long min(long a,
                       long b,
                       long c,
                       long d)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the minimum value.

min

public static float min(float a,
                        float b)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the minimum value.

min

public static float min(float a,
                        float b,
                        float c)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the minimum value.

min

public static float min(float a,
                        float b,
                        float c,
                        float d)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the minimum value.

min

public static double min(double a,
                         double b)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
Returns:
the minimum value.

min

public static double min(double a,
                         double b,
                         double c)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
Returns:
the minimum value.

min

public static double min(double a,
                         double b,
                         double c,
                         double d)
Returns the minimum of the specified values.

Parameters:
a - a value.
b - a value.
c - a value.
d - a value.
Returns:
the minimum value.