fxp

package
v5.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 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")
	Quarter       = FromStringForced("0.25")
	Half          = FromStringForced("0.5")
	One           = From(1)
	OneAndAHalf   = FromStringForced("1.5")
	Two           = From(2)
	Three         = From(3)
	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