Documentation ¶
Overview ¶
Utility and fast math functions.
Index ¶
- Variables
- func Atan2(y, x float32) float32
- func Ceil(value float32) int
- func CeilPositive(value float32) int
- func ClampFloat32(value float32, min float32, max float32) float32
- func ClampFloat64(value float64, min float64, max float64) float64
- func ClampInt(value int, min int, max int) int
- func ClampInt64(value int64, min int64, max int64) int64
- func ClampInt8(value int8, min int8, max int8) int8
- func Cos(radians float32) float32
- func CosDeg(degrees float32) float32
- func Floor(value float32) int
- func FloorPositive(value float32) int
- func IsEqual(a, b float32) bool
- func IsEqualTolerance(a, b, tolerance float32) bool
- func IsPowerOfTwo(value int) bool
- func IsZero(value float32) bool
- func IsZeroTolerance(value, tolerance float32) bool
- func Lerp(fromValue, toValue, progress float32) float32
- func Log(a, value float32) float32
- func Log2(value float32) float32
- func NextPowerOfTwo(value int) int
- func Random(n int) int
- func RandomFloat() float32
- func RandomRange(start, end int) int
- func RandomTriangular() float32
- func RandomTriangularMax(max float32) float32
- func RandomTriangularMinMax(min, max float32) float32
- func RandomTriangularMinMaxMode(min, max, mode float32) float32
- func Round(value float32) int
- func RoundPositive(value float32) int
- func Sin(radians float32) float32
- func SinDeg(degrees float32) float32
Constants ¶
This section is empty.
Variables ¶
var ( NanoToSec float32 = 1 / 1000000000 FLOAT_ROUNDING_ERROR float32 = 0.000001 // 32 bits PI float32 = 3.1415927 PI2 float32 = PI * 2 PI_4_3 float32 = PI * 4 / 3 E float32 = 2.7182818 SIN_BITS uint = 14 // 16KB. Adjust for accuracy. SIN_MASK int = ^(-1 << SIN_BITS) SIN_COUNT int = SIN_MASK + 1 RadFull float32 = PI * 2 DegFull float32 = 360 RadToIndex float32 = float32(SIN_COUNT) / RadFull DegToIndex float32 = float32(SIN_COUNT) / DegFull // multiply by this to convert from radians to degrees RadiansToDegrees float32 = 180 / PI // multiply by this to convert from degrees to radians DegreesToRadians float32 = PI / 180 DegRad float32 = DegreesToRadians BIG_ENOUGH_INT float32 = 16 * 1024 BIG_ENOUGH_FLOOR float32 = BIG_ENOUGH_INT CEIL float32 = 0.9999999 BIG_ENOUGH_CEIL float32 = 16384.999999999996 BIG_ENOUGH_ROUND float32 = BIG_ENOUGH_INT + 0.5 )
Functions ¶
func Atan2 ¶
* Returns atan2 in radians, faster but less accurate than math.atan2. Average error of 0.00231 radians (0.1323 degrees),
- largest error of 0.00488 radians (0.2796 degrees).
func Ceil ¶
* 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).
func CeilPositive ¶
* Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats that
- are positive.
func Floor ¶
* 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).
func FloorPositive ¶
* 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 float32 to int.
func IsEqual ¶
Returns true if a is nearly equal to b. The function uses the default floating error tolerance.
func IsEqualTolerance ¶
* Returns true if a is nearly equal to b.
- @param a the first value.
- @param b the second value.
- @param tolerance represent an upper bound below which the two values are considered equal.
func IsPowerOfTwo ¶
func IsZeroTolerance ¶
* Returns true if the value is zero.
- @param tolerance represent an upper bound below which the value is considered zero.
func NextPowerOfTwo ¶
Returns the next power of two. Returns the specified value if the value is already a power of two.
func RandomFloat ¶
func RandomFloat() float32
func RandomRange ¶
Returns a random number between start (inclusive) and end (inclusive).
func RandomTriangular ¶
func RandomTriangular() float32
* Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are
- more likely.
- <p>
- This is an optimized version of {@link #randomTriangular(float, float, float) randomTriangular(-1, 1, 0)}
func RandomTriangularMax ¶
Returns a triangularly distributed random number between {@code -max} (exclusive) and {@code max} (exclusive), where values * around zero are more likely. * <p> * This is an optimized version of {@link #randomTriangular(float, float, float) randomTriangular(-max, max, 0)} * @param max the upper limit
func RandomTriangularMinMax ¶
* Returns a triangularly distributed random number between {@code min} (inclusive) and {@code max} (exclusive), where the
- {@code mode} argument defaults to the midpoint between the bounds, giving a symmetric distribution.
- <p>
- This method is equivalent of {@link #randomTriangular(float, float, float) randomTriangular(min, max, (max - min) * .5f)}
- @param min the lower limit
- @param max the upper limit
func RandomTriangularMinMaxMode ¶
* Returns a triangularly distributed random number between {@code min} (inclusive) and {@code max} (exclusive), where values
- around {@code mode} are more likely.
- @param min the lower limit
- @param max the upper limit
- @param mode the point around which the values are more likely
func Round ¶
* Returns the closest integer to the specified float. This method will only properly round floats from -(2^14) to
- (Float.MAX_VALUE - 2^14).
func RoundPositive ¶
Returns the closest integer to the specified float. This method will only properly round floats that are positive.
Types ¶
This section is empty.