Documentation ¶
Index ¶
- Variables
- func As[T xmath.Numeric](value Int) T
- func NewEvaluator(resolver eval.VariableResolver) *eval.Evaluator
- func ResetIfOutOfRangeInt(value, minValue, maxValue, defValue int) int
- type DP
- type Fraction
- type Int
- func ApplyRounding(value Int, roundDown bool) Int
- func EvaluateToNumber(expression string, resolver eval.VariableResolver) Int
- func Extract(in string) (value Int, remainder string)
- func From[T xmath.Numeric](value T) Int
- func FromString(value string) (Int, error)
- func FromStringForced(value string) Int
- func ResetIfOutOfRange(value, minValue, maxValue, defValue Int) Int
- type Length
- type LengthUnits
- func (enum LengthUnits) EnsureValid() LengthUnits
- func (enum LengthUnits) Format(length Length) string
- func (enum LengthUnits) Key() string
- func (enum LengthUnits) MarshalText() (text []byte, err error)
- func (enum LengthUnits) String() string
- func (enum LengthUnits) ToInches(length Int) Int
- func (enum *LengthUnits) UnmarshalText(text []byte) error
- type Weight
- type WeightUnits
- func (enum WeightUnits) EnsureValid() WeightUnits
- func (enum WeightUnits) Format(weight Weight) string
- func (enum WeightUnits) Key() string
- func (enum WeightUnits) MarshalText() (text []byte, err error)
- func (enum WeightUnits) String() string
- func (enum WeightUnits) ToPounds(weight Int) Int
- func (enum *WeightUnits) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( EvalOperators = eval.FixedOperators[DP](true) EvalFuncs = eval.FixedFunctions[DP]() )
The evaluator operators and functions that will be used when calling NewEvaluator().
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.
var AllLengthUnits = []LengthUnits{ FeetAndInches, Inch, Feet, Yard, Mile, Centimeter, Kilometer, Meter, }
AllLengthUnits holds all possible values.
var AllWeightUnits = []WeightUnits{ Pound, PoundAlt, Ounce, Ton, TonAlt, Kilogram, Gram, }
AllWeightUnits holds all possible values.
Functions ¶
func NewEvaluator ¶
func NewEvaluator(resolver eval.VariableResolver) *eval.Evaluator
NewEvaluator creates a new evaluator whose number type is an Int.
func ResetIfOutOfRangeInt ¶
ResetIfOutOfRangeInt checks the value and if it is lower than minValue or greater than maxValue, returns defValue, otherwise returns value.
Types ¶
type Fraction ¶
Fraction is an alias for the fixed-point fractional type we are using.
func NewFraction ¶
NewFraction creates a new fractional value from a string.
type Int ¶
Int is an alias for the fixed-point type we are using.
func ApplyRounding ¶
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 ¶
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 FromString ¶
FromString creates an Int from a string.
func FromStringForced ¶
FromStringForced creates an Int from a string, ignoring any conversion inaccuracies.
func ResetIfOutOfRange ¶
ResetIfOutOfRange checks the value and if it is lower than minValue or greater than maxValue, returns defValue, otherwise returns value.
type Length ¶ added in v5.16.2
type Length Int
Length contains a fixed-point value in inches. Conversions to/from metric are done using the simplified Length metric conversion of 1 yd = 1 meter. For consistency, all metric lengths are converted to meters, then to yards, rather than the variations at different lengths that the Length rules suggest.
func LengthFromInteger ¶ added in v5.16.2
func LengthFromInteger[T constraints.Integer](value T, unit LengthUnits) Length
LengthFromInteger creates a new Length.
func LengthFromString ¶ added in v5.16.2
func LengthFromString(text string, defaultUnits LengthUnits) (Length, error)
LengthFromString creates a new Length. May have any of the known Units suffixes, a feet and inches format (e.g. 6'2"), or no notation at all, in which case defaultUnits is used.
func LengthFromStringForced ¶ added in v5.16.2
func LengthFromStringForced(text string, defaultUnits LengthUnits) Length
LengthFromStringForced creates a new Length. May have any of the known Units suffixes, a feet and inches format (e.g. 6'2"), or no notation at all, in which case defaultUnits is used.
func (Length) MarshalJSON ¶ added in v5.16.2
MarshalJSON implements json.Marshaler.
func (*Length) UnmarshalJSON ¶ added in v5.16.2
UnmarshalJSON implements json.Unmarshaler.
type LengthUnits ¶ added in v5.16.2
type LengthUnits byte
LengthUnits holds the length unit type. Note that conversions to/from metric are done using the simplified GURPS metric conversion of 1 yd = 1 meter. For consistency, all metric lengths are converted to meters, then to yards, rather than the variations at different lengths that the GURPS rules suggest.
const ( FeetAndInches LengthUnits = iota Inch Feet Yard Mile Centimeter Kilometer Meter LastLengthUnits = Meter )
Possible values.
func ExtractLengthUnits ¶ added in v5.16.2
func ExtractLengthUnits(str string) LengthUnits
ExtractLengthUnits extracts the value from a string.
func (LengthUnits) EnsureValid ¶ added in v5.16.2
func (enum LengthUnits) EnsureValid() LengthUnits
EnsureValid ensures this is of a known value.
func (LengthUnits) Format ¶ added in v5.16.2
func (enum LengthUnits) Format(length Length) string
Format the length for this LengthUnits.
func (LengthUnits) Key ¶ added in v5.16.2
func (enum LengthUnits) Key() string
Key returns the key used in serialization.
func (LengthUnits) MarshalText ¶ added in v5.16.2
func (enum LengthUnits) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface.
func (LengthUnits) String ¶ added in v5.16.2
func (enum LengthUnits) String() string
String implements fmt.Stringer.
func (LengthUnits) ToInches ¶ added in v5.16.2
func (enum LengthUnits) ToInches(length Int) Int
ToInches converts the length in this LengthUnits to inches.
func (*LengthUnits) UnmarshalText ¶ added in v5.16.2
func (enum *LengthUnits) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Weight ¶ added in v5.16.2
type Weight Int
Weight contains a fixed-point value in pounds.
func WeightFromInteger ¶ added in v5.16.2
func WeightFromInteger[T constraints.Integer](value T, unit WeightUnits) Weight
WeightFromInteger creates a new Weight.
func WeightFromString ¶ added in v5.16.2
func WeightFromString(text string, defaultUnits WeightUnits) (Weight, error)
WeightFromString creates a new Weight. May have any of the known Weight suffixes or no notation at all, in which case defaultUnits is used.
func WeightFromStringForced ¶ added in v5.16.2
func WeightFromStringForced(text string, defaultUnits WeightUnits) Weight
WeightFromStringForced creates a new Weight. May have any of the known Weight suffixes or no notation at all, in which case defaultUnits is used.
func (Weight) MarshalJSON ¶ added in v5.16.2
MarshalJSON implements json.Marshaler.
func (*Weight) UnmarshalJSON ¶ added in v5.16.2
UnmarshalJSON implements json.Unmarshaler.
type WeightUnits ¶ added in v5.16.2
type WeightUnits byte
WeightUnits holds the weight unit type. Note that conversions to/from metric are done using the simplified GURPS metric conversion of 1 lb = 0.5kg. For consistency, all metric weights are converted to kilograms, then to pounds, rather than the variations at different weights that the GURPS rules suggest.
const ( Pound WeightUnits = iota PoundAlt Ounce Ton TonAlt Kilogram Gram LastWeightUnits = Gram )
Possible values.
func ExtractWeightUnits ¶ added in v5.16.2
func ExtractWeightUnits(str string) WeightUnits
ExtractWeightUnits extracts the value from a string.
func TrailingWeightUnitsFromString ¶ added in v5.16.2
func TrailingWeightUnitsFromString(s string, defUnits WeightUnits) WeightUnits
TrailingWeightUnitsFromString extracts a trailing WeightUnits from a string.
func (WeightUnits) EnsureValid ¶ added in v5.16.2
func (enum WeightUnits) EnsureValid() WeightUnits
EnsureValid ensures this is of a known value.
func (WeightUnits) Format ¶ added in v5.16.2
func (enum WeightUnits) Format(weight Weight) string
Format the weight for this WeightUnits.
func (WeightUnits) Key ¶ added in v5.16.2
func (enum WeightUnits) Key() string
Key returns the key used in serialization.
func (WeightUnits) MarshalText ¶ added in v5.16.2
func (enum WeightUnits) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface.
func (WeightUnits) String ¶ added in v5.16.2
func (enum WeightUnits) String() string
String implements fmt.Stringer.
func (WeightUnits) ToPounds ¶ added in v5.16.2
func (enum WeightUnits) ToPounds(weight Int) Int
ToPounds the weight for this WeightUnits.
func (*WeightUnits) UnmarshalText ¶ added in v5.16.2
func (enum *WeightUnits) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.