mathutils

package
v1.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Number](value T) T

Abs returns the absolute value of an integer. For unsigned types, returns the value as-is.

func Average

func Average[T Number](values []T) float64

Average returns the average (mean) of all values in a slice. Returns 0 for empty slice.

func Clamp

func Clamp[T cmp.Ordered](value, min, max T) T

Clamp restricts a value to be within a specified range. If value < min, returns min. If value > max, returns max. Otherwise returns value.

func Gcd

func Gcd[T constraints.Integer](a, b T) T

Gcd returns the greatest common divisor of two integers using Euclidean algorithm.

func InRange

func InRange[T cmp.Ordered](value, min, max T) bool

InRange checks if a value is within a range [min, max] (inclusive).

func IsPrime

func IsPrime[T constraints.Integer](n T) bool

IsPrime checks if a number is prime. Returns false for numbers less than 2.

func Lcm

func Lcm[T constraints.Integer](a, b T) T

Lcm returns the least common multiple of two integers.

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number is a constraint for numeric types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL