Sprites for Processing  V2.1
 All Classes Functions Variables
sprites.maths.FastMath Class Reference

Static Public Member Functions

static double sqrt (final double a)
 
static double cosh (double x)
 
static double sinh (double x)
 
static double tanh (double x)
 
static double acosh (final double a)
 
static double asinh (double a)
 
static double atanh (double a)
 
static double signum (final double a)
 
static float signum (final float a)
 
static double nextUp (final double a)
 
static float nextUp (final float a)
 
static double random ()
 
static double exp (double x)
 
static double expm1 (double x)
 
static double log (final double x)
 
static double log1p (final double x)
 
static double log10 (final double x)
 
static double pow (double x, double y)
 
static double sin (double x)
 
static double cos (double x)
 
static double tan (double x)
 
static double atan (double x)
 
static double atan2 (double y, double x)
 
static double asin (double x)
 
static double acos (double x)
 
static double cbrt (double x)
 
static double toRadians (double x)
 
static double toDegrees (double x)
 
static int abs (final int x)
 
static long abs (final long x)
 
static float abs (final float x)
 
static double abs (double x)
 
static double ulp (double x)
 
static float ulp (float x)
 
static double scalb (final double d, final int n)
 
static float scalb (final float f, final int n)
 
static double nextAfter (double d, double direction)
 
static float nextAfter (final float f, final double direction)
 
static double floor (double x)
 
static double ceil (double x)
 
static double rint (double x)
 
static long round (double x)
 
static int round (final float x)
 
static int min (final int a, final int b)
 
static long min (final long a, final long b)
 
static float min (final float a, final float b)
 
static double min (final double a, final double b)
 
static int max (final int a, final int b)
 
static long max (final long a, final long b)
 
static float max (final float a, final float b)
 
static double max (final double a, final double b)
 
static double hypot (final double x, final double y)
 
static double IEEEremainder (double dividend, double divisor)
 
static double copySign (double magnitude, double sign)
 
static float copySign (float magnitude, float sign)
 
static int getExponent (final double d)
 
static int getExponent (final float f)
 

Static Public Attributes

static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9
 
static final double E = 2850325.0 / 1048576.0 + 8.254840070411028747e-8
 
static final double SAFE_MIN = 0x1.0p-1022
 

Detailed Description

Faster, more accurate, portable alternative to StrictMath.

Additionally implements the following methods not found in StrictMath:

The following methods are found in StrictMath since 1.6 only

Since
2.2

Member Function Documentation

static int sprites.maths.FastMath.abs ( final int  x)
static

Absolute value.

Parameters
xnumber from which absolute value is requested
Returns
abs(x)
static long sprites.maths.FastMath.abs ( final long  x)
static

Absolute value.

Parameters
xnumber from which absolute value is requested
Returns
abs(x)
static float sprites.maths.FastMath.abs ( final float  x)
static

Absolute value.

Parameters
xnumber from which absolute value is requested
Returns
abs(x)
static double sprites.maths.FastMath.abs ( double  x)
static

Absolute value.

Parameters
xnumber from which absolute value is requested
Returns
abs(x)
static double sprites.maths.FastMath.acos ( double  x)
static

Compute the arc cosine of a number.

Parameters
xnumber on which evaluation is done
Returns
arc cosine of x
static double sprites.maths.FastMath.acosh ( final double  a)
static

Compute the inverse hyperbolic cosine of a number.

Parameters
anumber on which evaluation is done
Returns
inverse hyperbolic cosine of a
static double sprites.maths.FastMath.asin ( double  x)
static

Compute the arc sine of a number.

Parameters
xnumber on which evaluation is done
Returns
arc sine of x
static double sprites.maths.FastMath.asinh ( double  a)
static

Compute the inverse hyperbolic sine of a number.

Parameters
anumber on which evaluation is done
Returns
inverse hyperbolic sine of a
static double sprites.maths.FastMath.atan ( double  x)
static

Arctangent function

Parameters
xa number
Returns
atan(x)
static double sprites.maths.FastMath.atan2 ( double  y,
double  x 
)
static

Two arguments arctangent function

