math

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 3 Imported by: 1

README

GoDoc Build Status Coverage Status Report Card

Documentation

Overview

Package math provides math-related utilities.

Index

Constants

View Source
const Version = "v0.3.3"

Version is the current version of the math package.

Variables

This section is empty.

Functions

func Abs

func Abs[T SignedNumeric](x T) T

Abs returns the absolute value of the given signed number.

func Clamp added in v0.1.0

func Clamp[T Numeric](x T, min T, max T) T

Clamp clamps the given value between [min,max] (inclusive).

func ClampMax added in v0.2.2

func ClampMax[T Numeric](x T, max T) T

ClampMax clamps the given value such that it is not greater than max (inclusive).

func ClampMin added in v0.2.2

func ClampMin[T Numeric](x T, min T) T

ClampMin clamps the given value such that it is not less than min (inclusive).

func ClosestPowerOf2 added in v0.2.0

func ClosestPowerOf2[T Numeric](x T) T

ClosestPowerOf2 returns the next T greater than x that is a power of 2.

func Fastrand added in v0.2.0

func Fastrand[T Unsigned32]() T

Fastrand returns a pseudorandom T in the range [0, 1<<32-1).

func Fastrandn added in v0.2.0

func Fastrandn[T Unsigned32](x T) T

Fastrandn returns a pseudorandom T in the range [0, min(x, 1<<32-1)). If x is greater than 1<<32-1, it will be clamped.

func Max

func Max[T Numeric](x T, y T) T

Max returns the maximum value of the two given numbers.

func MaxN added in v0.1.0

func MaxN[T Numeric](x ...T) T

MaxN returns the maximum value of the given numbers.

func Mean

func Mean[T Numeric](x ...T) T

Mean returns the truncated average value of all given numbers.

func MeanFloat64

func MeanFloat64[T Numeric](x ...T) float64

MeanFloat64 returns the average value of all given numbers.

func Min

func Min[T Numeric](x T, y T) T

Min returns the minimum value of the two given numbers.

func MinN added in v0.1.0

func MinN[T Numeric](x ...T) T

MinN returns the minimum value of the given numbers.

func NextPowerOf2 added in v0.2.0

func NextPowerOf2[T Numeric](x T) T

NextPowerOf2 returns the next T greater than x that is a power of 2. If x is a power of 2 itself, x is returned.

func Precision added in v0.3.1

func Precision[T constraints.Float](x T, precision int) T

Precision truncates x to the given precision. If precision is < 0, x is returned unchanged; if x == 0, x is rounded to the nearest integer; otherwise, the precision of x is changed and the resulting value rounded.

Types

type Numeric added in v0.1.0

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

Numeric is a constraint that permits any integer or floating point number.

type SignedNumeric added in v0.1.0

type SignedNumeric interface {
	constraints.Signed | constraints.Float
}

SignedNumeric is a constraint that permits any signed integer or floating point number.

type Unsigned32 added in v0.2.0

type Unsigned32 interface {
	~int | ~int64 | ~uint | ~uint32 | ~uint64 | constraints.Float
}

Unsigned32 is a constraint that permits any type that can fit a 32-bit unsigned integer.

Jump to

Keyboard shortcuts

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