fixedPoint

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 1 Imported by: 7

Documentation

Overview

Code generated by generators/genConstants.py; DO NOT EDIT.

Index

Constants

View Source
const (
	// The Div, Mul, and FMD functions support four rounding modes:
	//    RoundTowardZero: Returns the closest representable fixed-point value that has a magnitude
	//      less than or equal to the magnitude of the real result, effectively truncating the
	//      fractional part. e.g. 5e-8 / 2 = 2e-8, -5e-8 / 2 = -2e-8
	//    RoundAwayFromZero: Returns the closest representable fixed-point value that has a magnitude
	//      greater than or equal to the magnitude of the real result, effectively rounding up
	//      any fractional part. e.g. 5e-8 / 2 = 3e-8, -5e-8 / 2 = -3e-8
	//    RoundNearestHalfAway: Returns the closest representable fixed-point value to the real result,
	//      which could be larger (rounded up) or smaller (rounded down) depending on if the
	//      unrepresentable portion is greater than or less than one half the difference between two
	//      available values. If two representable values are equally close, the value will be rounded
	//      away from zero. e.g. 7e-8 / 2 = 4e-8, 5e-8 / 2 = 3e-8
	//    RoundNearestHalfEven: Returns the closest representable fixed-point value to the real result,
	//      which could be larger (rounded up) or smaller (rounded down) depending on if the
	//      unrepresentable portion is greater than or less than one half the difference between two
	//      available values. If two representable values are equally close, the value with an even
	//      digit in the smallest decimal place will be chosen. e.g. 7e-8 / 2 = 4e-8, 5e-8 / 2 = 2e-8
	//
	// Note that for ALL rounding modes when using signed inputs, the absolute value of the result
	// will be the same regardless of the sign of the inputs.
	//
	// In other words, for all rounding modes: abs(x / y) == abs(-x / y) == abs(x / -y) == abs(-x / -y)
	RoundTowardZero RoundingMode = iota
	RoundAwayFromZero
	RoundNearestHalfAway
	RoundNearestHalfEven

	RoundTruncate = RoundTowardZero
	RoundDown     = RoundTowardZero
	RoundUp       = RoundAwayFromZero
	RoundHalfUp   = RoundNearestHalfAway
	RoundHalfEven = RoundNearestHalfEven
)
View Source
const Fix128OneLeadingZeros = 48 // Number of leading zero bits for Fix128One
View Source
const Fix128Scale = 1E+24 // NOTE: Bigger than uint64! Mostly here as documentation...

Basic constants for Fix128 and UFix128

View Source
const Fix64HalfPi = Fix64(0x00000000095cd851)
View Source
const Fix64Max = Fix64(0x7fffffffffffffff) // Max value for Fix64
View Source
const Fix64Min = Fix64(0x8000000000000000) // Min value for Fix64
View Source
const Fix64One = Fix64(1 * Fix64Scale) // 1 in fix64
View Source
const Fix64OneLeadingZeros = 37 // Number of leading zero bits for Fix64One
View Source
const Fix64Pi = Fix64(0x0000000012b9b0a1)

Transcendental constants

View Source
const Fix64Scale = 1E+8

Basic constants for Fix64 and UFix64

View Source
const Fix64TwoPi = Fix64(0x0000000025736143)
View Source
const Fix64Zero = Fix64(0)
View Source
const UFix64Max = UFix64(0xffffffffffffffff) // Max value for UFix64
View Source
const UFix64One = UFix64(1 * Fix64Scale) // 1 in fix64
View Source
const UFix64Zero = UFix64(0)

Variables

View Source
var Fix128HalfPi = Fix128{Hi: 0x0000000000014ca1, Lo: 0x0a1cd055eb96585a}
View Source
var Fix128Max = Fix128{Hi: 0x7fffffffffffffff, Lo: 0xffffffffffffffff}
View Source
var Fix128Min = Fix128{Hi: 0x8000000000000000, Lo: 0x0000000000000000}
View Source
var Fix128One = Fix128{Hi: 0x000000000000d3c2, Lo: 0x1bcecceda1000000}
View Source
var Fix128Pi = Fix128{Hi: 0x0000000000029942, Lo: 0x1439a0abd72cb0b3}
View Source
var Fix128TwoPi = Fix128{Hi: 0x0000000000053284, Lo: 0x28734157ae596167}
View Source
var Fix128Zero = Fix128{Hi: 0x0000000000000000, Lo: 0x0000000000000000}
View Source
var UFix128Max = UFix128{Hi: 0xffffffffffffffff, Lo: 0xffffffffffffffff}
View Source
var UFix128One = UFix128{Hi: 0x000000000000d3c2, Lo: 0x1bcecceda1000000}
View Source
var UFix128Zero = UFix128{Hi: 0x0000000000000000, Lo: 0x0000000000000000}