Parameters
yordinate
xabscissa
Returns
phase angle of point (x,y) between
-PI
and
static double sprites.maths.FastMath.atanh ( double  a)
static

Compute the inverse hyperbolic tangent of a number.

Parameters
anumber on which evaluation is done
Returns
inverse hyperbolic tangent of a
static double sprites.maths.FastMath.cbrt ( double  x)
static

Compute the cubic root of a number.

Parameters
xnumber on which evaluation is done
Returns
cubic root of x
static double sprites.maths.FastMath.ceil ( double  x)
static

Get the smallest whole number larger than x.

Parameters
xnumber from which ceil is requested
Returns
a double number c such that c is an integer c - 1.0 < x <= c
static double sprites.maths.FastMath.copySign ( double  magnitude,
double  sign 
)
static

Returns the first argument with the sign of the second argument. A NaN

sign

argument is treated as positive.

Parameters
magnitudethe value to return
signthe sign for the returned value
Returns
the magnitude with the same sign as the
sign
argument
static float sprites.maths.FastMath.copySign ( float  magnitude,
float  sign 
)
static

Returns the first argument with the sign of the second argument. A NaN

sign

argument is treated as positive.

Parameters
magnitudethe value to return
signthe sign for the returned value
Returns
the magnitude with the same sign as the
sign
argument
static double sprites.maths.FastMath.cos ( double  x)
static

Cosine function

Parameters
xa number
Returns
cos(x)
static double sprites.maths.FastMath.cosh ( double  x)
static

Compute the hyperbolic cosine of a number.

Parameters
xnumber on which evaluation is done
Returns
hyperbolic cosine of x
static double sprites.maths.FastMath.exp ( double  x)
static

Exponential function.

Computes exp(x), function result is nearly rounded. It will be correctly rounded to the theoretical value for 99.9% of input values, otherwise it will have a 1 UPL error.

Method: Lookup intVal = exp(int(x)) Lookup fracVal = exp(int(x-int(x) / 1024.0) * 1024.0 ); Compute z as the exponential of the remaining bits by a polynomial minus one exp(x) = intVal * fracVal * (1 + z)

Accuracy: Calculation is done with 63 bits of precision, so result should be correctly rounded for 99.9% of input values, with less than 1 ULP error otherwise.

Parameters
xa double
Returns
double ex
static double sprites.maths.FastMath.expm1 ( double  x)
static

Compute exp(x) - 1

Parameters
xnumber to compute shifted exponential
Returns
exp(x) - 1
static double sprites.maths.FastMath.floor ( double  x)
static

Get the largest whole number smaller than x.

Parameters
xnumber from which floor is requested
Returns
a double number f such that f is an integer f <= x < f + 1.0
static int sprites.maths.FastMath.getExponent ( final double  d)
static

Return the exponent of a double number, removing the bias.

For double numbers of the form 2x, the unbiased exponent is exactly x.

Parameters
dnumber from which exponent is requested
Returns
exponent for d in IEEE754 representation, without bias
static int sprites.maths.FastMath.getExponent ( final float  f)
static

Return the exponent of a float number, removing the bias.

For float numbers of the form 2x, the unbiased exponent is exactly x.

Parameters
fnumber from which exponent is requested
Returns
exponent for d in IEEE754 representation, without bias
static double sprites.maths.FastMath.hypot ( final double  x,
final double  y 
)
static

Returns the hypotenuse of a triangle with sides

x

and

y
  • sqrt(x2 +y2)
    avoiding intermediate overflow or underflow.
  • If either argument is infinite, then the result is positive infinity.
  • else, if either argument is NaN then the result is NaN.
Parameters
xa value
ya value
Returns
sqrt(x2 +y2)
static double sprites.maths.FastMath.IEEEremainder ( double  dividend,
double  divisor 
)
static

Computes the remainder as prescribed by the IEEE 754 standard. The remainder value is mathematically equal to

x - y*n

where

n

is the mathematical integer closest to the exact mathematical value of the quotient

x/y

. If two mathematical integers are equally close to

x/y

then

n

is the integer that is even.

  • If either operand is NaN, the result is NaN.
  • If the result is not NaN, the sign of the result equals the sign of the dividend.
  • If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
  • If the dividend is finite and the divisor is an infinity, the result equals the dividend.
  • If the dividend is a zero and the divisor is finite, the result equals the dividend.

