math

package
v0.0.0-...-124f97e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MinNormal = float32(1.1754943508222875e-38) // 1 / 2**(127 - 1)
	MinValue  = float32(math.SmallestNonzeroFloat32)
	MaxValue  = float32(math.MaxFloat32)

	InfPos = float32(math.Inf(1))
	InfNeg = float32(math.Inf(-1))
	NaN    = float32(math.NaN())

	E       = float32(math.E)
	Pi      = float32(math.Pi)
	PiOver2 = Pi / 2
	PiOver4 = Pi / 4
	Sqrt2   = float32(math.Sqrt2)

	Epsilon = float32(1e-10)
)

Various useful constants.

Functions

func Abs

func Abs[T constraints.Float | constraints.Integer](v T) T

Abs returns the absolute value of a number

func Acos

func Acos(x float32) float32

func Asin

func Asin(x float32) float32

func Atan2

func Atan2(y, x float32) float32

func Ceil

func Ceil(x float32) float32

Ceil a number to the closest integer

func Clamp

func Clamp[T constraints.Ordered](v, min, max T) T

Clamp a value between a minimum and a maximum value

func Copysign

func Copysign(f, sign float32) float32

func Cos

func Cos(x float32) float32

Cos computes the cosine of x

func DegToRad

func DegToRad(deg float32) float32

DegToRad converts degrees to radians

func Equal

func Equal(a, b float32) bool

Equal checks two floats for (approximate) equality

func EqualThreshold

func EqualThreshold(a, b, epsilon float32) bool

EqualThreshold is a utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

This differs from FloatEqual in that it lets you pass in your comparison threshold, so that you can adjust the comparison value to your specific needs

func Floor

func Floor(x float32) float32

Floor a number to the closest integer

func Lerp

func Lerp(a, b, f float32) float32

Lerp performs linear interpolation between a and b

func Max

func Max[T constraints.Ordered](a, b T) T

Max returns the greater of two numbers

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the smaller of two numbers

func Mod

func Mod(x, y float32) float32

Mod returns the remainder of a floating point division

func Pow

func Pow(f, x float32) float32

func RadToDeg

func RadToDeg(rad float32) float32

RadToDeg converts radians to degrees

func Round

func Round(f float32) float32

func Sign

func Sign(x float32) float32

Sign returns the sign of x (-1 or 1)

func Sin

func Sin(x float32) float32

Sin computes the sine of x

func Sincos

func Sincos(x float32) (float32, float32)

func Snap

func Snap(f, multiple float32) float32

func Sqrt

func Sqrt(x float32) float32

Sqrt returns the square root of a number

func Tan

func Tan(x float32) float32

Tan computes the tangent of x

Types

type Noise

type Noise struct {
	opensimplex.Noise
	Seed int
	Freq float32
}

Noise utility to sample simplex noise

func NewNoise

func NewNoise(seed int, freq float32) *Noise

NewNoise creates a new noise struct from a seed value and a frequency factor.

func (*Noise) Sample

func (n *Noise) Sample(x, y, z int) float32

Sample the noise at a certain position

Directories

Path Synopsis
Based on code from github.com/go-gl/mathgl: Copyright 2014 The go-gl Authors.
Based on code from github.com/go-gl/mathgl: Copyright 2014 The go-gl Authors.
Based on code from github.com/go-gl/mathgl: Copyright 2014 The go-gl Authors.
Based on code from github.com/go-gl/mathgl: Copyright 2014 The go-gl Authors.

Jump to

Keyboard shortcuts

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