math

package
v0.0.0-...-4cea4d0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2014 License: BSD-2-Clause Imports: 1 Imported by: 2

Documentation

Overview

Package GLaM Math provides fast float32 math functions.

Index

Constants

View Source
const (
	E   = float32(2.71828182845904523536028747135266249775724709369995957496696763) // A001113
	Pi  = float32(3.14159265358979323846264338327950288419716939937510582097494459) // A000796
	Phi = float32(1.61803398874989484820458683436563811772030917980576286213544862) // A001622

	Sqrt2   = float32(1.41421356237309504880168872420969807856967187537694807317667974) // A002193
	SqrtE   = float32(1.64872127070012814684865078781416357165377610071014801157507931) // A019774
	SqrtPi  = float32(1.77245385090551602729816748334114518279754945612238712821380779) // A002161
	SqrtPhi = float32(1.27201964951406896425242246173749149171560804184009624861664038) // A139339

	Ln2    = float32(0.693147180559945309417232121458176568075500134360255254120680009) // A002162
	Log2E  = float32(1 / Ln2)
	Ln10   = float32(2.30258509299404568401799145468436420760110148862877297603332790) // A002392
	Log10E = float32(1 / Ln10)
)

Mathematical constants. Reference: http://oeis.org/Axxxxxx

View Source
const (
	MaxFloat32             = float32(3.40282346638528859811704183484516925440e+38)  // 2**127 * (2**24 - 1) / 2**23
	SmallestNormalFloat32  = float32(1.17549435082229e-38)                          // 1 / 2**(127 - 1)
	EpsilonFloat32         = float32(1.19209290e-07)                                // 1 / 2**23
	SmallestNonzeroFloat32 = float32(1.401298464324817070923729583289916131280e-45) // 1 / 2**(127 - 1 + 23)

	MaxFloat64             = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52
	SmallestNormalFloat64  = 2.2250738585072014e-308                        // 1 / 2**(1023 - 1)
	EpsilonFloat64         = 2.2204460492503131e-16                         // 1 / 2**52
	SmallestNonzeroFloat64 = 4.940656458412465441765687928682213723651e-324 // 1 / 2**(1023 - 1 + 52)
)

Floating-point limit values. `Max` is the largest finite value representable by the type. `SmallestNormal` is the smallest normal value representable by the type. `Epsilon` is the smallest value that, when added to one, yields a result different from one. `SmallestNonzero` is the smallest positive, non-zero value representable by the type.

View Source
const (
	MaxInt8   = 1<<7 - 1
	MinInt8   = -1 << 7
	MaxInt16  = 1<<15 - 1
	MinInt16  = -1 << 15
	MaxInt32  = 1<<31 - 1
	MinInt32  = -1 << 31
	MaxInt64  = 1<<63 - 1
	MinInt64  = -1 << 63
	MaxUint8  = 1<<8 - 1
	MaxUint16 = 1<<16 - 1
	MaxUint32 = 1<<32 - 1
	MaxUint64 = 1<<64 - 1
)

Integer limit values.

Variables

This section is empty.

Functions

func Abs

func Abs(x float32) float32

`Abs` returns the absolute value of `x`.

func Cos

func Cos(x float32) float32

`Cos` returns the sinus of `x`.

func FastCos

func FastCos(x float32) float32

`FastCos` returns an approximation of `sin(x)`.

Max absolute error in range [-Pi, Pi]: less than 1e-3

Faster than `Cos`.

func FastFloor

func FastFloor(x float32) int32

`FastFloor` returns `int32(x)` if `x`>0, `int32(x-1)` otherwise.

func FastSin

func FastSin(x float32) float32

`FastSin` returns an approximation of `sin(x)`.

Max absolute error in range [-Pi, Pi]: less than 1e-3

Faster than `Sin`.

func Float32bits

func Float32bits(f float32) uint32

`Float32bits` returns the IEEE 754 binary representation of `f`.

func Float32frombits

func Float32frombits(b uint32) float32

`Float32frombits` returns the floating point number corresponding to the IEEE 754 binary representation `b`.

func Float64bits

func Float64bits(f float64) uint64

`Float64bits` returns the IEEE 754 binary representation of `f`.

func Float64frombits

func Float64frombits(b uint64) float64

`Float64frombits` returns the floating point number corresponding the IEEE 754 binary representation `b`.

func Floor

func Floor(x float32) float32

`Floor` returns the nearest integer less than or equal to `x`.

func Inf

func Inf(sign int) float32

`Inf` returns positive infinity if `sign` >= 0, negative infinity if `sign` < 0.

func IsAlmostEqual

func IsAlmostEqual(a, b float32, ulps uint32) bool

`IsAlmostEqual` returns true if the difference between `a` and `b` in ULPs (Unit in the Last Place) is less than `ulps`.

Handle special cases: zero, infinites, denormals.

See also `IsNearlyEqual` and `IsRoughlyEqual`.

func IsInf

func IsInf(f float32, sign int) bool

`IsInf` returns whether `f` is an infinity, according to `sign`. If `sign` > 0, `IsInf` returns whether `f` is positive infinity. If `sign` < 0, `IsInf` returns whether `f` is negative infinity. If `sign` == 0, `IsInf` returns whether `f` is either infinity.

func IsNaN

func IsNaN(f float32) (is bool)

`IsNaN` returns whether f is an IEEE 754 "not-a-number" value.

func IsNearlyEqual

func IsNearlyEqual(a, b float32, epsilon float32) bool

`IsNearlyEqual` Returns true if the relative error between `a` and `b` is less than `epsilon`.

Handles special cases: zero, infinites, denormals.

See also `IsAlmostEqual` and `IsRoughlyEqual`.

func IsRoughlyEqual

func IsRoughlyEqual(a, b float32, epsilon float32) bool

`IsRoughlyEqual` Returns true if the absolute error between `a` and `b` is less than `epsilon`.

See also `IsNearlyEqual` and `IsAlmostEqual`.

func Mix

func Mix(x, y float32, a float32) float32

`Mix` returns the linear interpolation between `x` and `y` using `a` to weight between them. The value is computed as follows: `x*(1-a) + y*a`

func NaN

func NaN() float32

`NaN` returns an IEEE 754 "not-a-number" value.

func Normalized

func Normalized(x float32) (y float32, exp int)

`Normalized` returns a normal number `y` and exponent `exp` satisfying `x == y × 2**exp`. It assumes `x` is finite and non-zero.

func Round

func Round(x float32) int32

`Round` returns the nearest integer to `x`.

func Sin

func Sin(x float32) float32

`Sin` returns the sinus of `x`.

func Sqrt

func Sqrt(x float32) float32

`Sqrt` returns the square root of `x`.

func Tan

func Tan(x float32) float32

`Tan` returns the tangent of `x`.

Types

This section is empty.

Jump to

Keyboard shortcuts

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