Note: this implementation currently delegates to StrictMath#IEEEremainder

Parameters
dividendthe number to be divided
divisorthe number by which to divide
Returns
the remainder, rounded
static double sprites.maths.FastMath.log ( final double  x)
static

Natural logarithm.

Parameters
xa double
Returns
log(x)
static double sprites.maths.FastMath.log10 ( final double  x)
static

Compute the base 10 logarithm.

Parameters
xa number
Returns
log10(x)
static double sprites.maths.FastMath.log1p ( final double  x)
static

Compute log(1 + x).

Parameters
xa number
Returns
log(1 + x)
static int sprites.maths.FastMath.max ( final int  a,
final int  b 
)
static

Compute the maximum of two values

Parameters
afirst value
bsecond value
Returns
b if a is lesser or equal to b, a otherwise
static long sprites.maths.FastMath.max ( final long  a,
final long  b 
)
static

Compute the maximum of two values

Parameters
afirst value
bsecond value
Returns
b if a is lesser or equal to b, a otherwise
static float sprites.maths.FastMath.max ( final float  a,
final float  b 
)
static

Compute the maximum of two values

Parameters
afirst value
bsecond value
Returns
b if a is lesser or equal to b, a otherwise
static double sprites.maths.FastMath.max ( final double  a,
final double  b 
)
static

Compute the maximum of two values

Parameters
afirst value
bsecond value
Returns
b if a is lesser or equal to b, a otherwise
static int sprites.maths.FastMath.min ( final int  a,
final int  b 
)
static

Compute the minimum of two values

Parameters
afirst value
bsecond value
Returns
a if a is lesser or equal to b, b otherwise
static long sprites.maths.FastMath.min ( final long  a,
final long  b 
)
static

Compute the minimum of two values

Parameters
afirst value
bsecond value
Returns
a if a is lesser or equal to b, b otherwise
static float sprites.maths.FastMath.min ( final float  a,
final float  b 
)
static

Compute the minimum of two values

Parameters
afirst value
bsecond value
Returns
a if a is lesser or equal to b, b otherwise
static double sprites.maths.FastMath.min ( final double  a,
final double  b 
)
static

Compute the minimum of two values

Parameters
afirst value
bsecond value
Returns
a if a is lesser or equal to b, b otherwise
static double sprites.maths.FastMath.nextAfter ( double  d,
double  direction 
)
static

Get the next machine representable number after a number, moving in the direction of another number.

The ordering is as follows (increasing):

  • -INFINITY
  • -MAX_VALUE
  • -MIN_VALUE
  • -0.0
  • +0.0
  • +MIN_VALUE
  • +MAX_VALUE
  • +INFINITY
  • If arguments compare equal, then the second argument is returned.

    If

    direction

    is greater than

    d

    , the smallest machine representable number strictly greater than

    d

    is returned; if less, then the largest representable number strictly less than

    d

    is returned.

    If

    d

    is infinite and direction does not bring it back to finite numbers, it is returned unchanged.

    Parameters
    dbase number
    direction(the only important thing is whether
    direction
    is greater or smaller than
    d
    )
    Returns
    the next machine representable number in the specified direction
static float sprites.maths.FastMath.nextAfter ( final float  f,
final double  direction 
)
static

Get the next machine representable number after a number, moving in the direction of another number.

The ordering is as follows (increasing):

  • -INFINITY
  • -MAX_VALUE
  • -MIN_VALUE
  • -0.0
  • +0.0
  • +MIN_VALUE
  • +MAX_VALUE
  • +INFINITY
  • If arguments compare equal, then the second argument is returned.

    If

    direction

    is greater than

    f

    , the smallest machine representable number strictly greater than

    f

    is returned; if less, then the largest representable number strictly less than

    f

    is returned.

    If

    f

    is infinite and direction does not bring it back to finite numbers, it is returned unchanged.

    Parameters
    fbase number
    direction(the only important thing is whether
    direction
    is greater or smaller than
    f
    )
    Returns
    the next machine representable number in the specified direction
static double sprites.maths.FastMath.nextUp ( final double  a)
static

