APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.math

public final Class MathUtils

extends Object
Class Inheritance
Imports
java.util.Random

Utility and fast math functions.

Thanks to Riven on JavaGaming.org for the basis of sin/cos/floor/ceil.

Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final double
private static final double
private static final int
private static final double
private static final double
private static final float
public static final float
public static final float
degreesToRadians

multiply by this to convert from degrees to radians

private static final float
public static final float
E

public static final float
public static final float
public static final float
public static final float
public static final float
public static final float
private static final float
public static final float
radiansToDegrees

multiply by this to convert from radians to degrees

private static final float
public static Random
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static float

Returns:

between 0 and PI when a is in the defined range
acos
(float
acos is defined only when a is between -1f and 1f, inclusive
a
)

Returns acos in radians; less accurate than Math.acos but may be faster.

public static float

Returns:

between 0 and 180 when a is in the defined range
acosDeg
(float
acos is defined only when a is between -1f and 1f, inclusive
a
)

Returns arccosine in degrees.

public static float

Returns:

between -HALF_PI and HALF_PI when a is in the defined range
asin
(float
asin is defined only when a is between -1f and 1f, inclusive
a
)

Returns asin in radians; less accurate than Math.asin but may be faster.

public static float

Returns:

between -90 and 90 when a is in the defined range
asinDeg
(float
asin is defined only when a is between -1f and 1f, inclusive
a
)

Returns arcsine in degrees.

public static float

Returns:

