fxp

package
v0.0.0-...-0bb4724 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

LengthUnits holds all possible values.

View Source
var WeightUnits = []WeightUnit{
	Pound,
	PoundAlt,
	Ounce,
	Ton,
	TonAlt,
	Kilogram,
	Gram,
}

WeightUnits holds all possible values.

Functions

func As

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

As returns the equivalent value in the destination type.

Types

type DP

type DP = fixed.D4

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

type Int

type Int = f64.Int[DP]

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

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.

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 (l Length) MarshalText() ([]byte, error)

func (Length) String

func (l Length) String() string

func (*Length) UnmarshalText

func (l *Length) UnmarshalText(in []byte) error

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) String

func (enum LengthUnit) String() string

String implements fmt.Stringer.

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 (w Weight) MarshalText() ([]byte, error)

func (Weight) String

func (w Weight) String() string

func (*Weight) UnmarshalText

func (w *Weight) UnmarshalText(in []byte) error

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) String

func (enum WeightUnit) String() string

String implements fmt.Stringer.

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.

Jump to

Keyboard shortcuts

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