Documentation
¶
Overview ¶
Package detmath provides FMA-free deterministic math helpers and canonical state hashing shared by physics, physics3d, and vehicle.
Go's arm64 compiler automatically contracts x*y+z into single-rounding FMADD instructions unless an explicit float32/float64 conversion separates the multiply from the add, whereas amd64 uses separate multiply and add instructions. Go's standard library math.Sin, math.Cos, math.Atan2, math.Acos, math.Tan, and math.Hypot also compile with FMADD/FMSUB on arm64. Every function in this package inserts explicit conversions around products so arm64, amd64, and wasm execute identical IEEE-754 rounding bit-for-bit.
Index ¶
- func Acos(x float64) float64
- func Atan(x float64) float64
- func Atan2(y, x float64) float64
- func Cos(x float64) float64
- func Float32Bits(v float32) uint32
- func Float64Bits(v float64) uint64
- func Hypot(p, q float64) float64
- func MulAdd32(a, b, c float32) float32
- func MulAdd64(a, b, c float64) float64
- func MulSub32(a, b, c float32) float32
- func MulSub64(a, b, c float64) float64
- func Sin(x float64) float64
- func Sincos(x float64) (sin, cos float64)
- func Tan(x float64) float64
- type Hasher
- func (h *Hasher) Sum64() uint64
- func (h *Hasher) WriteBool(v bool)
- func (h *Hasher) WriteFloat32(v float32)
- func (h *Hasher) WriteFloat64(v float64)
- func (h *Hasher) WriteInt(v int)
- func (h *Hasher) WriteString(s string)
- func (h *Hasher) WriteUint8(v uint8)
- func (h *Hasher) WriteUint32(v uint32)
- func (h *Hasher) WriteUint64(v uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Atan2 ¶
Atan2 returns the arc tangent of y/x using the signs of both to determine the quadrant, without FMA contraction.
func Float32Bits ¶
Float32Bits returns canonical IEEE-754 bits for hashing: -0.0 maps to +0.0 and any NaN maps to a single quiet NaN bit pattern.
func Float64Bits ¶
Float64Bits returns canonical IEEE-754 bits for hashing: -0.0 maps to +0.0 and any NaN maps to a single quiet NaN bit pattern.
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a zero-allocation streaming 64-bit FNV-1a hasher for deterministic physics world checksums.
func NewHasher ¶
func NewHasher() Hasher
NewHasher returns a new FNV-1a Hasher initialized with the standard 64-bit offset basis.
func (*Hasher) WriteFloat32 ¶
WriteFloat32 mixes canonical IEEE-754 float32 bits into the hash.
func (*Hasher) WriteFloat64 ¶
WriteFloat64 mixes canonical IEEE-754 float64 bits into the hash.
func (*Hasher) WriteInt ¶
WriteInt mixes an int as a fixed-width int64 so 32-bit and 64-bit targets agree.
func (*Hasher) WriteString ¶
WriteString mixes the length and bytes of s into the hash.
func (*Hasher) WriteUint8 ¶
WriteUint8 mixes one byte into the hash.
func (*Hasher) WriteUint32 ¶
WriteUint32 mixes a little-endian uint32 into the hash.
func (*Hasher) WriteUint64 ¶
WriteUint64 mixes a little-endian uint64 into the hash.