an output from the inverse tangent function, from -HALF_PI to HALF_PI inclusive
atan
(float
an input to the inverse tangent function; any float is accepted
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 11's algorithm, which is the fourth-fastest and fourth-least precise).

public static float

Returns:

the angle to the given point, in radians as a float; ranges from -PI to PI
atan2
(final float
y-component of the point to find the angle towards; note the parameter order is unusual by convention
y
,
float
x-component of the point to find the angle towards; note the parameter order is unusual by convention
x
)

Close approximation of the frequently-used trigonometric method atan2.

public static float

Returns:

the angle to the given point, in degrees as a float; ranges from -180 to 180
atan2Deg
(final float
y-component of the point to find the angle towards; note the parameter order is unusual by convention
y
,
float
x-component of the point to find the angle towards; note the parameter order is unusual by convention
x
)

Close approximation of the frequently-used trigonometric method atan2, using positive or negative degrees.

public static float

Returns:

the angle to the given point, in degrees as a float; ranges from 0 to 360
atan2Deg360
(final float
y-component of the point to find the angle towards; note the parameter order is unusual by convention
y
,
float
x-component of the point to find the angle towards; note the parameter order is unusual by convention
x
)

Close approximation of the frequently-used trigonometric method atan2, using non-negative degrees only.

public static float

Returns:

an output from the inverse tangent function in degrees, from -90 to 90 inclusive
atanDeg
(float
an input to the inverse tangent function; any float is accepted
i
)

Arc tangent approximation returning a value measured in positive or negative degrees, using an algorithm from the 1955 research study "Approximations for Digital Computers," by RAND Corporation (this is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise).

public static float

Returns:

an output from the inverse tangent function, from -HALF_PI to HALF_PI inclusive
atanUnchecked
(double
any finite double or float, but more commonly a float
i
)

A variant on atan(float) that does not tolerate infinite inputs for speed reasons.

public static double

Returns:

an output from the inverse tangent function in degrees, from -90 to 90 inclusive
atanUncheckedDeg
(double
any finite double or float, but more commonly a float
i
)

A variant on atanDeg(float) that does not tolerate infinite inputs for speed reasons.

public static int
ceil(float value)

Returns the smallest integer greater than or equal to the specified float.

public static int
ceilPositive(float value)

Returns the smallest integer greater than or equal to the specified float.

public static short
clamp(short value, short min, short max)

public static int
clamp(int value, int min, int max)

public static long
clamp(long value, long min, long max)

public static float
clamp(float value, float min, float max)

public static double
clamp(double value, double min, double max)

public static float
cos(float radians)

Returns the cosine in radians from a lookup table.

public static float
cosDeg(float degrees)

Returns the cosine in degrees from a lookup table.

public static int
floor(float value)

Returns the largest integer less than or equal to the specified float.

public static int
floorPositive(float value)

Returns the largest integer less than or equal to the specified float.

public static boolean
isEqual(float
the first value.
a
,
float
the second value.
b
)

Returns true if a is nearly equal to b.

public static boolean
isEqual(float
the first value.
a
,
float
the second value.
b
,
float
represent an upper bound below which the two values are considered equal.
tolerance
)

Returns true if a is nearly equal to b.

public static boolean
isPowerOfTwo(int value)

public static boolean
isZero(float value)

Returns true if the value is zero (using the default tolerance as upper bound)

public static boolean
isZero(float value, float
represent an upper bound below which the value is considered zero.
tolerance
)

Returns true if the value is zero.

public static float
lerp(float fromValue, float toValue, float progress)

Linearly interpolates between fromValue to toValue on progress position.

public static float

Returns:

the interpolated angle in the range [0, PI2[
lerpAngle
(float
start angle in radians
fromRadians
,
float
target angle in radians
toRadians
,
float
interpolation value in the range [0, 1]
progress
)

Linearly interpolates between two angles in radians.

public static float

Returns:

the interpolated angle in the range [0, 360[
lerpAngleDeg
(float
start angle in degrees
fromDegrees
,
float
target angle in degrees
toDegrees
,
float
interpolation value in the range [0, 1]
progress
)

Linearly interpolates between two angles in degrees.

public static float
log(float a, float value)

Returns: the logarithm of value with base a

public static float
log2(float value)

Returns: the logarithm of value with base 2

public static float

Returns:

Mapped value. Values outside of the input range are not clamped to output range
map
(float
Input range start
inRangeStart
,
float
Input range end
inRangeEnd
,
float
Output range start
outRangeStart
,
float
Output range end
outRangeEnd
,
float
Value to map
value
)

Linearly map a value from one range to another.

public static int
nextPowerOfTwo(int value)

Returns the next power of two.

public static float

Returns:

Normalized value. Values outside of the range are not clamped to 0 and 1
norm
(float
Range start normalized to 0
rangeStart
,
float
Range end normalized to 1
rangeEnd
,
float
Value to normalize
value
)

Linearly normalizes value from a range.

public static int
random(int range)

Returns a random number between 0 (inclusive) and the specified value (inclusive).

public static int
random(int start, int end)

Returns a random number between start (inclusive) and end (inclusive).

public static long
random(long range)

Returns a random number between 0 (inclusive) and the specified value (inclusive).

public static long
random(long start, long end)

Returns a random number between start (inclusive) and end (inclusive).

public static float
random()

Returns random number between 0.0 (inclusive) and 1.0 (exclusive).

public static float
random(float range)

Returns a random number between 0 (inclusive) and the specified value (exclusive).

public static float
random(float start, float end)

Returns a random number between start (inclusive) and end (exclusive).

public static boolean
randomBoolean()

Returns a random boolean value.

public static boolean
randomBoolean(float chance)

Returns true if a random value between 0 and 1 is less than the specified value.

public static int
randomSign()

Returns -1 or 1, randomly.

public static float
randomTriangular()

Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are more likely.

public static float
randomTriangular(float
the upper limit
max
)

Returns a triangularly distributed random number between -max (exclusive) and max (exclusive), where values around zero are more likely.

public static float
randomTriangular(float
the lower limit
min
,
float
the upper limit
max
)

Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where the mode argument defaults to the midpoint between the bounds, giving a symmetric distribution.

public static float
randomTriangular(float
the lower limit
min
,
float
the upper limit
max
,
float
the point around which the values are more likely
mode
)

Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where values around mode are more likely.

public static int
round(float value)

Returns the closest integer to the specified float.

public static int
roundPositive(float value)

Returns the closest integer to the specified float.

public static float
sin(float radians)

Returns the sine in radians from a lookup table.

public static float
sinDeg(float degrees)

Returns the sine in degrees from a lookup table.

public static float

Returns:

a float approximation of tan()
tan
(float
a float angle in radians, where 0 to PI2 is one rotation
radians
)

Returns the tangent given an input in radians, using a Padé approximant.

public static float

Returns:

a float approximation of tan()
tanDeg
(float
an angle in degrees, where 0 to 360 is one rotation
degrees
)

Returns the tangent given an input in degrees, using a Padé approximant.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIG_ENOUGH_CEILback to summary
private static final double BIG_ENOUGH_CEIL
BIG_ENOUGH_FLOORback to summary
private static final double BIG_ENOUGH_FLOOR
BIG_ENOUGH_INTback to summary
private static final int BIG_ENOUGH_INT
BIG_ENOUGH_ROUNDback to summary
private static final double BIG_ENOUGH_ROUND
CEILback to summary
private static final double CEIL
degFullback to summary
private static final float degFull
degRadback to summary
public static final float degRad
degreesToRadiansback to summary
public static final float degreesToRadians

multiply by this to convert from degrees to radians

degToIndexback to summary
private static final float degToIndex
Eback to summary
public static final float E
FLOAT_ROUNDING_ERRORback to summary
public static final float FLOAT_ROUNDING_ERROR
HALF_PIback to summary
public static final float HALF_PI
nanoToSecback to summary
public static final float nanoToSec
PIback to summary
public static final float PI
PI2back to summary
public static final float PI2
radDegback to summary
public static final float radDeg
radFullback to summary
private static final float radFull
radiansToDegreesback to summary
public static final float radiansToDegrees

multiply by this to convert from radians to degrees

radToIndexback to summary
private static final float radToIndex
randomback to summary
public static Random random
SIN_BITSback to summary
private static final int SIN_BITS
SIN_COUNTback to summary
private static final int SIN_COUNT
SIN_MASKback to summary
private static final int SIN_MASK

Constructor Detail

MathUtilsback to summary
private MathUtils()

Method Detail

acosback to summary
public static float acos(float a)

Returns acos in radians; less accurate than Math.acos but may be faster. Average error of 0.00002845 radians (0.0016300649 degrees), largest error of 0.000067548 radians (0.0038702153 degrees). This implementation does not return NaN if given an out-of-range input (Math.acos does return NaN), unless the input is NaN.

Parameters
a:float

acos is defined only when a is between -1f and 1f, inclusive

Returns:float

between 0 and PI when a is in the defined range

acosDegback to summary
public static float acosDeg(float a)

Returns arccosine in degrees. This implementation does not return NaN if given an out-of-range input (Math.acos does return NaN), unless the input is NaN.

Parameters
a:float

acos is defined only when a is between -1f and 1f, inclusive

Returns:float

between 0 and 180 when a is in the defined range

asinback to summary
public static float asin(float a)

Returns asin in radians; less accurate than Math.asin but may be faster. Average error of 0.000028447 radians (0.0016298931 degrees), largest error of 0.000067592 radians (0.0038727364 degrees). This implementation does not return NaN if given an out-of-range input (Math.asin does return NaN), unless the input is NaN.

Parameters
a:float

asin is defined only when a is between -1f and 1f, inclusive

Returns:float

between -HALF_PI and HALF_PI when a is in the defined range

asinDegback to summary
public static float asinDeg(float a)

Returns arcsine in degrees. This implementation does not return NaN if given an out-of-range input (Math.asin does return NaN), unless the input is NaN.

Parameters
a:float

asin is defined only when a is between -1f and 1f, inclusive

Returns:float

between -90 and 90 when a is in the defined range

atanback to summary
public 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 11's algorithm, which is the fourth-fastest and fourth-least precise). This method is usually about 4x faster than Math#atan(double), but is somewhat less precise than Math's implementation. For finite inputs only, you may get a tiny speedup by using atanUnchecked(double), but this method will be correct enough for infinite inputs, and atanUnchecked() will not be.

Parameters
i:float

an input to the inverse tangent function; any float is accepted

Returns:float

an output from the inverse tangent function, from -HALF_PI to HALF_PI inclusive

See Also
If you know the input will be finite, you can use atanUnchecked() instead.
atan2back to summary
public static float atan2(final float y, float x)

Close approximation of the frequently-used trigonometric method atan2. Average error is 1.057E-6 radians; maximum error is 1.922E-6. Takes y and x (in that unusual order) as floats, and returns the angle from the origin to that point in radians. It is about 4 times faster than Math#atan2(double, double) (roughly 15 ns instead of roughly 60 ns for Math, on Java 8 HotSpot).
Credit for this goes to the 1955 research study "Approximations for Digital Computers," by RAND Corporation. This is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise. The algorithms on sheets 8-10 are faster, but only by a very small degree, and are considerably less precise. That study provides an atan(float) method, and that cleanly translates to atan2().

Parameters
y:float

y-component of the point to find the angle towards; note the parameter order is unusual by convention

x:float

x-component of the point to find the angle towards; note the parameter order is unusual by convention

Returns:float

the angle to the given point, in radians as a float; ranges from -PI to PI

atan2Degback to summary
public static float atan2Deg(final float y, float x)

Close approximation of the frequently-used trigonometric method atan2, using positive or negative degrees. Average absolute error is 0.00006037 degrees; relative error is 0 degrees, maximum error is 0.00010396 degrees. Takes y and x (in that unusual order) as floats, and returns the angle from the origin to that point in degrees.
Credit for this goes to the 1955 research study "Approximations for Digital Computers," by RAND Corporation. This is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise. The algorithms on sheets 8-10 are faster, but only by a very small degree, and are considerably less precise. That study provides an atan(float) method, and that cleanly translates to atan2().

Parameters
y:float

y-component of the point to find the angle towards; note the parameter order is unusual by convention

x:float

x-component of the point to find the angle towards; note the parameter order is unusual by convention

Returns:float

the angle to the given point, in degrees as a float; ranges from -180 to 180

atan2Deg360back to summary
public static float atan2Deg360(final float y, float x)

Close approximation of the frequently-used trigonometric method atan2, using non-negative degrees only. Average absolute error is 0.00006045 degrees; relative error is 0 degrees; maximum error is 0.00011178 degrees. Takes y and x (in that unusual order) as floats, and returns the angle from the origin to that point in degrees.
This can be useful when a negative result from atan() would require extra work to handle.
Credit for this goes to the 1955 research study "Approximations for Digital Computers," by RAND Corporation. This is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise. The algorithms on sheets 8-10 are faster, but only by a very small degree, and are considerably less precise. That study provides an atan(float) method, and that cleanly translates to atan2Deg360().

Parameters
y:float

y-component of the point to find the angle towards; note the parameter order is unusual by convention

x:float

x-component of the point to find the angle towards; note the parameter order is unusual by convention

Returns:float

the angle to the given point, in degrees as a float; ranges from 0 to 360

atanDegback to summary
public static float atanDeg(float i)

Arc tangent approximation returning a value measured in positive or negative degrees, using an algorithm from the 1955 research study "Approximations for Digital Computers," by RAND Corporation (this is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise). For finite inputs only, you may get a tiny speedup by using atanUncheckedDeg(double), but this method will be correct enough for infinite inputs, and atanUnchecked() will not be.

Parameters
i:float

an input to the inverse tangent function; any float is accepted

Returns:float

an output from the inverse tangent function in degrees, from -90 to 90 inclusive

See Also
If you know the input will be finite, you can use atanUncheckedDeg() instead.
atanUncheckedback to summary
public static float atanUnchecked(double i)

A variant on atan(float) that does not tolerate infinite inputs for speed reasons. This can be given a double parameter, but is otherwise the same as atan(float), and returns a float like that method. It uses the same approximation, from sheet 11 of "Approximations for Digital Computers." This is mostly meant to be used inside atan2(float, float), but it may be a tiny bit faster than atan(float) in other code.

Parameters
i:double

any finite double or float, but more commonly a float

Returns:float

an output from the inverse tangent function, from -HALF_PI to HALF_PI inclusive

atanUncheckedDegback to summary
public static double atanUncheckedDeg(double i)

A variant on atanDeg(float) that does not tolerate infinite inputs for speed reasons. This can be given a double parameter, but is otherwise the same as atanDeg(float), and returns a float like that method. It uses the same approximation, from sheet 11 of "Approximations for Digital Computers." This is mostly meant to be used inside atan2(float, float), but it may be a tiny bit faster than atanDeg(float) in other code.

Parameters
i:double

any finite double or float, but more commonly a float

Returns:double

an output from the inverse tangent function in degrees, from -90 to 90 inclusive

ceilback to summary
public static int ceil(float value)

Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats from -(2^14) to (Float.MAX_VALUE - 2^14).

ceilPositiveback to summary
public static int ceilPositive(float value)

Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats that are positive.

clampback to summary
public static short clamp(short value, short min, short max)
clampback to summary
public static int clamp(int value, int min, int max)
clampback to summary
public static long clamp(long value, long min, long max)
clampback to summary
public static float clamp(float value, float min, float max)
clampback to summary
public static double clamp(double value, double min, double max)
cosback to summary
public static float cos(float radians)

Returns the cosine in radians from a lookup table. For optimal precision, use radians between -PI2 and PI2 (both inclusive).

cosDegback to summary
public static float cosDeg(float degrees)

Returns the cosine in degrees from a lookup table. For optimal precision, use degrees between -360 and 360 (both inclusive).

floorback to summary
public static int floor(float value)

Returns the largest integer less than or equal to the specified float. This method will only properly floor floats from -(2^14) to (Float.MAX_VALUE - 2^14).

floorPositiveback to summary
public static int floorPositive(float value)

Returns the largest integer less than or equal to the specified float. This method will only properly floor floats that are positive. Note this method simply casts the float to int.

isEqualback to summary
public static boolean isEqual(float a, float b)

Returns true if a is nearly equal to b. The function uses the default floating error tolerance.

Parameters
a:float

the first value.

b:float

the second value.

isEqualback to summary
public static boolean isEqual(float a, float b, float tolerance)

Returns true if a is nearly equal to b.

Parameters
a:float

the first value.

b:float

the second value.

tolerance:float

represent an upper bound below which the two values are considered equal.

isPowerOfTwoback to summary
public static boolean isPowerOfTwo(int value)
isZeroback to summary
public static boolean isZero(float value)

Returns true if the value is zero (using the default tolerance as upper bound)

isZeroback to summary
public static boolean isZero(float value, float tolerance)

Returns true if the value is zero.

Parameters
tolerance:float

represent an upper bound below which the value is considered zero.

lerpback to summary
public static float lerp(float fromValue, float toValue, float progress)

Linearly interpolates between fromValue to toValue on progress position.

lerpAngleback to summary
public static float lerpAngle(float fromRadians, float toRadians, float progress)

Linearly interpolates between two angles in radians. Takes into account that angles wrap at two pi and always takes the direction with the smallest delta angle.

Parameters
fromRadians:float

start angle in radians

toRadians:float

target angle in radians

progress:float

interpolation value in the range [0, 1]

Returns:float

the interpolated angle in the range [0, PI2[

lerpAngleDegback to summary
public static float lerpAngleDeg(float fromDegrees, float toDegrees, float progress)

Linearly interpolates between two angles in degrees. Takes into account that angles wrap at 360 degrees and always takes the direction with the smallest delta angle.

Parameters
fromDegrees:float

start angle in degrees

toDegrees:float

target angle in degrees

progress:float

interpolation value in the range [0, 1]

Returns:float

the interpolated angle in the range [0, 360[

logback to summary
public static float log(float a, float value)
Returns:float

the logarithm of value with base a

log2back to summary
public static float log2(float value)
Returns:float

the logarithm of value with base 2

mapback to summary
public static float map(float inRangeStart, float inRangeEnd, float outRangeStart, float outRangeEnd, float value)

Linearly map a value from one range to another. Input range must not be empty. This is the same as chaining norm(float, float, float) from input range and lerp(float, float, float) to output range.

Parameters
inRangeStart:float

Input range start

inRangeEnd:float

Input range end

outRangeStart:float

Output range start

outRangeEnd:float

Output range end

value:float

Value to map

Returns:float

Mapped value. Values outside of the input range are not clamped to output range

nextPowerOfTwoback to summary
public static int nextPowerOfTwo(int value)

Returns the next power of two. Returns the specified value if the value is already a power of two.

normback to summary
public static float norm(float rangeStart, float rangeEnd, float value)

Linearly normalizes value from a range. Range must not be empty. This is the inverse of lerp(float, float, float).

Parameters
rangeStart:float

Range start normalized to 0

rangeEnd:float

Range end normalized to 1

value:float

Value to normalize

Returns:float

Normalized value. Values outside of the range are not clamped to 0 and 1

randomback to summary
public static int random(int range)

Returns a random number between 0 (inclusive) and the specified value (inclusive).

randomback to summary
public static int random(int start, int end)

Returns a random number between start (inclusive) and end (inclusive).

randomback to summary
public static long random(long range)

Returns a random number between 0 (inclusive) and the specified value (inclusive).

randomback to summary
public static long random(long start, long end)

Returns a random number between start (inclusive) and end (inclusive).

randomback to summary
public static float random()

Returns random number between 0.0 (inclusive) and 1.0 (exclusive).

randomback to summary
public static float random(float range)

Returns a random number between 0 (inclusive) and the specified value (exclusive).

randomback to summary
public static float random(float start, float end)

Returns a random number between start (inclusive) and end (exclusive).

randomBooleanback to summary
public static boolean randomBoolean()

Returns a random boolean value.

randomBooleanback to summary
public static boolean randomBoolean(float chance)

Returns true if a random value between 0 and 1 is less than the specified value.

randomSignback to summary
public static int randomSign()

Returns -1 or 1, randomly.

randomTriangularback to summary
public static float randomTriangular()

Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are more likely.

This is an optimized version of randomTriangular(-1, 1, 0)

randomTriangularback to summary
public static float randomTriangular(float max)

Returns a triangularly distributed random number between -max (exclusive) and max (exclusive), where values around zero are more likely.

This is an optimized version of randomTriangular(-max, max, 0)

Parameters
max:float

the upper limit

randomTriangularback to summary
public static float randomTriangular(float min, float max)

Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where the mode argument defaults to the midpoint between the bounds, giving a symmetric distribution.

This method is equivalent of randomTriangular(min, max, (min + max) * 0.5f)

Parameters
min:float

the lower limit

max:float

the upper limit

randomTriangularback to summary
public static float randomTriangular(float min, float max, float mode)

Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where values around mode are more likely.

Parameters
min:float

the lower limit

max:float

the upper limit

mode:float

the point around which the values are more likely

roundback to summary
public static int round(float value)

Returns the closest integer to the specified float. This method will only properly round floats from -(2^14) to (Float.MAX_VALUE - 2^14).

roundPositiveback to summary
public static int roundPositive(float value)

Returns the closest integer to the specified float. This method will only properly round floats that are positive.

sinback to summary
public static float sin(float radians)

Returns the sine in radians from a lookup table. For optimal precision, use radians between -PI2 and PI2 (both inclusive).

sinDegback to summary
public static float sinDeg(float degrees)

Returns the sine in degrees from a lookup table. For optimal precision, use degrees between -360 and 360 (both inclusive).

tanback to summary
public static float tan(float radians)

Returns the tangent given an input in radians, using a Padé approximant.
Padé approximants tend to be most accurate when they aren't producing results of extreme magnitude; in the tan() function, those results occur on and near odd multiples of PI/2, and this method is least accurate when given inputs near those multiples.
For inputs between -1.57 to 1.57 (just inside half-pi), separated by 0x1p-20f, absolute error is 0.00890192, relative error is 0.00000090, and the maximum error is 17.98901367 when given 1.56999838. The maximum error might seem concerning, but it's the difference between the correct 1253.22167969 and the 1235.23266602 this returns, so for many purposes the difference won't be noticeable.
For inputs between -1.55 to 1.55 (getting less close to half-pi), separated by 0x1p-20f, absolute error is 0.00023368, relative error is -0.00000009, and the maximum error is 0.02355957 when given -1.54996467. The maximum error is the difference between the correct -47.99691010 and the -47.97335052 this returns.
While you don't have to use a dedicated method for tan(), and you can use sin(x)/cos(x), approximating tan() in that way is very susceptible to error building up from any of sin(), cos() or the division. Where this tan() has a maximum error in the -1.55 to 1.55 range of 0.02355957, that simpler division technique on the same range has a maximum error of 1.25724030 (about 50 times worse), as well as larger absolute and relative errors. Casting the double result of Math#tan(double) to float will get the highest precision, but can be anywhere from 2.5x to nearly 4x slower than this, depending on JVM.
Based on this Stack Exchange answer by Soonts.

Parameters
radians:float

a float angle in radians, where 0 to PI2 is one rotation

Returns:float

a float approximation of tan()

tanDegback to summary
public static float tanDeg(float degrees)

Returns the tangent given an input in degrees, using a Padé approximant. Based on this Stack Exchange answer.

Parameters
degrees:float

an angle in degrees, where 0 to 360 is one rotation

Returns:float

a float approximation of tan()

com.badlogic.gdx.math back to summary

private Class MathUtils.Sin

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final float[]

Constructor Summary

AccessConstructor and Description
private
Sin()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

tableback to summary
pack-priv static final float[] table

Constructor Detail

Sinback to summary
private Sin()