Documentation
¶
Index ¶
- Variables
- func As[T xmath.Numeric](value Int) T
- type DP
- type Int
- type Length
- type LengthUnit
- func (enum LengthUnit) EnsureValid() LengthUnit
- func (enum LengthUnit) Format(length Length) string
- func (enum LengthUnit) Key() string
- func (enum LengthUnit) MarshalText() (text []byte, err error)
- func (enum LengthUnit) String() string
- func (enum LengthUnit) ToInches(length Int) Int
- func (enum *LengthUnit) UnmarshalText(text []byte) error
- type Weight
- type WeightUnit
- func (enum WeightUnit) EnsureValid() WeightUnit
- func (enum WeightUnit) Format(weight Weight) string
- func (enum WeightUnit) Key() string
- func (enum WeightUnit) MarshalText() (text []byte, err error)
- func (enum WeightUnit) String() string
- func (enum WeightUnit) ToPounds(weight Int) Int
- func (enum *WeightUnit) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( Fifth = FromStringForced("0.2") Quarter = FromStringForced("0.25") ThreeTenths = FromStringForced("0.3") Half = FromStringForced("0.5") One = From(1) Two = From(2) Three = From(3) Four = From(4) Five = From(5) Six = From(6) Seven = From(7) Eight = From(8) Nine = From(9) Twelve = From(12) Thirteen = From(13) Sixteen = From(16) ThirtySix = From(36) Hundred = From(100) FiveHundred = From(500) TwoThousand = From(2000) ThirtySixThousand = From(36000) MileInInches = From(63360) )
Common values that can be reused.
var LengthUnits = []LengthUnit{ FeetAndInches, Inch, Feet, Yard, Mile, Centimeter, Kilometer, Meter, }
LengthUnits holds all possible values.
var WeightUnits = []WeightUnit{ Pound, PoundAlt, Ounce, Ton, TonAlt, Kilogram, Gram, }
WeightUnits holds all possible values.
Functions ¶
Types ¶
type Int ¶
Int is an alias for the fixed-point type we are using.
func FromString ¶
FromString creates an Int from a string.
func FromStringForced ¶
FromStringForced creates an Int from a string, ignoring any conversion inaccuracies.
type Length ¶
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 ¶
func LengthFromInteger[T constraints.Integer](value T, unit LengthUnit) Length
LengthFromInteger creates a new Length.
func LengthFromString ¶
func LengthFromString(text string, defaultUnits LengthUnit) (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 (Length) MarshalText ¶
func (*Length) UnmarshalText ¶
type LengthUnit ¶
type LengthUnit byte
LengthUnit 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 LengthUnit = iota Inch Feet Yard Mile Centimeter Kilometer Meter )
Possible values.
const LastLengthUnit LengthUnit = Meter
LastLengthUnit is the last valid value.
func ExtractLengthUnit ¶
func ExtractLengthUnit(str string) LengthUnit
ExtractLengthUnit extracts the value from a string.
func (LengthUnit) EnsureValid ¶
func (enum LengthUnit) EnsureValid() LengthUnit
EnsureValid ensures this is of a known value.
func (LengthUnit) Format ¶
func (enum LengthUnit) Format(length Length) string
Format the length for this LengthUnit.
func (LengthUnit) Key ¶
func (enum LengthUnit) Key() string
Key returns the key used in serialization.
func (LengthUnit) MarshalText ¶
func (enum LengthUnit) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface.
func (LengthUnit) ToInches ¶
func (enum LengthUnit) ToInches(length Int) Int
ToInches converts the length in this LengthUnit to inches.
func (*LengthUnit) UnmarshalText ¶
func (enum *LengthUnit) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Weight ¶
type Weight Int
Weight contains a fixed-point value in pounds.
func WeightFromString ¶
func WeightFromString(text string, defaultUnits WeightUnit) (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 (Weight) MarshalText ¶
func (*Weight) UnmarshalText ¶
type WeightUnit ¶
type WeightUnit byte
WeightUnit 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 WeightUnit = iota PoundAlt Ounce Ton TonAlt Kilogram Gram )
Possible values.
const LastWeightUnit WeightUnit = Gram
LastWeightUnit is the last valid value.
func ExtractWeightUnit ¶
func ExtractWeightUnit(str string) WeightUnit
ExtractWeightUnit extracts the value from a string.
func (WeightUnit) EnsureValid ¶
func (enum WeightUnit) EnsureValid() WeightUnit
EnsureValid ensures this is of a known value.
func (WeightUnit) Format ¶
func (enum WeightUnit) Format(weight Weight) string
Format the weight for this WeightUnit.
func (WeightUnit) Key ¶
func (enum WeightUnit) Key() string
Key returns the key used in serialization.
func (WeightUnit) MarshalText ¶
func (enum WeightUnit) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface.
func (WeightUnit) ToPounds ¶
func (enum WeightUnit) ToPounds(weight Int) Int
ToPounds the weight for this WeightUnit.
func (*WeightUnit) UnmarshalText ¶
func (enum *WeightUnit) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.