fxp

package
v5.10.4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MPL-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EvalOperators = eval.FixedOperators[DP](true)
	EvalFuncs     = eval.FixedFunctions[DP]()
)

The evaluator operators and functions that will be used when calling NewEvaluator().

View Source
var (
	Min            = Int(f64.Min)
	NegPointEight  = FromStringForced("-0.8")
	Twentieth      = FromStringForced("0.05")
	PointZeroSix   = FromStringForced("0.06")
	PointZeroSeven = FromStringForced("0.07")
	PointZeroEight = FromStringForced("0.08")
	PointZeroNine  = FromStringForced("0.09")
	Tenth          = FromStringForced("0.1")
	PointOneTwo    = FromStringForced("0.12")
	Eighth         = FromStringForced("0.125")
	PointOneFive   = FromStringForced("0.15")
	Fifth          = FromStringForced("0.2")
	Quarter        = FromStringForced("0.25")
	ThreeTenths    = FromStringForced("0.3")
	TwoFifths      = FromStringForced("0.4")
	Half           = FromStringForced("0.5")
	ThreeFifths    = FromStringForced("0.6")
	SevenTenths    = FromStringForced("0.7")
	ThreeQuarters  = FromStringForced("0.75")
	FourFifths     = FromStringForced("0.8")
	One            = From(1)
	OnePointOne    = FromStringForced("1.1")
	OnePointTwo    = FromStringForced("1.2")
	OneAndAQuarter = FromStringForced("1.25")
	OneAndAHalf    = FromStringForced("1.5")
	Two            = From(2)
	TwoAndAHalf    = FromStringForced("2.5")
	Three          = From(3)
	ThreeAndAHalf  = FromStringForced("3.5")
	Four           = From(4)
	Five           = From(5)
	Six            = From(6)
	Seven          = From(7)
	Eight          = From(8)
	Nine           = From(9)
	Ten            = From(10)
	Twelve         = From(12)
	Fifteen        = From(15)
	Nineteen       = From(19)
	Twenty         = From(20)
	TwentyFour     = From(24)
	ThirtySix      = From(36)
	Thirty         = From(30)
	Forty          = From(40)
	Fifty          = From(50)
	Seventy        = From(70)
	Eighty         = From(80)
	NinetyNine     = From(99)
	Hundred        = From(100)
	Thousand       = From(1000)
	MaxBasePoints  = From(999999)
	Max            = Int(f64.Max)
)

Common values that can be reused.

Functions

func As

func As[T xmath.Numeric](value Int) T

As returns the equivalent value in the destination type.

func NewEvaluator

func NewEvaluator(resolver eval.VariableResolver) *eval.Evaluator

NewEvaluator creates a new evaluator whose number type is an Int.

func ResetIfOutOfRangeInt

func ResetIfOutOfRangeInt(value, min, max, def int) int

ResetIfOutOfRangeInt checks the value and if it is lower than min or greater than max, returns def, otherwise returns value.

Types

type DP

type DP = fixed.D4

DP is an alias for the fixed-point decimal places configuration we are using.

type Fraction

type Fraction = f64.Fraction[DP]

Fraction is an alias for the fixed-point fractional type we are using.

func NewFraction

func NewFraction(str string) Fraction

NewFraction creates a new fractional value from a string.

type Int

type Int = f64.Int[DP]

Int is an alias for the fixed-point type we are using.

func ApplyRounding

func ApplyRounding(value Int, roundDown bool) Int

ApplyRounding rounds in the positive direction of roundDown is false, or in the negative direction if roundDown is true.

func EvaluateToNumber

func EvaluateToNumber(expression string, resolver eval.VariableResolver) Int

EvaluateToNumber evaluates the provided expression and returns a number.

func Extract

func Extract(in string) (value Int, remainder string)

Extract a leading value from a string. If a value is found, it is returned along with the portion of the string that was unused. If a value is not found, then 0 is returned along with the original string.

func From

func From[T xmath.Numeric](value T) Int

From creates an Int from a numeric value.

func FromString

func FromString(value string) (Int, error)

FromString creates an Int from a string.

func FromStringForced

func FromStringForced(value string) Int

FromStringForced creates an Int from a string, ignoring any conversion inaccuracies.

func ResetIfOutOfRange

func ResetIfOutOfRange(value, min, max, def Int) Int

ResetIfOutOfRange checks the value and if it is lower than min or greater than max, returns def, otherwise returns value.

Jump to

Keyboard shortcuts

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