Functions

This section is empty.

Types

type DivisionByZeroError

type DivisionByZeroError struct{}

func (DivisionByZeroError) Error

func (DivisionByZeroError) Error() string

type Fix128

type Fix128 raw128

func NewFix128

func NewFix128(hi, lo uint64) Fix128

func (Fix128) Abs

func (a Fix128) Abs() (UFix128, int64)

Abs returns the absolute value of `a` as an unsigned value, with a sign value as an int64. Note that this method works properly for Fix128Min, which can NOT be represented as a positive Fix128.

func (Fix128) Add

func (a Fix128) Add(b Fix128) (Fix128, error)

Add returns the sum of `a` and `b`, or an error on overflow or negative overflow.

func (Fix128) Cos

func (a Fix128) Cos() (Fix128, error)

func (Fix128) Div

func (a Fix128) Div(b Fix128, round RoundingMode) (Fix128, error)

Div returns the quotient of `a` and `b`, or an error on division by zero, overflow, or underflow.

func (Fix128) Eq

func (a Fix128) Eq(b Fix128) bool

func (Fix128) Exp

func (a Fix128) Exp() (UFix128, error)

Exp(a) returns `e^a`, or an error on overflow or underflow. Note that although the input is a Fix128, the output is a UFix128, since `e^a` is always positive.

func (Fix128) FMD

func (a Fix128) FMD(b, c Fix128, round RoundingMode) (Fix128, error)

FMD returns `a*b/c` without intermediate rounding, or an error on division by zero, overflow, or underflow.

func (Fix128) Gt

func (a Fix128) Gt(b Fix128) bool

func (Fix128) Gte

func (a Fix128) Gte(b Fix128) bool

func (Fix128) IsNeg

func (a Fix128) IsNeg() bool

IsNeg returns true if `a` is negative.

func (Fix128) IsZero

func (a Fix128) IsZero() bool

func (Fix128) Lt

func (a Fix128) Lt(b Fix128) bool

func (Fix128) Lte

func (a Fix128) Lte(b Fix128) bool

func (Fix128) Mod

func (a Fix128) Mod(b Fix128) (Fix128, error)

