public final class FastMath extends Object
| Modifier and Type | Class and Description |
|---|---|
class |
FastMath.DoubleWrapper |
class |
FastMath.IntWrapper |
| Modifier and Type | Field and Description |
|---|---|
static double |
E |
static double |
PI |
static double |
PI_SUP
High approximation of PI, which is further from PI
than the low approximation Math.PI:
PI ~= 3.14159265358979323846...
|
| Modifier and Type | Method and Description |
|---|---|
static double |
abs(double a) |
static float |
abs(float a) |
static int |
abs(int value) |
static long |
abs(long a) |
static double |
acos(double value) |
static double |
acosInRange(double value)
If value is not NaN and is outside [-1,1] range, closest value in this range is used.
|
static int |
addBounded(int a,
int b) |
static long |
addBounded(long a,
long b) |
static int |
addExact(int a,
int b) |
static long |
addExact(long a,
long b) |
static double |
asin(double value) |
static double |
asinInRange(double value)
If value is not NaN and is outside [-1,1] range, closest value in this range is used.
|
static double |
atan(double value) |
static double |
atan2(double y,
double x)
For special values for which multiple conventions could be adopted, behaves like Math.atan2(double,double).
|
static double |
cbrt(double value) |
static double |
ceil(double value)
Supposed to behave like Math.ceil(double), for safe interchangeability.
|
static float |
ceil(float value) |
static double |
copySign(double magnitude,
double sign) |
static float |
copySign(float magnitude,
float sign) |
static double |
cos(double angle) |
static double |
cosh(double value) |
static double |
cosQuick(double angle)
Quick cosine, with accuracy of about 1.6e-3 (PI/'look-up tabs size')
for |angle| < 6588397.0 (Integer.MAX_VALUE * (2*PI/'look-up tabs size')),
and no accuracy at all for larger values.
|
static double |
exp(double value) |
static double |
expm1(double value)
Much more accurate than exp(value)-1, for values close to zero.
|
static double |
expQuick(double value)
Quick exp, with a max relative error of about 3e-2 for |value| < 700.0 or so,
and no accuracy at all outside this range.
|
static double |
floor(double value)
Supposed to behave like Math.floor(double), for safe interchangeability.
|
static float |
floor(float value) |
static int |
getExponent(double value) |
static int |
getExponent(float value) |
static double |
hypot(double x,
double y)
Returns sqrt(x^2+y^2) without intermediate overflow or underflow.
|
static double |
IEEEremainder(double f1,
double f2) |
static boolean |
isInClockwiseDomain(double startAngRad,
double angSpanRad,
double angRad)
NB: Since 2*Math.PI < 2*PI, a span of 2*Math.PI does not mean full angular range.
|
static boolean |
isNaNOrInfinite(double value) |
static boolean |
isNaNOrInfinite(float value) |
static double |
log(double value) |
static double |
log10(double value) |
static double |
log1p(double value)
Much more accurate than log(1+value), for values close to zero.
|
static int |
log2(int value) |
static int |
log2(long value) |
static double |
logQuick(double value)
Quick log, with a max relative error of about 2.8e-4
for values in ]0,+infinity[, and no accuracy at all
outside this range.
|
static double |
max(double a,
double b) |
static float |
max(float a,
float b) |
static int |
max(int a,
int b) |
static long |
max(long a,
long b) |
static double |
min(double a,
double b) |
static float |
min(float a,
float b) |
static int |
min(int a,
int b) |
static long |
min(long a,
long b) |
static int |
multiplyBounded(int a,
int b) |
static long |
multiplyBounded(long a,
long b) |
static int |
multiplyExact(int a,
int b) |
static long |
multiplyExact(long a,
long b) |
static double |
nextAfter(double start,
double direction) |
static float |
nextAfter(float start,
float direction) |
static double |
nextUp(double d) |
static float |
nextUp(float f) |
static double |
normalizeMinusHalfPiHalfPi(double angle) |
static double |
normalizeMinusHalfPiHalfPiFast(double angle)
Not accurate for large values.
|
static double |
normalizeMinusPiPi(double angle) |
static double |
normalizeMinusPiPiFast(double angle)
Not accurate for large values.
|
static double |
normalizeZeroTwoPi(double angle) |
static double |
normalizeZeroTwoPiFast(double angle)
Not accurate for large values.
|
static double |
pow(double value,
double power)
1e-13ish accuracy (or better) on whole double range.
|
static double |
pow2(double value) |
static float |
pow2(float value) |
static int |
pow2(int value) |
static long |
pow2(long value) |
static double |
pow3(double value) |
static float |
pow3(float value) |
static int |
pow3(int value) |
static long |
pow3(long value) |
static double |
powFast(double value,
int power)
This treatment is somehow accurate for low values of |power|,
and for |power*getExponent(value)| < 1023 or so (to stay away
from double extreme magnitudes (large and small)).
|
static double |
powQuick(double value,
double power)
Quick pow, with a max relative error of about 3.5e-2
for |a^b| < 1e10, of about 0.17 for |a^b| < 1e50,
and worse accuracy above.
|
static double |
random() |
static double |
remainder(double dividend,
double divisor)
Returns dividend - divisor * n, where n is the mathematical integer
closest to dividend/divisor.
|
static double |
rint(double a) |
static long |
round(double value)
Supposed to behave like Math.round(double), for safe interchangeability.
|
static int |
round(float value)
Supposed to behave like Math.round(float), for safe interchangeability.
|
static double |
scalb(double d,
int scaleFactor) |
static float |
scalb(float f,
int scaleFactor) |
static double |
signum(double d) |
static float |
signum(float f) |
static double |
sin(double angle) |
static void |
sinAndCos(double angle,
FastMath.DoubleWrapper sine,
FastMath.DoubleWrapper cosine)
Computes sine and cosine together, at the cost of... a dependency of this class with DoubleWrapper.
|
static double |
sinh(double value) |
static void |
sinhAndCosh(double value,
FastMath.DoubleWrapper hsine,
FastMath.DoubleWrapper hcosine)
Computes hyperbolic sine and hyperbolic cosine together, at the cost of... a dependency of this class with DoubleWrapper.
|
static double |
sinQuick(double angle)
Quick sine, with accuracy of about 1.6e-3 (PI/'look-up tabs size')
for |angle| < 6588397.0 (Integer.MAX_VALUE * (2*PI/'look-up tabs size')),
and no accuracy at all for larger values.
|
static double |
sqrt(double value) |
static int |
subtractBounded(int a,
int b) |
static long |
subtractBounded(long a,
long b) |
static int |
subtractExact(int a,
int b) |
static long |
subtractExact(long a,
long b) |
static double |
tan(double angle) |
static double |
tanh(double value) |
static double |
toDegrees(boolean sign,
int degrees,
int minutes,
double seconds) |
static double |
toDegrees(double angrad)
Gives same result as Math.toDegrees for some particular values
like Math.PI/2, Math.PI or 2*Math.PI, but is faster (no division).
|
static boolean |
toDMS(double angrad,
FastMath.IntWrapper degrees,
FastMath.IntWrapper minutes,
FastMath.DoubleWrapper seconds) |
static int |
toInt(long value) |
static int |
toIntExact(long value) |
static double |
toRadians(boolean sign,
int degrees,
int minutes,
double seconds) |
static double |
toRadians(double angdeg)
Gives same result as Math.toRadians for some particular values
like 90.0, 180.0 or 360.0, but is faster (no division).
|
static double |
toRange(double minValue,
double maxValue,
double value) |
static float |
toRange(float minValue,
float maxValue,
float value) |
static int |
toRange(int minValue,
int maxValue,
int value) |
static long |
toRange(long minValue,
long maxValue,
long value) |
static double |
twoPow(int power)
Returns the exact result, provided it's in double range.
|
static double |
ulp(double d) |
static float |
ulp(float f) |
public static final double PI_SUP
public static final double E
public static final double PI
public static double cos(double angle)
angle - Angle in radians.public static double cosQuick(double angle)
angle - Angle in radians.public static double sin(double angle)
angle - Angle in radians.public static double sinQuick(double angle)
angle - Angle in radians.public static void sinAndCos(double angle,
FastMath.DoubleWrapper sine,
FastMath.DoubleWrapper cosine)
angle - Angle in radians.sine - Angle sine.cosine - Angle cosine.public static double tan(double angle)
angle - Angle in radians.public static double acos(double value)
value - Value in [-1,1].public static double acosInRange(double value)
value - Value in [-1,1].public static double asin(double value)
value - Value in [-1,1].public static double asinInRange(double value)
value - Value in [-1,1].public static double atan(double value)
value - A double value.public static double atan2(double y,
double x)
y - Coordinate on y axis.x - Coordinate on x axis.public static double cosh(double value)
value - A double value.public static double sinh(double value)
value - A double value.public static void sinhAndCosh(double value,
FastMath.DoubleWrapper hsine,
FastMath.DoubleWrapper hcosine)
value - A double value.hsine - Value hyperbolic sine.hcosine - Value hyperbolic cosine.public static double tanh(double value)
value - A double value.public static double exp(double value)
value - A double value.public static double expQuick(double value)
value - A double value.public static double expm1(double value)
value - A double value.public static double log(double value)
value - A double value.public static double logQuick(double value)
public static double log10(double value)
value - A double value.public static double log1p(double value)
value - A double value.public static int log2(int value)
value - An integer value in [1,Integer.MAX_VALUE].IllegalArgumentException - if the specified value is <= 0.public static int log2(long value)
value - An integer value in [1,Long.MAX_VALUE].IllegalArgumentException - if the specified value is <= 0.public static double pow(double value,
double power)
value - A double value.power - A power.public static double powQuick(double value,
double power)
value - A double value, in ]0,+infinity[ (strictly positive and finite).power - A double value.public static double powFast(double value,
int power)
value - A double value.power - A power.public static double twoPow(int power)
power - A power.public static int pow2(int value)
value - An int value.public static long pow2(long value)
value - A long value.public static float pow2(float value)
value - A float value.public static double pow2(double value)
value - A double value.public static int pow3(int value)
value - An int value.public static long pow3(long value)
value - A long value.public static float pow3(float value)
value - A float value.public static double pow3(double value)
value - A double value.public static double sqrt(double value)
value - A double value.public static double cbrt(double value)
value - A double value.public static double remainder(double dividend,
double divisor)
dividend - Dividend.divisor - Divisor.public static double normalizeMinusPiPi(double angle)
angle - Angle in radians.public static double normalizeMinusPiPiFast(double angle)
angle - Angle in radians.public static double normalizeZeroTwoPi(double angle)
angle - Angle in radians.public static double normalizeZeroTwoPiFast(double angle)
angle - Angle in radians.public static double normalizeMinusHalfPiHalfPi(double angle)
angle - Angle in radians.public static double normalizeMinusHalfPiHalfPiFast(double angle)
angle - Angle in radians.public static double hypot(double x,
double y)
public static float ceil(float value)
value - A float value.public static double ceil(double value)
value - A double value.public static float floor(float value)
value - A float value.public static double floor(double value)
value - A double value.public static int round(float value)
value - A double value.public static long round(double value)
value - A double value.public static int getExponent(float value)
value - A float value.public static int getExponent(double value)
value - A double value.public static double toDegrees(double angrad)
angrad - Angle value in radians.public static double toRadians(double angdeg)
angdeg - Angle value in degrees.public static double toRadians(boolean sign,
int degrees,
int minutes,
double seconds)
sign - Sign of the angle: true for positive, false for negative.degrees - Degrees, in [0,180].minutes - Minutes, in [0,59].seconds - Seconds, in [0.0,60.0[.public static double toDegrees(boolean sign,
int degrees,
int minutes,
double seconds)
sign - Sign of the angle: true for positive, false for negative.degrees - Degrees, in [0,180].minutes - Minutes, in [0,59].seconds - Seconds, in [0.0,60.0[.public static boolean toDMS(double angrad,
FastMath.IntWrapper degrees,
FastMath.IntWrapper minutes,
FastMath.DoubleWrapper seconds)
angrad - Angle in radians.degrees - (out) Degrees, in [0,180].minutes - (out) Minutes, in [0,59].seconds - (out) Seconds, in [0.0,60.0[.public static int abs(int value)
value - An int value.public static int toIntExact(long value)
value - A long value.ArithmeticException - if the specified value is not in [Integer.MIN_VALUE,Integer.MAX_VALUE] range.public static int toInt(long value)
value - A long value.public static int addExact(int a,
int b)
a - An int value.b - An int value.ArithmeticException - if the mathematical result of a+b is not in [Integer.MIN_VALUE,Integer.MAX_VALUE] range.public static long addExact(long a,
long b)
a - A long value.b - A long value.ArithmeticException - if the mathematical result of a+b is not in [Long.MIN_VALUE,Long.MAX_VALUE] range.public static int addBounded(int a,
int b)
a - An int value.b - An int value.public static long addBounded(long a,
long b)
a - A long value.b - A long value.public static int subtractExact(int a,
int b)
a - An int value.b - An int value.ArithmeticException - if the mathematical result of a-b is not in [Integer.MIN_VALUE,Integer.MAX_VALUE] range.public static long subtractExact(long a,
long b)
a - A long value.b - A long value.ArithmeticException - if the mathematical result of a-b is not in [Long.MIN_VALUE,Long.MAX_VALUE] range.public static int subtractBounded(int a,
int b)
a - An int value.b - An int value.public static long subtractBounded(long a,
long b)
a - A long value.b - A long value.public static int multiplyExact(int a,
int b)
a - An int value.b - An int value.ArithmeticException - if the mathematical result of a*b is not in [Integer.MIN_VALUE,Integer.MAX_VALUE] range.public static long multiplyExact(long a,
long b)
a - A long value.b - A long value.ArithmeticException - if the mathematical result of a*b is not in [Long.MIN_VALUE,Long.MAX_VALUE] range.public static int multiplyBounded(int a,
int b)
a - An int value.b - An int value.public static long multiplyBounded(long a,
long b)
a - A long value.b - A long value.public static int toRange(int minValue,
int maxValue,
int value)
minValue - An int value.maxValue - An int value.value - An int value.public static long toRange(long minValue,
long maxValue,
long value)
minValue - A long value.maxValue - A long value.value - A long value.public static float toRange(float minValue,
float maxValue,
float value)
minValue - A float value.maxValue - A float value.value - A float value.public static double toRange(double minValue,
double maxValue,
double value)
minValue - A double value.maxValue - A double value.value - A double value.public static boolean isInClockwiseDomain(double startAngRad,
double angSpanRad,
double angRad)
startAngRad - An angle, in radians.angSpanRad - An angular span, >= 0.0, in radians.angRad - An angle, in radians.public static boolean isNaNOrInfinite(float value)
public static boolean isNaNOrInfinite(double value)
public static double abs(double a)
public static float abs(float a)
public static long abs(long a)
public static double copySign(double magnitude,
double sign)
public static float copySign(float magnitude,
float sign)
public static double IEEEremainder(double f1,
double f2)
public static double max(double a,
double b)
public static float max(float a,
float b)
public static int max(int a,
int b)
public static long max(long a,
long b)
public static double min(double a,
double b)
public static float min(float a,
float b)
public static int min(int a,
int b)
public static long min(long a,
long b)
public static double nextAfter(double start,
double direction)
public static float nextAfter(float start,
float direction)
public static double nextUp(double d)
public static float nextUp(float f)
public static double random()
public static double rint(double a)
public static double scalb(double d,
int scaleFactor)
public static float scalb(float f,
int scaleFactor)
public static double signum(double d)
public static float signum(float f)
public static double ulp(double d)
public static float ulp(float f)
Copyright © 2015. All rights reserved.