math

package
v1.2.115 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs added in v1.2.69

func Abs[T constraints.Number](x T) T

Abs returns the absolute value of last.

func Clamp added in v1.2.38

func Clamp[T constraints.Ordered](v, lo, hi T) T

Clamp returns the value between boundary [lo,hi], as v < lo ? v : hi > v : hi : v. Reference to lo if v is less than lo, reference to hi if hi is less than v, otherwise reference to v. If v compares equivalent to either bound, returns a reference to v, not the bound.

func Compare added in v1.2.74

func Compare[E constraints.Ordered](a E, b E) int

Compare returns an integer comparing two elements. The result will be 0 if a == b, -1 if a < b, and +1 if a > b. This implementation places NaN values before any others, by using:

a < b || (math.IsNaN(a) && !math.IsNaN(b))

func Dim

func Dim[T constraints_.Number](x, y T) T

Dim returns the maximum of x-y or 0.

func IsNaN added in v1.2.74

func IsNaN[E constraints.Ordered](f E) bool

IsNaN is a copy of math.IsNaN to avoid a dependency on the math package.

func Latest added in v1.2.69

func Latest[T SerialNumber](s1, s2 T) T

Latest return newer of s1, s2

func Max

func Max[T constraints.Ordered](s ...T) T

Max returns the largest of s.

func MaxInt added in v1.2.69

func MaxInt[T constraints.Integer]() T

MaxInt returns the largest value representable by the type.

func Mean added in v1.2.73

func Mean[T constraints_.Number, R constraints.Float](s ...T) R

Mean returns the mean of s.

func Min

func Min[T constraints.Ordered](s ...T) T

Min returns the smallest of s.

func MinInt added in v1.2.69

func MinInt[T constraints.Integer]() T

MinInt returns the smallest value representable by the type.

func Reverse added in v1.2.76

func Reverse[E constraints.Ordered](cmp func(a E, b E) int) func(a E, b E) int

Reverse returns the reverse comparison for cmp, as cmp(b, a).

func RingRem added in v1.2.68

func RingRem[T constraints.Integer](x, y T) T

RingRem returns the remainder of x looped by +ny until in y > 0 ? [0, y) : (y, 0]. RingRem panics for y == 0 (division by zero). y > 0, then ∈ [0, y) y < 0, then ∈ (y, 0]

func StandardDeviation added in v1.2.73

func StandardDeviation[T constraints_.Number, R constraints.Float](s ...T) R

StandardDeviation returns the standard deviation of s.

func Sum added in v1.2.73

func Sum[T, R constraints_.Number](s ...T) R

Sum returns the sum of s.

func Unwrap added in v1.2.69

func Unwrap[T SerialNumber](lastValue int64, value T) int64

Unwrap unwrap a number to a larger type. The numbers will never be unwrapped to a negative value.

func Variance added in v1.2.73

func Variance[T constraints_.Number, R constraints.Float](s ...T) R

Variance returns the variance of s.

Types

type SerialNumber added in v1.2.69

type SerialNumber = constraints.Unsigned

SerialNumber is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.

type Unwrapper added in v1.2.69

type Unwrapper[T SerialNumber] struct {
	// contains filtered or unexported fields
}

Unwrapper is an utility class to unwrap a number to a larger type. The numbers will never be unwrapped to a negative value.

func (*Unwrapper[T]) Unwrap added in v1.2.69

func (u *Unwrapper[T]) Unwrap(value T) int64

Unwrap the value and update the internal state.

func (*Unwrapper[T]) UnwrapWithoutUpdate added in v1.2.69

func (u *Unwrapper[T]) UnwrapWithoutUpdate(value T) int64

UnwrapWithoutUpdate returns the unwrapped value, but don't update the internal state.

func (*Unwrapper[T]) UpdateLast added in v1.2.69

func (u *Unwrapper[T]) UpdateLast(lastValue int64)

UpdateLast only update the internal state to the specified last (unwrapped) value.

Jump to

Keyboard shortcuts

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