public final class NumberTools
extends java.lang.Object
bounce(float)
), or even can yield a performance boost (compare
zigzag(float)
to using modulus to accomplish the same results). The bit manipulation has good performance on
GWT thanks to JS typed arrays, which are well-supported now across all recent browsers and have fallbacks in GWT in
the unlikely event of a browser not supporting them.Constructor and Description |
---|
NumberTools() |
Modifier and Type | Method and Description |
---|---|
static double |
acos_(double x)
Inverse cosine function (arccos) but with output measured in turns instead of radians.
|
static float |
acos_(float x)
Inverse cosine function (arccos) but with output measured in turns instead of radians.
|
static double |
acos(double x)
Arc cosine approximation with very low error, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 35's algorithm, which is the fastest
and least precise).
|
static float |
acos(float x)
Arc cosine approximation with very low error, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 35's algorithm, which is the fastest
and least precise).
|
static double |
asin_(double x)
Inverse sine function (arcsine) but with output measured in turns instead of radians.
|
static float |
asin_(float x)
Inverse sine function (arcsine) but with output measured in turns instead of radians.
|
static double |
asin(double x)
Arc sine approximation with very low error, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 35's algorithm, which is the fastest
and least precise).
|
static float |
asin(float x)
Arc sine approximation with very low error, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 35's algorithm, which is the fastest
and least precise).
|
static double |
atan(double i)
Arc tangent approximation with very low error, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 9's algorithm, which is the
second-fastest and second-least precise).
|
static float |
atan(float i)
Arc tangent approximation with very low error, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 9's algorithm, which is the
second-fastest and second-least precise).
|
static double |
atan2_(double y,
double x)
Altered-range approximation of the frequently-used trigonometric method atan2, taking y and x positions as
doubles and returning an angle measured in turns from 0.0 to 1.0 (inclusive), with one cycle over the range
equivalent to 360 degrees or 2PI radians.
|
static float |
atan2_(float y,
float x)
Altered-range approximation of the frequently-used trigonometric method atan2, taking y and x positions as floats
and returning an angle measured in turns from 0.0f to 1.0f, with one cycle over the range equivalent to 360
degrees or 2PI radians.
|
static double |
atan2(double y,
double x)
Close approximation of the frequently-used trigonometric method atan2, with higher precision than libGDX's atan2
approximation.
|
static float |
atan2(float y,
float x)
Close approximation of the frequently-used trigonometric method atan2, with higher precision than libGDX's atan2
approximation.
|
static double |
atan2Degrees(double y,
double x)
Close approximation of the frequently-used trigonometric method atan2 measured in degrees, with higher precision
than libGDX's atan2 approximation.
|
static float |
atan2Degrees(float y,
float x)
Close approximation of the frequently-used trigonometric method atan2 measured in degrees, with higher precision
than libGDX's atan2 approximation.
|
static double |
atan2Degrees360(double y,
double x)
Altered-range approximation of the frequently-used trigonometric method atan2, taking y and x positions as
doubles and returning an angle measured in turns from 0.0 to 360.0 (inclusive), with one cycle over the range
equivalent to 2PI radians or 1 turn.
|
static float |
atan2Degrees360(float y,
float x)
Altered-range approximation of the frequently-used trigonometric method atan2, taking y and x positions as
floats and returning an angle measured in turns from 0.0 to 360.0 (inclusive), with one cycle over the range
equivalent to 2PI radians or 1 turn.
|
static double |
atanDegrees(double i)
Arc tangent approximation measured in degrees, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 9's algorithm, which is the
second-fastest and second-least precise).
|
static float |
atanDegrees(float i)
Arc tangent approximation measured in degrees, using an algorithm from the 1955 research study
"Approximations for Digital Computers," by RAND Corporation (this is sheet 9's algorithm, which is the
second-fastest and second-least precise).
|
static double |
bounce(double value)
Very limited-use; takes any double and produces a double in the -1.0 to 1.0 range, with similar inputs producing
close to a consistent rate of up and down through the range.
|
static float |
bounce(float value)
Very limited-use; takes any double and produces a double in the -1.0 to 1.0 range, with similar inputs producing
close to a consistent rate of up and down through the range.
|
static double |
bounce(int valueLow,
int valueHigh)
Very limited-use; takes the significand bits of a double, represented as a pair of ints
valueLow and
valueHigh , using all bits in valueLow and the least-significant 20 bits of valueHigh, and
produces a double in the -1.0 to 1.0 range, with similar inputs producing close to a consistent rate of up and
down through the range. |
static double |
bounce(long value)
Very limited-use; takes the significand bits of a double, represented as a long of which this uses 52 bits, and
produces a double in the -1.0 to 1.0 range, with similar inputs producing close to a consistent rate of up and
down through the range.
|
static double |
cos_(double turns)
A variation on
Math.cos(double) that takes its input as a fraction of a turn instead of in radians; one
turn is equal to 360 degrees or two*PI radians. |
static float |
cos_(float turns)
A variation on
Math.cos(double) that takes its input as a fraction of a turn instead of in radians (it
also takes and returns a float); one turn is equal to 360 degrees or two*PI radians. |
static double |
cos(double radians)
A fairly-close approximation of
Math.cos(double) that can be significantly faster (between 8x and 80x
faster cos() calls in benchmarking; if you have access to libGDX you should consider its sometimes-more-precise
and sometimes-faster MathUtils.cos() method. |
static float |
cos(float radians)
A fairly-close approximation of
Math.cos(double) that can be significantly faster (between 8x and 80x
faster cos() calls in benchmarking, and both takes and returns floats; if you have access to libGDX you should
consider its more-precise and sometimes-faster MathUtils.cos() method. |
static float |
cosDegrees(float degrees)
A fairly-close approximation of
Math.cos(double) that can be significantly faster (between 8x and 80x
faster cos() calls in benchmarking, and both takes and returns floats; if you have access to libGDX, you should
consider its more-precise and sometimes-faster MathUtils.cosDeg() method. |
static int |
doubleToHighIntBits(double value)
Converts
value to a long and gets the upper 32 bits of that long, as an int. |
static long |
doubleToLongBits(double value)
Identical to
Double.doubleToLongBits(double) on desktop; optimized on GWT. |
static int |
doubleToLowIntBits(double value)
Converts
value to a long and gets the lower 32 bits of that long, as an int. |
static int |
doubleToMixedIntBits(double value)
Converts
value to a long and gets the XOR of its upper and lower 32-bit sections. |
static long |
doubleToRawLongBits(double value)
Identical to
Double.doubleToLongBits(double) on desktop (note, not
Double.doubleToRawLongBits(double) ); optimized on GWT. |
static int |
floatToIntBits(float value)
Identical to
Float.floatToIntBits(float) on desktop; optimized on GWT. |
static int |
floatToRawIntBits(float value)
Identical to
Float.floatToIntBits(float) on desktop (note, not Float.floatToRawIntBits(float) );
optimized on GWT. |
static int |
floatToReversedIntBits(float value)
Gets the bit representation of the given float
value , but with reversed byte order. |
static double |
formCurvedDouble(long start)
A different kind of determine-like method that expects to be given a random long and produces a random double
with a curved distribution that centers on 0 (where it has a bias) and can (rarely) approach -1f and 1f.
|
static double |
formCurvedDoubleTight(long start)
A different kind of determine-like method that expects to be given a random long and produces a random double
with a curved distribution that centers on 0 (where it has a bias) and can (rarely) approach 0.0 and 1.0.
|
static float |
formCurvedFloat(int start)
A different kind of determine-like method that expects to be given a random int and produces a random float with
a curved distribution that centers on 0 (where it has a bias) and can (rarely) approach -1f and 1f.
|
static float |
formCurvedFloat(int start1,
int start2)
A different kind of determine-like method that expects to be given random ints and produces a random float with
a curved distribution that centers on 0 (where it has a bias) and can (rarely) approach -1f and 1f.
|
static float |
formCurvedFloat(long start)
A different kind of determine-like method that expects to be given a random long and produces a random float with
a curved distribution that centers on 0 (where it has a bias) and can (rarely) approach -1f and 1f.
|
static double |
formDouble(long seed)
Given a long as a seed, this uses its least-significant 52 bits to produce a double between 0 (inclusive) and 1
(exclusive).
|
static float |
formFloat(int seed)
Given an int as a seed, this uses its least-significant 23 bits to produce a float between 0f (inclusive) and 1f
(exclusive).
|
static double |
formSignedDouble(long seed)
Given a long as a seed, this uses its least-significant 52 bits to produce a double between -1 (inclusive) and 1
(exclusive).
|
static float |
formSignedFloat(int seed)
Given an int as a seed, this uses its least-significant 23 bits to produce a float between -1f (inclusive) and 1f
(exclusive).
|
static byte |
getSelectedByte(double value,
int whichByte)
Gets an 8-bit section of the given double
value , using whichByte to select whether this should
return byte 0 (least significant), 1, 2, and so on up to 7 (most significant). |
static byte |
getSelectedByte(float value,
int whichByte)
Gets an 8-bit section of the given float
value , using whichByte to select whether this should
return byte 0 (least significant), 1, 2, or 3 (most significant). |
static float |
intBitsToFloat(int bits)
Identical to
Float.intBitsToFloat(int) on desktop; optimized on GWT. |
static double |
longBitsToDouble(long bits)
Identical to
Double.longBitsToDouble(long) on desktop; optimized on GWT. |
static int |
lowestOneBit(int num)
Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in
the specified int value.
|
static long |
lowestOneBit(long num)
Returns an long value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in
the specified long value.
|
static double |
randomDouble(long seed)
Generates a pseudo-random double between 0.0 (inclusive) and 1.0 (exclusive) using the given long seed, passing
it once through the (decent-quality and very fast)
ThrustAltRNG algorithm. |
static float |
randomFloat(long seed)
Generates a pseudo-random float between 0f (inclusive) and 1f (exclusive) using the given long seed, passing it
once through the (decent-quality and very fast)
ThrustAltRNG algorithm. |
static float |
randomFloatCurved(long seed)
Generates a pseudo-random double between -1.0 (exclusive) and 1.0 (exclusive) with a distribution that has a
strong central bias (around 0.0).
|
static double |
randomSignedDouble(long seed)
Generates a pseudo-random double between -1.0 (inclusive) and 1.0 (exclusive) using the given long seed, passing
it once through the (decent-quality and very fast)
ThrustAltRNG algorithm. |
static float |
randomSignedFloat(long seed)
Generates a pseudo-random float between -1f (inclusive) and 1f (exclusive) using the given long seed, passing
it once through the (decent-quality and very fast)
ThrustAltRNG algorithm. |
static float |
reversedIntBitsToFloat(int bits)
Reverses the byte order of
bits and converts that to a float. |
static double |
setExponent(double value,
int exponentBits)
Makes a modified version of value that uses the specified bits (up to 12) for its exponent and sign.
|
static double |
setSelectedByte(double value,
int whichByte,
byte newValue)
Like
getSelectedByte(double, int) , this sets the byte at a selected position in the int representation of
a double, then returns the double produced by the bit change. |
static float |
setSelectedByte(float value,
int whichByte,
byte newValue)
Like
getSelectedByte(float, int) , this sets the byte at a selected position in the int representation of
a float, then returns the float produced by the bit change. |
static double |
sin_(double turns)
A variation on
Math.sin(double) that takes its input as a fraction of a turn instead of in radians; one
turn is equal to 360 degrees or two*PI radians. |
static float |
sin_(float turns)
A variation on
Math.sin(double) that takes its input as a fraction of a turn instead of in radians (it
also takes and returns a float); one turn is equal to 360 degrees or two*PI radians. |
static double |
sin(double radians)
A fairly-close approximation of
Math.sin(double) that can be significantly faster (between 8x and 80x
faster sin() calls in benchmarking; if you have access to libGDX you should consider its sometimes-more-precise
and sometimes-faster MathUtils.sin() method. |
static float |
sin(float radians)
A fairly-close approximation of
Math.sin(double) that can be significantly faster (between 8x and 80x
faster sin() calls in benchmarking, and both takes and returns floats; if you have access to libGDX you should
consider its more-precise and sometimes-faster MathUtils.sin() method. |
static float |
sinDegrees(float degrees)
A fairly-close approximation of
Math.sin(double) that can be significantly faster (between 8x and 80x
faster sin() calls in benchmarking, and both takes and returns floats; if you have access to libGDX, you should
consider its more-precise and sometimes-faster MathUtils.sinDeg() method. |
static double |
sway(double value)
Very similar to
sin_(double) with half frequency, or Math.sin(double) with Math.PI
frequency, but optimized (and shaped) a little differently. |
static float |
sway(float value)
Very similar to
sin_(float) with half frequency, or Math.sin(double) with Math.PI
frequency, but optimized (and shaped) a little differently. |
static float |
swayAngleRandomized(long seed,
float value)
A 1D "noise" method that produces smooth transitions like
sway(float) , but also wrapping around at pi *
2 so this can be used to get smoothly-changing random angles. |
static double |
swayCubic(double value)
Very similar to
sin_(double) with half frequency, or Math.sin(double) with Math.PI
frequency, but optimized (and shaped) a little differently. |
static float |
swayCubic(float value)
Very similar to
sin_(float) with half frequency, or Math.sin(double) with Math.PI
frequency, but optimized (and shaped) a little differently. |
static double |
swayRandomized(int seed,
double value)
A variant on
swayRandomized(long, double) that takes an int seed instead of a long, and is optimized for
usage on GWT. |
static float |
swayRandomized(int seed,
float value)
A variant on
swayRandomized(long, float) that takes an int seed instead of a long, and is optimized for
usage on GWT. |
static double |
swayRandomized(long seed,
double value)
A mix of the smooth transitions of
sway(double) with (seeded) random peaks and valleys between -1.0 and
1.0 (both exclusive). |
static float |
swayRandomized(long seed,
float value)
A mix of the smooth transitions of
sway(float) with (seeded) random peaks and valleys between -1f and
1f (both exclusive). |
static double |
swayTight(double value)
Limited-use; takes any double and produces a double in the 0.0 to 1.0 range, with a graph of input to output that
looks much like a sine wave, curving to have a flat slope when given an integer input and a steep slope when the
input is halfway between two integers, smoothly curving at any points between those extremes.
|
static float |
swayTight(float value)
Limited-use; takes any float and produces a float in the 0f to 1f range, with a graph of input to output that
looks much like a sine wave, curving to have a flat slope when given an integer input and a steep slope when the
input is halfway between two integers, smoothly curving at any points between those extremes.
|
static double |
zigzag(double value)
Limited-use; takes any double and produces a double in the -1.0 to 1.0 range, with similar inputs producing
close to a consistent rate of up and down through the range.
|
static float |
zigzag(float value)
Limited-use; takes any float and produces a float in the -1f to 1f range, with similar inputs producing
close to a consistent rate of up and down through the range.
|
public static long doubleToLongBits(double value)
Double.doubleToLongBits(double)
on desktop; optimized on GWT. When compiling to JS via GWT,
there is no way to distinguish NaN values with different bits but that are still NaN, so this doesn't try to
somehow permit that. Uses JS typed arrays on GWT, which are well-supported now across all recent browsers and
have fallbacks in GWT in the unlikely event of a browser not supporting them. JS typed arrays support double, but
not long, so this needs to compose a long from two ints, which means the double-to/from-long conversions aren't
as fast as float-to/from-int conversions.value
- a double
floating-point number.public static long doubleToRawLongBits(double value)
Double.doubleToLongBits(double)
on desktop (note, not
Double.doubleToRawLongBits(double)
); optimized on GWT. When compiling to JS via GWT, there is no way to
distinguish NaN values with different bits but that are still NaN, so this doesn't try to somehow permit that.
Uses JS typed arrays on GWT, which are well-supported now across all recent browsers and have fallbacks in GWT in
the unlikely event of a browser not supporting them. JS typed arrays support double, but not long, so this needs
to compose a long from two ints, which means the double-to/from-long conversions aren't as fast as
float-to/from-int conversions.value
- a double
floating-point number.public static double longBitsToDouble(long bits)
Double.longBitsToDouble(long)
on desktop; optimized on GWT. Uses JS typed arrays on GWT,
which are well-supported now across all recent browsers and have fallbacks in GWT in the unlikely event of a
browser not supporting them. JS typed arrays support double, but not long, so this needs to compose a long from
two ints, which means the double-to/from-long conversions aren't as fast as float-to/from-int conversions.bits
- a long.double
floating-point value with the same bit pattern.public static int doubleToLowIntBits(double value)
value
to a long and gets the lower 32 bits of that long, as an int.value
- a double
precision floating-point number.public static int doubleToHighIntBits(double value)
value
to a long and gets the upper 32 bits of that long, as an int.value
- a double
precision floating-point number.public static int doubleToMixedIntBits(double value)
value
to a long and gets the XOR of its upper and lower 32-bit sections. Useful for numerical
code where a 64-bit double needs to be reduced to a 32-bit value with some hope of keeping different doubles
giving different ints.value
- a double
precision floating-point number.public static double setExponent(double value, int exponentBits)
exponentBits |= 0x800
to set the sign bit to negative, or exponentBits &= 0x7ff
for positive.value
- a double that will have its sign and exponent set to the specified bitsexponentBits
- the bits to use for the sign and exponent section of the returned modification of valuepublic static byte getSelectedByte(double value, int whichByte)
value
, using whichByte
to select whether this should
return byte 0 (least significant), 1, 2, and so on up to 7 (most significant).value
- a floatwhichByte
- an int that will be used to select the byte to take from value (any int is allowed, only the bottom 3 bits are used to select)public static double setSelectedByte(double value, int whichByte, byte newValue)
getSelectedByte(double, int)
, this sets the byte at a selected position in the int representation of
a double, then returns the double produced by the bit change. Uses whichByte
to select whether this should
set byte 0 (least significant), 1, 2, and so on up to 7 (most significant). newValue
is a byte.value
- a doublewhichByte
- an int that will be used to select the byte to take from value (any int is allowed, only the bottom 3 bits are used to select)newValue
- a byte that will be placed into the returned double's bits at the selected positionpublic static double bounce(double value)
value
- any doublepublic static float bounce(float value)
value
- any doublepublic static double bounce(long value)
value
- any long; only the lower 52 bits will be usedpublic static double bounce(int valueLow, int valueHigh)
valueLow
and
valueHigh
, using all bits in valueLow and the least-significant 20 bits of valueHigh, and
produces a double in the -1.0 to 1.0 range, with similar inputs producing close to a consistent rate of up and
down through the range. This is meant for noise, where it may be useful to limit the amount of change between
nearby points' noise values and prevent sudden "jumps" in noise value.valueLow
- any int; all bits will be used as the less-significant bits of the significandvalueHigh
- any int; only the bottom 20 bits will be used as the more-significant bits of the significandpublic static double zigzag(double value)
bounce(double)
, but unlike bounce() this will maintain a continuous rate regardless of
the magnitude of its input. An input of any even number should produce something very close to -1.0, any odd
number should produce something very close to 1.0, and any number halfway between two incremental integers (like
8.5 or -10.5) should produce 0.0 or a very small fraction. This method is closely related to
sway(double)
, which will smoothly curve its output to produce more values that are close to -1 or 1.value
- any doublepublic static float zigzag(float value)
bounce(float)
, but unlike bounce() this will maintain a continuous rate regardless of
the magnitude of its input. An input of any even number should produce something very close to -1f, any odd
number should produce something very close to 1f, and any number halfway between two incremental integers (like
8.5f or -10.5f) should produce 0f or a very small fraction. This method is closely related to
sway(float)
, which will smoothly curve its output to produce more values that are close to -1 or 1.value
- any floatpublic static double sway(double value)
sin_(double)
with half frequency, or Math.sin(double)
with Math.PI
frequency, but optimized (and shaped) a little differently. This looks like a squished sine wave when graphed,
and is essentially just interpolating between each pair of odd and even inputs using what FastNoise calls
QUINTIC
interpolation. This interpolation is slightly flatter at peaks and valleys than a sine wave is.
value
- any double other than NaN or infinite values; extremely large values can't work properlypublic static float sway(float value)
sin_(float)
with half frequency, or Math.sin(double)
with Math.PI
frequency, but optimized (and shaped) a little differently. This looks like a squished sine wave when graphed,
and is essentially just interpolating between each pair of odd and even inputs using what FastNoise calls
QUINTIC
interpolation. This interpolation is slightly flatter at peaks and valleys than a sine wave is.
value
- any float other than NaN or infinite values; extremely large values can't work properlypublic static double swayCubic(double value)
sin_(double)
with half frequency, or Math.sin(double)
with Math.PI
frequency, but optimized (and shaped) a little differently. This looks like a squished sine wave when graphed,
and is essentially just interpolating between each pair of odd and even inputs using what FastNoise calls
HERMITE
interpolation. This interpolation is rounder at peaks and valleys than a sine wave is; it is
also called smoothstep
in GLSL, and is called Cubic here because it gets the third power of a value.
value
- any double other than NaN or infinite values; extremely large values can't work properlypublic static float swayCubic(float value)
sin_(float)
with half frequency, or Math.sin(double)
with Math.PI
frequency, but optimized (and shaped) a little differently. This looks like a squished sine wave when graphed,
and is essentially just interpolating between each pair of odd and even inputs using what FastNoise calls
HERMITE
interpolation. This interpolation is rounder at peaks and valleys than a sine wave is; it is
also called smoothstep
in GLSL, and is called Cubic here because it gets the third power of a value.
value
- any float other than NaN or infinite values; extremely large values can't work properlypublic static float swayTight(float value)
bounce(float)
and zigzag(float)
, but unlike bounce() this will not change its
frequency of returning max or min values, regardless of the magnitude of its input (as long as there is enough
floating-point precision to represent changes smaller than 1f), and unlike zigzag() this will smooth its path.
An input of any even number should produce something very close to 0f, any odd number should produce something
very close to 1f, and any number halfway between two incremental integers (like 8.5f or -10.5f) should produce
0.5f. In the (unlikely) event that this is given a float that is too large to represent many or any non-integer
values, this will simply return 0f or 1f. This version is called "Tight" because its range is tighter than
sway(float)
.value
- any float other than NaN or infinite values; extremely large values can't work properlypublic static double swayTight(double value)
bounce(double)
and zigzag(double)
, but unlike bounce() this will not change its
frequency of returning max or min values, regardless of the magnitude of its input (as long as there is enough
floating-point precision to represent changes smaller than 1.0), and unlike zigzag() this will smooth its path.
An input of any even number should produce something very close to 0.0, any odd number should produce something
very close to 1.0, and any number halfway between two incremental integers (like 8.5 or -10.5) should produce
0.5f. In the (unlikely) event that this is given a double that is too large to represent many or any non-integer
values, this will simply return 0.0 or 1.0. This version is called "Tight" because its range is tighter than
sway(double)
.value
- any double other than NaN or infinite values; extremely large values can't work properlypublic static double swayRandomized(long seed, double value)
sway(double)
with (seeded) random peaks and valleys between -1.0 and
1.0 (both exclusive). The pattern this will produces will be completely different if the seed changes, and it is
suitable for 1D noise. Uses a simple method of cubic interpolation between random values, where a random value is
used without modification when given an integer for value
. Note that this uses a different type of
interpolation than sway(double)
, which uses quintic (this causes swayRandomized() to produce more
outputs in the mid-range and less at extremes; it is also slightly faster and simpler).
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 1.0, with direction changes at integer inputspublic static float swayRandomized(long seed, float value)
sway(float)
with (seeded) random peaks and valleys between -1f and
1f (both exclusive). The pattern this will produces will be completely different if the seed changes, and it is
suitable for 1D noise. Uses a simple method of cubic interpolation between random values, where a random value is
used without modification when given an integer for value
. Note that this uses a different type of
interpolation than sway(float)
, which uses quintic (this causes swayRandomized() to produce more
outputs in the mid-range and less at extremes; it is also slightly faster and simpler).
seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputspublic static double swayRandomized(int seed, double value)
swayRandomized(long, double)
that takes an int seed instead of a long, and is optimized for
usage on GWT. Like the version with a long seed, this uses cubic interpolation between random peak or valley
points; only the method of generating those random peaks and valleys has changed.seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a double that typically changes slowly, by less than 2.0, with direction changes at integer inputspublic static float swayRandomized(int seed, float value)
swayRandomized(long, float)
that takes an int seed instead of a long, and is optimized for
usage on GWT. Like the version with a long seed, this uses cubic interpolation between random peak or valley
points; only the method of generating those random peaks and valleys has changed.seed
- an int seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 2.0, with direction changes at integer inputspublic static float swayAngleRandomized(long seed, float value)
sway(float)
, but also wrapping around at pi *
2 so this can be used to get smoothly-changing random angles. Has (seeded) random peaks and valleys where it
slows its range of change, but can return any value from 0 to 6.283185307179586f, or pi * 2. The pattern this
will produces will be completely different if the seed changes, and the value is expected to be something other
than an angle, like time. Uses a simple method of cubic interpolation between random values, where a random value
is used without modification when given an integer for value
. Note that this uses a different type of
interpolation than sway(float)
, which uses quintic (this causes swayAngleRandomized() to be slightly
faster and simpler).seed
- a long seed that will determine the pattern of peaks and valleys this will generate as value changes; this should not change between callsvalue
- a float that typically changes slowly, by less than 1.0, with possible direction changes at integer inputspublic static int floatToIntBits(float value)
Float.floatToIntBits(float)
on desktop; optimized on GWT. Uses JS typed arrays on GWT, which
are well-supported now across all recent browsers and have fallbacks in GWT in the unlikely event of a browser
not supporting them.value
- a floating-point number.public static int floatToRawIntBits(float value)
Float.floatToIntBits(float)
on desktop (note, not Float.floatToRawIntBits(float)
);
optimized on GWT. When compiling to JS via GWT, there is no way to distinguish NaN values with different bits but
that are still NaN, so this doesn't try to somehow permit that. Uses JS typed arrays on GWT, which are
well-supported now across all recent browsers and have fallbacks in GWT in the unlikely event of a browser not
supporting them.value
- a floating-point number.public static int floatToReversedIntBits(float value)
value
, but with reversed byte order. On desktop, this is
equivalent to calling Integer.reverseBytes(Float.floatToIntBits(value))
, but it is implemented using
typed arrays on GWT.value
- a floating-point numberpublic static float reversedIntBitsToFloat(int bits)
bits
and converts that to a float. On desktop, this is
equivalent to calling Float.intBitsToFloat(Integer.reverseBytes(bits))
, but it is implemented using
typed arrays on GWT.bits
- an integerfloat
floating-point value with the given bits using their byte order reversed from normal.public static float intBitsToFloat(int bits)
Float.intBitsToFloat(int)
on desktop; optimized on GWT. Uses JS typed arrays on GWT, which
are well-supported now across all recent browsers and have fallbacks in GWT in the unlikely event of a browser
not supporting them.bits
- an integer.float
floating-point value with the same bit pattern.public static byte getSelectedByte(float value, int whichByte)
value
, using whichByte
to select whether this should
return byte 0 (least significant), 1, 2, or 3 (most significant).value
- a floatwhichByte
- an int that will be used to select the byte to take from value (any int is allowed, only the bottom 2 bits are used to select)public static float setSelectedByte(float value, int whichByte, byte newValue)
getSelectedByte(float, int)
, this sets the byte at a selected position in the int representation of
a float, then returns the float produced by the bit change. Uses whichByte
to select whether this should
set byte 0 (least significant), 1, 2, or 3 (most significant). newValue
is a byte.value
- a floatwhichByte
- an int that will be used to select the byte to take from value (any int is allowed, only the bottom 2 bits are used to select)newValue
- a byte that will be placed into the returned float's bits at the selected positionpublic static double randomDouble(long seed)
ThrustAltRNG
algorithm.
NumberTools.randomDouble(++seed)
for an optimal period of 2 to the 64 when
repeatedly called, but NumberTools.randomDouble(seed += ODD_LONG)
will also work just fine if ODD_LONG is
any odd-number long, positive or negative.seed
- any long to be used as a seedpublic static double randomSignedDouble(long seed)
ThrustAltRNG
algorithm.
NumberTools.randomSignedDouble(++seed)
for an optimal period of 2 to the 64
when repeatedly called, but NumberTools.randomSignedDouble(seed += ODD_LONG)
will also work just fine if
ODD_LONG is any odd-number long, positive or negative.seed
- any long to be used as a seedpublic static float randomFloat(long seed)
ThrustAltRNG
algorithm.
NumberTools.randomFloat(++seed)
for an optimal period of 2 to the 64 when
repeatedly called, but NumberTools.randomFloat(seed += ODD_LONG)
will also work just fine if ODD_LONG is
any odd-number long, positive or negative.seed
- any long to be used as a seedpublic static float randomSignedFloat(long seed)
ThrustAltRNG
algorithm. This can be useful as a
multiplier that has approximately equal likelihood of changing or leaving the sign of its multiplicand, and won't
make the result larger (more significant) but will usually make it closer to 0.
NumberTools.randomDouble(++seed)
for an optimal period of 2 to the 64 when
repeatedly called, but NumberTools.randomDouble(seed += ODD_LONG)
will also work just fine if ODD_LONG is
any odd-number long, positive or negative.seed
- any long to be used as a seedpublic static float randomFloatCurved(long seed)
ThrustAltRNG
algorithm. This produces a pseudo-random long, which this simply passes to
formCurvedFloat(long)
, since it is already well-suited to generating a curved distribution.
NumberTools.randomFloatCurved(++seed)
for an optimal period of 2 to the 64
when repeatedly called, but NumberTools.randomFloatCurved(seed += ODD_LONG)
will also work just fine if
ODD_LONG is any odd-number long, positive or negative.seed
- any int to be used as a seedpublic static float formFloat(int seed)
seed
- an int; only the bottom 23 bits will be usedpublic static float formSignedFloat(int seed)
seed
- an int; only the bottom 23 bits will be usedpublic static double formDouble(long seed)
seed
- a long; only the bottom 52 bits will be usedpublic static double formSignedDouble(long seed)
seed
- a long; only the bottom 52 bits will be usedpublic static double formCurvedDouble(long start)
start
- a long, usually random, such as one produced by any RandomnessSource; all bits will be usedpublic static double formCurvedDoubleTight(long start)
start
- a long, usually random, such as one produced by any RandomnessSource; all bits will be usedpublic static float formCurvedFloat(long start)
start
- a long, usually random, such as one produced by any RandomnessSourcepublic static float formCurvedFloat(int start1, int start2)
start1
- an int usually random, such as one produced by any RandomnessSourcestart2
- an int usually random, such as one produced by any RandomnessSourcepublic static float formCurvedFloat(int start)
start
- an int, usually random, such as one produced by any RandomnessSourcepublic static int lowestOneBit(int num)
Integer.lowestOneBit(int)
, but super-sourced to act correctly on GWT. If you have GWT as a
target and do bit manipulation work, double-check everything! An int can be higher than Integer.MAX_VALUE
or lower than Integer.MIN_VALUE
on GWT, without actually being a long (internally it's a double). This
is especially relevant for the overload of this method that takes and returns a long;
Long.lowestOneBit(long)
does not provide correct results for certain inputs on GWT, such as
-17592186044416L, which it mysteriously returns 0L on, so you should use lowestOneBit(long)
.num
- the value whose lowest one bit is to be computedpublic static long lowestOneBit(long num)
Long.lowestOneBit(long)
, but super-sourced to act correctly on GWT. If you have GWT as a
target and do bit manipulation work, double-check everything! An int can be higher than Integer.MAX_VALUE
or lower than Integer.MIN_VALUE
on GWT, without actually being a long (internally it's a double). This
is especially relevant for this overload (for longs more so than for ints); Long.lowestOneBit(long)
does
not provide correct results for certain inputs on GWT, such as -17592186044416L, which it mysteriously returns 0L
on, so you should use this method.num
- the value whose lowest one bit is to be computedpublic static double sin(double radians)
Math.sin(double)
that can be significantly faster (between 8x and 80x
faster sin() calls in benchmarking; if you have access to libGDX you should consider its sometimes-more-precise
and sometimes-faster MathUtils.sin() method. Because this method doesn't rely on a
lookup table, where libGDX's MathUtils does, applications that have a bottleneck on memory may perform better
with this method than with MathUtils. Takes the same arguments Math.sin() does, so one angle in radians,
which may technically be any double (but this will lose precision on fairly large doubles, such as those that are
larger than Long.MAX_VALUE
, because those doubles themselves will lose precision at that scale). This
is closely related to sway(double)
, but the shape of the output when graphed is almost identical to
sin(). The difference between the result of this method and Math.sin(double)
should be under 0.0011 at
all points between -pi and pi, with an average difference of about 0.0005; not all points have been checked for
potentially higher errors, though.
sin(float)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
radians
- an angle in radians as a double, often from 0 to pi * 2, though not required to be.public static double cos(double radians)
Math.cos(double)
that can be significantly faster (between 8x and 80x
faster cos() calls in benchmarking; if you have access to libGDX you should consider its sometimes-more-precise
and sometimes-faster MathUtils.cos() method. Because this method doesn't rely on a
lookup table, where libGDX's MathUtils does, applications that have a bottleneck on memory may perform better
with this method than with MathUtils. Takes the same arguments Math.cos() does, so one angle in radians,
which may technically be any double (but this will lose precision on fairly large doubles, such as those that are
larger than Long.MAX_VALUE
, because those doubles themselves will lose precision at that scale). This
is closely related to sway(double)
, but the shape of the output when graphed is almost identical to
cos(). The difference between the result of this method and Math.cos(double)
should be under 0.0011 at
all points between -pi and pi, with an average difference of about 0.0005; not all points have been checked for
potentially higher errors, though.
cos(float)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
radians
- an angle in radians as a double, often from 0 to pi * 2, though not required to be.public static float sin(float radians)
Math.sin(double)
that can be significantly faster (between 8x and 80x
faster sin() calls in benchmarking, and both takes and returns floats; if you have access to libGDX you should
consider its more-precise and sometimes-faster MathUtils.sin() method. Because this method doesn't rely on a
lookup table, where libGDX's MathUtils does, applications that have a bottleneck on memory may perform better
with this method than with MathUtils. Takes the same arguments Math.sin() does, so one angle in radians,
which may technically be any float (but this will lose precision on fairly large floats, such as those that are
larger than Integer.MAX_VALUE
, because those floats themselves will lose precision at that scale). This
is closely related to sway(float)
, but the shape of the output when graphed is almost identical to
sin(). The difference between the result of this method and Math.sin(double)
should be under 0.0011 at
all points between -pi and pi, with an average difference of about 0.0005; not all points have been checked for
potentially higher errors, though.
sin(double)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
radians
- an angle in radians as a float, often from 0 to pi * 2, though not required to be.public static float cos(float radians)
Math.cos(double)
that can be significantly faster (between 8x and 80x
faster cos() calls in benchmarking, and both takes and returns floats; if you have access to libGDX you should
consider its more-precise and sometimes-faster MathUtils.cos() method. Because this method doesn't rely on a
lookup table, where libGDX's MathUtils does, applications that have a bottleneck on memory may perform better
with this method than with MathUtils. Takes the same arguments Math.cos() does, so one angle in radians,
which may technically be any float (but this will lose precision on fairly large floats, such as those that are
larger than Integer.MAX_VALUE
, because those floats themselves will lose precision at that scale). This
is closely related to sway(float)
, but the shape of the output when graphed is almost identical to
cos(). The difference between the result of this method and Math.cos(double)
should be under 0.0011 at
all points between -pi and pi, with an average difference of about 0.0005; not all points have been checked for
potentially higher errors, though.
cos(double)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
radians
- an angle in radians as a float, often from 0 to pi * 2, though not required to be.public static float sinDegrees(float degrees)
Math.sin(double)
that can be significantly faster (between 8x and 80x
faster sin() calls in benchmarking, and both takes and returns floats; if you have access to libGDX, you should
consider its more-precise and sometimes-faster MathUtils.sinDeg() method. Because this method doesn't rely on a
lookup table, where libGDX's MathUtils does, applications that have a bottleneck on memory may perform better
with this method than with MathUtils. Takes one angle in degrees,
which may technically be any float (but this will lose precision on fairly large floats, such as those that are
larger than Integer.MAX_VALUE
, because those floats themselves will lose precision at that scale). This
is closely related to sway(float)
, but the shape of the output when graphed is almost identical to
sin(). The difference between the result of this method and Math.sin(double)
should be under 0.0011 at
all points between -360 and 360, with an average difference of about 0.0005; not all points have been checked for
potentially higher errors, though.
sin(double)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
degrees
- an angle in degrees as a float, often from 0 to 360, though not required to be.public static float cosDegrees(float degrees)
Math.cos(double)
that can be significantly faster (between 8x and 80x
faster cos() calls in benchmarking, and both takes and returns floats; if you have access to libGDX, you should
consider its more-precise and sometimes-faster MathUtils.cosDeg() method. Because this method doesn't rely on a
lookup table, where libGDX's MathUtils does, applications that have a bottleneck on memory may perform better
with this method than with MathUtils. Takes one angle in degrees,
which may technically be any float (but this will lose precision on fairly large floats, such as those that are
larger than Integer.MAX_VALUE
, because those floats themselves will lose precision at that scale). This
is closely related to sway(float)
, but the shape of the output when graphed is almost identical to
cos(). The difference between the result of this method and Math.cos(double)
should be under 0.0011 at
all points between -360 and 360, with an average difference of about 0.0005; not all points have been checked for
potentially higher errors, though.
cos(double)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
degrees
- an angle in degrees as a float, often from 0 to pi * 2, though not required to be.public static double sin_(double turns)
Math.sin(double)
that takes its input as a fraction of a turn instead of in radians; one
turn is equal to 360 degrees or two*PI radians. This can be useful as a building block for other measurements;
to make a sine method that takes its input in grad (with 400 grad equal to 360 degrees), you would just divide
the grad value by 400.0 (or multiply it by 0.0025) and pass it to this method. Similarly for binary degrees, also
called brad (with 256 brad equal to 360 degrees), you would divide by 256.0 or multiply by 0.00390625 before
passing that value here. The brad case is especially useful because you can use a byte for any brad values, and
adding up those brad values will wrap correctly (256 brad goes back to 0) while keeping perfect precision for the
results (you still divide by 256.0 when you pass the brad value to this method).
sin_(float)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
turns
- an angle as a fraction of a turn as a double, with 0.5 here equivalent to PI radians in cos(double)
public static double cos_(double turns)
Math.cos(double)
that takes its input as a fraction of a turn instead of in radians; one
turn is equal to 360 degrees or two*PI radians. This can be useful as a building block for other measurements;
to make a cosine method that takes its input in grad (with 400 grad equal to 360 degrees), you would just divide
the grad value by 400.0 (or multiply it by 0.0025) and pass it to this method. Similarly for binary degrees, also
called brad (with 256 brad equal to 360 degrees), you would divide by 256.0 or multiply by 0.00390625 before
passing that value here. The brad case is especially useful because you can use a byte for any brad values, and
adding up those brad values will wrap correctly (256 brad goes back to 0) while keeping perfect precision for the
results (you still divide by 256.0 when you pass the brad value to this method).
cos_(float)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
turns
- an angle as a fraction of a turn as a double, with 0.5 here equivalent to PI radians in cos(double)
public static float sin_(float turns)
Math.sin(double)
that takes its input as a fraction of a turn instead of in radians (it
also takes and returns a float); one turn is equal to 360 degrees or two*PI radians. This can be useful as a
building block for other measurements; to make a sine method that takes its input in grad (with 400 grad equal to
360 degrees), you would just divide the grad value by 400.0 (or multiply it by 0.0025) and pass it to this
method. Similarly for binary degrees, also called brad (with 256 brad equal to 360 degrees), you would divide by
256.0 or multiply by 0.00390625 before passing that value here. The brad case is especially useful because you
can use a byte for any brad values, and adding up those brad values will wrap correctly (256 brad goes back to 0)
while keeping perfect precision for the results (you still divide by 256.0 when you pass the brad value to this
method).
sin_(double)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
turns
- an angle as a fraction of a turn as a float, with 0.5 here equivalent to PI radians in cos(double)
public static float cos_(float turns)
Math.cos(double)
that takes its input as a fraction of a turn instead of in radians (it
also takes and returns a float); one turn is equal to 360 degrees or two*PI radians. This can be useful as a
building block for other measurements; to make a cosine method that takes its input in grad (with 400 grad equal
to 360 degrees), you would just divide the grad value by 400.0 (or multiply it by 0.0025) and pass it to this
method. Similarly for binary degrees, also called brad (with 256 brad equal to 360 degrees), you would divide by
256.0 or multiply by 0.00390625 before passing that value here. The brad case is especially useful because you
can use a byte for any brad values, and adding up those brad values will wrap correctly (256 brad goes back to 0)
while keeping perfect precision for the results (you still divide by 256.0 when you pass the brad value to this
method).
cos_(double)
, so you should
choose based on what type you have as input and/or want to return rather than on quality concerns. Coercion
between float and double takes about as long as this method normally takes to run (or longer), so if you have
floats you should usually use methods that take floats (or return floats, if assigning the result to a float),
and likewise for doubles.
turns
- an angle as a fraction of a turn as a float, with 0.5 here equivalent to PI radians in cos(double)
public static double atan(double i)
Math.atan(double)
,
but is somewhat less precise than Math's implementation.i
- an input to the inverse tangent function; any double is acceptedpublic static float atan(float i)
Math.atan(double)
,
but is somewhat less precise than Math's implementation.i
- an input to the inverse tangent function; any float is acceptedpublic static double atan2(double y, double x)
Math.atan2(double, double)
(roughly 12 ns instead of roughly 62 ns for
Math, on Java 8 HotSpot). It is slightly faster than libGDX' MathUtils approximation of the same method;
MathUtils seems to have worse average error, though.
atan(double)
method, and the small code to make that work as atan2() was worked out from Wikipedia.
atan2_(double, double)
if you don't want a mess converting to degrees or some other
measurement, since that method returns an angle from 0f (equal to 0 degrees) to 1f (equal to 360 degrees). You
can also use atan2Degrees(double, double)
or atan2Degrees360(double, double)
to produce a
result in degrees, either from -180 to 180 or 0 to 360.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static float atan2(float y, float x)
Math.atan2(double, double)
(roughly 12 ns instead of roughly 62 ns for
Math, on Java 8 HotSpot). It is slightly faster than libGDX' MathUtils approximation of the same method;
MathUtils seems to have worse average error, though.
atan(float)
method, and the small code to make that work as atan2() was worked out from Wikipedia.
atan2_(float, float)
if you don't want a mess converting to degrees or some other measurement,
since that method returns an angle from 0f (equal to 0 degrees) to 1f (equal to 360 degrees). You can also use
atan2Degrees(float, float)
or atan2Degrees360(float, float)
to produce a result in degrees,
either from -180 to 180 or 0 to 360.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static double atan2_(double y, double x)
6.2831855f
to change to radians,
or by 360f
to change to degrees. Takes y and x (in that unusual order) as doubles. Will never return a
negative number, which may help avoid costly floating-point modulus when you actually want a positive number.
atan(float)
method, and the small code to make that work as atan2_() was worked out from Wikipedia.
atan2(double, double)
returns an angle in radians and can return negative results, which may
be fine for many tasks; these two methods are extremely close in implementation and speed. There are also
atan2Degrees(double, double)
and atan2Degrees360(double, double)
, which provide an angle in
degrees, either from -180 to 180 or 0 to 360.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static float atan2_(float y, float x)
6.2831855f
to change to radians, or by 360f
to change to degrees. Takes y and x (in that unusual order) as floats. Will never return a negative number, which
may help avoid costly floating-point modulus when you actually want a positive number.
atan(float)
method, and the small code to make that work as atan2_() was worked out from Wikipedia.
atan2(float, float)
returns an angle in radians and can return negative results, which may
be fine for many tasks; these two methods are extremely close in implementation and speed. There are also
atan2Degrees(float, float)
and atan2Degrees360(float, float)
, which provide an angle in
degrees, either from -180 to 180 or 0 to 360.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static double atanDegrees(double i)
Math.atan(double)
,
but is somewhat less precise than Math's implementation. This implementation can return negative or positive
results in degrees.i
- an input to the inverse tangent function; any double is acceptedpublic static float atanDegrees(float i)
Math.atan(double)
,
but is somewhat less precise than Math's implementation. This implementation can return negative or positive
results in degrees.i
- an input to the inverse tangent function; any float is acceptedpublic static double atan2Degrees(double y, double x)
Math.atan2(double, double)
(roughly 12 ns instead of roughly 62 ns for
Math, on Java 8 HotSpot). It is slightly faster than libGDX' MathUtils approximation of the same method;
MathUtils seems to have worse average error, as well.
atan(double)
method, and the small code to make that work as atan2Degrees() was worked out from Wikipedia.
atan2_(double, double)
for a version that returns a measurement as a fraction of a turn, or
atan2(double, double)
for the typical radians. You
can also use atan2Degrees360(double, double)
to produce a result in degrees from 0 to 360.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static float atan2Degrees(float y, float x)
Math.atan2(double, double)
(roughly 12 ns instead of roughly 62 ns for
Math, on Java 8 HotSpot). It is slightly faster than libGDX' MathUtils approximation of the same method;
MathUtils seems to have worse average error, as well.
atan(float)
method, and the small code to make that work as atan2Degrees() was worked out from Wikipedia.
atan2_(float, float)
for a version that returns a measurement as a fraction of a turn, or
atan2(float, float)
for the typical radians. You
can also use atan2Degrees360(float, float)
to produce a result in degrees from 0 to 360.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static double atan2Degrees360(double y, double x)
atan(double)
method, and the small code to make that work as atan2Degrees360() was worked out from Wikipedia.
atan2_(double, double)
for a version that returns a measurement as a fraction of a turn, or
atan2(double, double)
for the typical radians. You
can also use atan2Degrees(double, double)
to produce a result in degrees from -180 to 180.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static float atan2Degrees360(float y, float x)
atan(float)
method, and the small code to make that work as atan2Degrees360() was worked out from Wikipedia.
atan2_(float, float)
for a version that returns a measurement as a fraction of a turn, or
atan2(float, float)
for the typical radians. You
can also use atan2Degrees(float, float)
to produce a result in degrees from -180 to 180.y
- y-component of the point to find the angle towards; note the parameter order is unusual by conventionx
- x-component of the point to find the angle towards; note the parameter order is unusual by conventionpublic static float asin(float x)
Math.asin(double)
, but is somewhat less
precise than Math's implementation. It is currently the same as libGDX's approximation in their MathUtils.x
- an input to the inverse sine function, from -1 to 1 inclusivepublic static float acos(float x)
Math.acos(double)
, but is somewhat less
precise than Math's implementation. It is currently the same as libGDX's approximation in their MathUtils.
x
- an input to the inverse cosine function, from -1 to 1 inclusivepublic static double asin(double x)
Math.asin(double)
, but is somewhat less
precise than Math's implementation. It is currently the same as libGDX's approximation in their MathUtils, except
that this takes a double and returns a double.
x
- an input to the inverse sine function, from -1 to 1 inclusivepublic static double acos(double x)
Math.acos(double)
, but is somewhat less
precise than Math's implementation. It is currently the same as libGDX's approximation in their MathUtils, except
that this takes a double and returns a double.
x
- an input to the inverse cosine function, from -1 to 1 inclusivepublic static double asin_(double x)
x
- a double from -1.0 to 1.0 (both inclusive), usually the output of sin_() or cos_()n
if it were passed to sin_(double)
public static double acos_(double x)
x
- a double from -1.0 to 1.0 (both inclusive), usually the output of sin_() or cos_()n
if it were passed to cos_(double)
public static float asin_(float x)
x
- a float from -1.0f to 1.0f (both inclusive), usually the output of sin_() or cos_()n
if it were passed to sin_(float)
public static float acos_(float x)
x
- a float from -1.0f to 1.0f (both inclusive), usually the output of sin_() or cos_()n
if it were passed to cos_(float)
Copyright © Eben Howard 2012–2022. All rights reserved.