Documentation
¶
Overview ¶
Package mathutils - because apparently I needed MORE math in my life Contains basic math functions and some black magic optimization algorithms that I probably shouldn't understand but somehow work.
Index ¶
- func Abs[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64](x T) T
- func Average[...](slice []T) (float64, bool)
- func Clamp[...](value, min, max T) T
- func DegToRad(degrees float64) float64
- func Factorial(n int) int
- func FastCos(x float64) float64
- func FastInvSqrt(x float32) float32
- func FastPow(base float64, exp int) float64
- func FastSin(x float64) float64
- func GCD(a, b int) int
- func IsInf(x float64, sign int) bool
- func IsNaN(x float64) bool
- func IsPowerOfTwo(x int) bool
- func IsPrime(n int) bool
- func LCM(a, b int) int
- func Lerp(a, b, t float64) float64
- func Max[...](a, b T) T
- func MaxSlice[...](slice []T) (T, bool)
- func Min[...](a, b T) T
- func MinSlice[...](slice []T) (T, bool)
- func NextPowerOfTwo(x int) int
- func PopCount(x uint64) int
- func RadToDeg(radians float64) float64
- func Round(x float64) float64
- func RoundToDecimal(x float64, decimals int) float64
- func SmoothStep(edge0, edge1, x float64) float64
- func Sum[...](slice []T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Average ¶
func Average[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64](slice []T) (float64, bool)
Average calculates the mean because life isn't always extreme
func Clamp ¶
func Clamp[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64](value, min, max T) T
Clamp constrains a value because some things need boundaries (unlike my caffeine intake)
func FastInvSqrt ¶
FastInvSqrt - The legendary Quake inverse square root This is basically black magic from the 90s that still makes me question reality
func GCD ¶
GCD - Greatest Common Divisor using Euclidean algorithm (Euclid was clearly showing off but hey, it works)
func IsPowerOfTwo ¶
IsPowerOfTwo checks if a number is a power of 2 using bit wizardry
func IsPrime ¶
IsPrime checks if a number is prime using trial division (Because even numbers need to feel special sometimes)
func Max ¶
func Max[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64](a, b T) T
Max because everyone wants to be the winner
func MaxSlice ¶
func MaxSlice[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64](slice []T) (T, bool)
MaxSlice finds the biggest number (unlike my bank account)
func Min ¶
func Min[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64](a, b T) T
Min because someone has to lose
func MinSlice ¶
func MinSlice[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64](slice []T) (T, bool)
MinSlice finds the smallest number in a slice (like my self-esteem in code reviews)
func NextPowerOfTwo ¶
NextPowerOfTwo finds the next power of 2 (useful for memory allocation and existential dread)
func PopCount ¶
PopCount returns the number of set bits (because counting 1s is apparently important)
func RoundToDecimal ¶
RoundToDecimal rounds to n decimal places (for when you need to be precise-ish)
func SmoothStep ¶
SmoothStep - Smooth Hermite interpolation for when linear is too boring
Types ¶
This section is empty.