Mod returns the remainder of `a` divided by `b`, the result matches the sign of `a` (as per Go's % operator).

func (Fix128) Mul

func (a Fix128) Mul(b Fix128, round RoundingMode) (Fix128, error)

Mul returns the product of `a` and `b`, or an error on overflow or underflow.

func (Fix128) Neg

func (a Fix128) Neg() (Fix128, error)

Neg returns the additive inverse of `a` (i.e. -a), or a negative overflow error

func (Fix128) Sin

func (a Fix128) Sin() (Fix128, error)

func (Fix128) Sub

func (a Fix128) Sub(b Fix128) (Fix128, error)

Sub returns the difference of `a` and `b`, or an error on overflow or negative overflow.

func (Fix128) ToFix64

func (a Fix128) ToFix64(round RoundingMode) (Fix64, error)

ToFix64 converts a Fix128 to a Fix64, returns an error if the value can't be represented in Fix64, including overflow, negative overflow, and underflow cases.

type Fix64

type Fix64 raw64

func (Fix64) Abs

func (a Fix64) Abs() (UFix64, int64)

Abs returns the absolute value of `a` as an unsigned value, with a sign value as an int64. Note that this method works properly for Fix64Min, which can NOT be represented as a positive Fix64.

func (Fix64) Add

func (a Fix64) Add(b Fix64) (Fix64, error)

Add returns the sum of `a` and `b`, or an error on overflow or negative overflow.

func (Fix64) Cos

func (a Fix64) Cos() (Fix64, error)

func (Fix64) Div

func (a Fix64) Div(b Fix64, round RoundingMode) (Fix64, error)

Div returns the quotient of `a` and `b`, or an error on division by zero, overflow, or underflow.

func (Fix64) Eq

func (a Fix64) Eq(b Fix64) bool

func (Fix64) Exp

func (a Fix64) Exp() (UFix64, error)

Exp(a) returns `e^a`, or an error on overflow or underflow. Note that although the input is a Fix64, the output is a UFix64, since `e^a` is always positive.

func (Fix64) FMD

func (a Fix64) FMD(b, c Fix64, round RoundingMode) (Fix64, error)

FMD returns `a*b/c` without intermediate rounding, or an error on division by zero, overflow, or underflow.

func (Fix64) Gt

func (a Fix64) Gt(b Fix64) bool

func (Fix64) Gte

func (a Fix64) Gte(b Fix64) bool

func (Fix64) IsNeg

func (a Fix64) IsNeg() bool

IsNeg returns true if `a` is negative.

func (Fix64) IsZero

func (a Fix64) IsZero() bool

func (Fix64) Lt

func (a Fix64) Lt(b Fix64) bool

func (Fix64) Lte

func (a Fix64) Lte(b Fix64) bool

func (Fix64) Mod

func (a Fix64) Mod(b Fix64) (Fix64, error)

Mod returns the remainder of `a` divided by `b`, the result matches the sign of `a` (as per Go's % operator).

func (Fix64) Mul

func (a Fix64) Mul(b Fix64, round RoundingMode) (Fix64, error)

Mul returns the product of `a` and `b`, or an error on overflow or underflow.

func (Fix64) Neg

func (a Fix64) Neg() (Fix64, error)

Neg returns the additive inverse of `a` (i.e. -a), or a negative overflow error

func (Fix64) Sin

func (a Fix64) Sin() (Fix64, error)

func (Fix64) Sub

func (a Fix64) Sub(b Fix64) (Fix64, error)

Sub returns the difference of `a` and `b`, or an error on overflow or negative overflow.

func (Fix64) ToFix128

func (a Fix64) ToFix128() Fix128

ToFix128 converts a Fix64 to a Fix128, can't fail since Fix128 has a larger range than Fix64.

type NegativeOverflowError

type NegativeOverflowError struct{}

NegativeOverflowError is reported when the value is negative and has a magnitude that is too large to be represented using the given bit length.

func (NegativeOverflowError) Error

func (NegativeOverflowError) Error() string

type OutOfDomainErrorError

type OutOfDomainErrorError struct{}

func (OutOfDomainErrorError) Error

func (OutOfDomainErrorError) Error() string

type PositiveOverflowError

type PositiveOverflowError struct{}

PositiveOverflowError is reported when the value is positive and has a magnitude that is too large to be represented using the given bit length.

func (PositiveOverflowError) Error

func (PositiveOverflowError) Error() string

type RoundingMode

type RoundingMode int

Rounding modes

type UFix128

type UFix128 raw128

func NewUFix128

func NewUFix128(hi, lo uint64) UFix128

func (UFix128) Add

func (a UFix128) Add(b UFix128) (UFix128, error)

Add returns the sum of `a` and `b`, or an error on overflow.

func (UFix128) ApplySign

func (a UFix128) ApplySign(sign int64) (Fix128, error)

ApplySign converts a UFix128 to a Fix128, applying the sign specified by the input.

func (UFix128) Div

func (a UFix128) Div(b UFix128, round RoundingMode) (UFix128, error)

Div returns the quotient of `a` and `b`, or an error on division by zero, overflow, or underflow.

func (UFix128) Eq

func (a UFix128) Eq(b UFix128) bool

Eq returns true if `a` and `b` are equal.

func (UFix128) FMD

func (a UFix128) FMD(b, c UFix128, round RoundingMode) (UFix128, error)

FMD returns a*b/c without intermediate rounding, or an error on division by zero, overflow, or underflow.

func (UFix128) Gt

func (a UFix128) Gt(b UFix128) bool

Gt returns true if `a` is greater than `b`.

func (UFix128) Gte

func (a UFix128) Gte(b UFix128) bool

Gte returns true if `a` is greater than or equal to `b`.

func (UFix128) IsZero

func (a UFix128) IsZero() bool

IsZero returns true if `a` is zero.

func (UFix128) Ln

func (a UFix128) Ln() (Fix128, error)

func (UFix128) Lt

func (a UFix128) Lt(b UFix128) bool

Lt returns true if `a` is less than `b`

func (UFix128) Lte

func (a UFix128) Lte(b UFix128) bool

Lte returns true if `a` is less than or equal to `b`.

func (UFix128) Mod

func (a UFix128) Mod(b UFix128) (UFix128, error)

Mod returns the remainder of `a` divided by `b`, or an error on division by zero.

func (UFix128) Mul

func (a UFix128) Mul(b UFix128, round RoundingMode) (UFix128, error)

Mul returns the product of `a` and `b`, or an error on overflow or underflow.

func (UFix128) Pow

func (a UFix128) Pow(b Fix128) (UFix128, error)

func (UFix128) Sqrt

func (a UFix128) Sqrt(round RoundingMode) (UFix128, error)

Sqrt returns the square root of `a` using Newton-Rhaphson. Note that this method returns an error result for consistency with other methods, but can't actually ever fail...

func (UFix128) Sub

func (a UFix128) Sub(b UFix128) (UFix128, error)

Sub returns the difference of `a` and `b`, or an error on negative overflow.

func (UFix128) ToUFix64

func (a UFix128) ToUFix64(round RoundingMode) (UFix64, error)

ToUFix64 converts a UFix128 to a UFix64, returns an error if the value can't be represented in UFix64, including overflow and underflow cases.

type UFix64

type UFix64 raw64

Exported fixed-point types

func (UFix64) Add

func (a UFix64) Add(b UFix64) (UFix64, error)

Add returns the sum of `a` and `b`, or an error on overflow.

func (UFix64) ApplySign

func (a UFix64) ApplySign(sign int64) (Fix64, error)

ApplySign converts a UFix64 to a Fix64, applying the sign specified by the input.

func (UFix64) Div

func (a UFix64) Div(b UFix64, round RoundingMode) (UFix64, error)

Div returns the quotient of `a` and `b`, or an error on division by zero, overflow, or underflow.

func (UFix64) Eq

func (a UFix64) Eq(b UFix64) bool

Eq returns true if `a` and `b` are equal.

func (UFix64) FMD

func (a UFix64) FMD(b, c UFix64, round RoundingMode) (UFix64, error)

FMD returns a*b/c without intermediate rounding, or an error on division by zero, overflow, or underflow.

func (UFix64) Gt

func (a UFix64) Gt(b UFix64) bool

Gt returns true if `a` is greater than `b`.

func (UFix64) Gte

func (a UFix64) Gte(b UFix64) bool

Gte returns true if `a` is greater than or equal to `b`.

func (UFix64) IsZero

func (a UFix64) IsZero() bool

IsZero returns true if `a` is zero.

func (UFix64) Ln

func (a UFix64) Ln() (Fix64, error)

func (UFix64) Lt

func (a UFix64) Lt(b UFix64) bool

Lt returns true if `a` is less than `b`

func (UFix64) Lte

func (a UFix64) Lte(b UFix64) bool

Lte returns true if `a` is less than or equal to `b`.

func (UFix64) Mod

func (a UFix64) Mod(b UFix64) (UFix64, error)

Mod returns the remainder of `a` divided by `b`, or an error on division by zero.

func (UFix64) Mul

func (a UFix64) Mul(b UFix64, round RoundingMode) (UFix64, error)

Mul returns the product of `a` and `b`, or an error on overflow or underflow.

func (UFix64) Pow

func (a UFix64) Pow(b Fix64) (UFix64, error)

func (UFix64) Sqrt

func (a UFix64) Sqrt(round RoundingMode) (UFix64, error)

Sqrt returns the square root of `a` using Newton-Rhaphson. Note that this method returns an error result for consistency with other methods, but can't actually ever fail...

func (UFix64) Sub

func (a UFix64) Sub(b UFix64) (UFix64, error)

Sub returns the difference of `a` and `b`, or an error on negative overflow.

func (UFix64) ToUFix128

func (a UFix64) ToUFix128() UFix128

ToUFix128 converts a UFix64 to a UFix128, can't fail since UFix128 has a larger range than UFix64.

type UnderflowError

type UnderflowError struct{}

UnderflowError is reported when the magnitude of the value is too small to be represented using the given bit length.

func (UnderflowError) Error

func (UnderflowError) Error() string

Jump to

Keyboard shortcuts

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