Documentation ¶
Overview ¶
Package Float provides a generic math library for floating-point numbers.
Index ¶
- Constants
- func Abs[X Any](x X) X
- func BezierDerivative[T Any](start, control_1, control_2, end, t T) T
- func BezierInterpolate[T Any](start, control_1, control_2, end, t T) T
- func Ceil[X Any](x X) X
- func Clamp[X Any](value, min, max X) X
- func CubicInterpolate[X Any](from, to, pre, post, weight X) X
- func CubicInterpolateInTime[X Any](from, to, pre, post, weight, to_t, pre_t, post_t X) X
- func DecibelsToLinear[X Any](db X) X
- func Ease[X Any](x, curve X) X
- func Exp[X Any](x X) X
- func Floor[X Any](x X) X
- func InverseLerp[X Any](from, to, weight X) X
- func IsApproximatelyEqual[X Any](a, b X) bool
- func IsApproximatelyZero[X Any](x X) bool
- func IsFinite[X Any](x X) bool
- func IsInf[X Any](x X) bool
- func IsNaN[X Any](x X) bool
- func Lerp[X Any](from, to, weight X) X
- func LinearToDecibels[X Any](energy X) X
- func Log[X Any](x X) X
- func Max[T Any](a, b T) T
- func Min[T Any](a, b T) T
- func Mod[X Any](x, y X) X
- func MoveToward[X Any](from, to, delta X) X
- func PingPong[X Any](value, length X) X
- func Posmod[X Any](x, y X) X
- func Pow[X Any](base, exp X) X
- func Remap[X Any](value, istart, istop, ostart, ostop X) X
- func Round[X Any](x X) X
- func Sign[X Any](x X) X
- func Smoothstep[X Any](from, to, x X) X
- func Snapped[X Any](x, step X) X
- func Sqrt[X Any](x X) X
- func StepDecimals[X Any](x X) int
- func Wrap[X Any](value, min, max X) X
- type Any
- type X
Constants ¶
const Epsilon = 0.00001
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[X Any](x X) X
Abs returns the absolute value of the float parameter x (i.e. non-negative value).
func BezierDerivative ¶
func BezierDerivative[T Any](start, control_1, control_2, end, t T) T
BezierDerivative returns the derivative at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.
func BezierInterpolate ¶
func BezierInterpolate[T Any](start, control_1, control_2, end, t T) T
BezierInterpolate returns the point at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.
func Ceil ¶
func Ceil[X Any](x X) X
Ceil rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.
func Clamp ¶
func Clamp[X Any](value, min, max X) X
Clamp clamps the value, returning a Variant not less than min and not more than max. Any values that can be compared with the less than and greater than operators will work.
func CubicInterpolate ¶
func CubicInterpolate[X Any](from, to, pre, post, weight X) X
CubicInterpolate cubic interpolates between two values by the factor defined in weightSee also with pre and post values.
func CubicInterpolateInTime ¶
func CubicInterpolateInTime[X Any](from, to, pre, post, weight, to_t, pre_t, post_t X) X
CubicInterpolateInTime cubic interpolates between two values by the factor defined in weight with pre and post values.
It can perform smoother interpolation than cubic_interpolate by the time values.
func DecibelsToLinear ¶
func DecibelsToLinear[X Any](db X) X
DecibelsToLinear converts from decibels to linear energy (audio).
func Ease ¶
func Ease[X Any](x, curve X) X
Ease returns an "eased" value of x based on an easing function defined with curve. This easing function is based on an exponent. The curve can be any floating-point number, with specific values leading to the following behaviors:
- Lower than -1.0 (exclusive): Ease in-out - 1.0: Linear - Between -1.0 and 0.0 (exclusive): Ease out-in - 0.0: Constant - Between 0.0 to 1.0 (exclusive): Ease out - 1.0: Linear - Greater than 1.0 (exclusive): Ease in
https://raw.githubusercontent.com/godotengine/godot-docs/master/img/ease_cheatsheet.png
See also Smoothstep. If you need to perform more advanced transitions, use [Tween.InterpolateValue].
func Floor ¶
func Floor[X Any](x X) X
Floorf rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.
func InverseLerp ¶
func InverseLerp[X Any](from, to, weight X) X
InverseLerp returns an interpolation or extrapolation factor considering the range specified in from and to, and the interpolated value specified in weight. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive). If weight is located outside this range, then an extrapolation factor will be returned (return value lower than 0.0 or greater than 1.0). Use Clamp on the result of InverseLerp if this is not desired.
func IsApproximatelyEqual ¶
IsApproximatelyEqual returns true if a and b are approximately equal to each other.
Here, "approximately equal" means that a and b are within a small internal epsilon of each other, which scales with the magnitude of the numbers.
Infinity values of the same sign are considered equal.
func IsApproximatelyZero ¶
IsApproximatelyZero Returns true if x is zero or almost zero. The comparison is done using a tolerance calculation with a small internal Epsilon. This function is faster than using IsApproximatelyEqual with one value as zero.
func Lerp ¶
func Lerp[X Any](from, to, weight X) X
Lerpf linearly interpolates between two values by the factor defined in weight. To perform interpolation, weight should be between 0.0 and 1.0 (inclusive). However, values outside this range are allowed and can be used to perform extrapolation. If this is not desired, use [Clampf] on the result of this function.
See also InverseLerp which performs the reverse of this operation. To perform eased interpolation with [Lerpf], combine it with ease or smoothstep.
func LinearToDecibels ¶
func LinearToDecibels[X Any](energy X) X
LinearToDecibels converts from linear energy (audio) to decibels.
func Mod ¶
func Mod[X Any](x, y X) X
Fmod returns the floating-point remainder of x divided by y, keeping the sign of x.
func MoveToward ¶
func MoveToward[X Any](from, to, delta X) X
MoveToward moves from toward to by the delta amount. Will not go past to. Use a negative delta value to move away.
func PingPong ¶
func PingPong[X Any](value, length X) X
PingPong wraps value between 0 and the length. If the limit is reached, the next value the function returns is decreased to the 0 side or increased to the length side (like a triangle wave). If length is less than zero, it becomes positive.
func Posmod ¶
func Posmod[X Any](x, y X) X
Fposmod returns the floating-point modulus of x divided by y, wrapping equally in positive and negative.
func Pow ¶
func Pow[X Any](base, exp X) X
Pow returns the result of base raised to the power of exp.
func Remap ¶
func Remap[X Any](value, istart, istop, ostart, ostop X) X
Remap maps a value from range (istart, istop) to (ostart, ostop). See also Lerp and InverseLerp. If value is outside (istart, istop), then the resulting value will also be outside (ostart, ostop). If this is not desired, use Clamp on the result of this function.
func Round ¶
func Round[X Any](x X) X
Round rounds x to the nearest whole number, with halfway cases rounded away from 0.
func Sign ¶
func Sign[X Any](x X) X
Sign returns -1.0 if x is negative, 1.0 if x is positive, and 0.0 if x is zero. For NaN values of x it returns 0.0.
func Smoothstep ¶
func Smoothstep[X Any](from, to, x X) X
Smoothstep returns the result of smoothly interpolating the value of x between 0 and 1, based on the where x lies with respect to the edges from and to.
The return value is 0 if x <= from, and 1 if x >= to. If x lies between from and to, the returned value follows an S-shaped curve that maps x between 0 and 1.
This S-shaped curve is the cubic Hermite interpolator, given by
(y) = 3*y^2 - 2*y^3 where y = (x-from) / (to-from).
func Snapped ¶
func Snapped[X Any](x, step X) X
Snapped returns the multiple of step that is the closest to x. This can also be used to round a floating point number to an arbitrary number of decimals.
func Sqrt ¶
func Sqrt[X Any](x X) X
Sqrt returns the square root of x. Where x is negative, the result is NaN.
func StepDecimals ¶
StepDecimals returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
Types ¶
type X ¶
type X = float32
func RandomBetween ¶
RandomBetween returns a random float between min and max (inclusive).
func RandomlyDistributed ¶
RandomlyDistributed eeturns a normally-distributed, pseudo-random floating-point value from the specified mean and a standard deviation. This is also known as a Gaussian distribution.