Compute next number towards positive infinity.

Parameters
anumber to which neighbor should be computed
Returns
neighbor of a towards positive infinity
static float sprites.maths.FastMath.nextUp ( final float  a)
static

Compute next number towards positive infinity.

Parameters
anumber to which neighbor should be computed
Returns
neighbor of a towards positive infinity
static double sprites.maths.FastMath.pow ( double  x,
double  y 
)
static

Power function. Compute x^y.

Parameters
xa double
ya double
Returns
double
static double sprites.maths.FastMath.random ( )
static

Returns a pseudo-random number between 0.0 and 1.0.

Note: this implementation currently delegates to Math#random

Returns
a random number between 0.0 and 1.0
static double sprites.maths.FastMath.rint ( double  x)
static

Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers.

Parameters
xnumber from which nearest whole number is requested
Returns
a double number r such that r is an integer r - 0.5 <= x <= r + 0.5
static long sprites.maths.FastMath.round ( double  x)
static

Get the closest long to x.

Parameters
xnumber from which closest long is requested
Returns
closest long to x
static int sprites.maths.FastMath.round ( final float  x)
static

Get the closest int to x.

Parameters
xnumber from which closest int is requested
Returns
closest int to x
static double sprites.maths.FastMath.scalb ( final double  d,
final int  n 
)
static

Multiply a double number by a power of 2.

Parameters
dnumber to multiply
npower of 2
Returns
d × 2n
static float sprites.maths.FastMath.scalb ( final float  f,
final int  n 
)
static

Multiply a float number by a power of 2.

Parameters
fnumber to multiply
npower of 2
Returns
f × 2n
static double sprites.maths.FastMath.signum ( final double  a)
static

Compute the signum of a number. The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise

Parameters
anumber on which evaluation is done
Returns
-1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
static float sprites.maths.FastMath.signum ( final float  a)
static

Compute the signum of a number. The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise

Parameters
anumber on which evaluation is done
Returns
-1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
static double sprites.maths.FastMath.sin ( double  x)
static

Sine function.

Parameters
xa number
Returns
sin(x)
static double sprites.maths.FastMath.sinh ( double  x)
static

Compute the hyperbolic sine of a number.

Parameters
xnumber on which evaluation is done
Returns
hyperbolic sine of x
static double sprites.maths.FastMath.sqrt ( final double  a)
static

Compute the square root of a number.

Note: this implementation currently delegates to Math#sqrt

Parameters
anumber on which evaluation is done
Returns
square root of a
static double sprites.maths.FastMath.tan ( double  x)
static

Tangent function

Parameters
xa number
Returns
tan(x)
static double sprites.maths.FastMath.tanh ( double  x)
static

Compute the hyperbolic tangent of a number.

Parameters
xnumber on which evaluation is done
Returns
hyperbolic tangent of x
static double sprites.maths.FastMath.toDegrees ( double  x)
static

Convert radians to degrees, with error of less than 0.5 ULP

Parameters
xangle in radians
Returns
x converted into degrees
static double sprites.maths.FastMath.toRadians ( double  x)
static

Convert degrees to radians, with error of less than 0.5 ULP

Parameters
xangle in degrees
Returns
x converted into radians
static double sprites.maths.FastMath.ulp ( double  x)
static

Compute least significant bit (Unit in Last Position) for a number.

Parameters
xnumber from which ulp is requested
Returns
ulp(x)
static float sprites.maths.FastMath.ulp ( float  x)
static

Compute least significant bit (Unit in Last Position) for a number.

Parameters
xnumber from which ulp is requested
Returns
ulp(x)

Member Data Documentation

final double sprites.maths.FastMath.E = 2850325.0 / 1048576.0 + 8.254840070411028747e-8
static

Napier's constant e, base of the natural logarithm.

final double sprites.maths.FastMath.PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9
static

Archimede's constant PI, ratio of circle circumference to diameter.

final double sprites.maths.FastMath.SAFE_MIN = 0x1.0p-1022
static

Safe minimum, such that 1 / SAFE_MIN does not overflow.

In IEEE 754 arithmetic, this is also the smallest normalized number 2-1022.


The documentation for this class was generated from the following file: