f64

package
v0.0.0-...-883d5d7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Max holds the maximum value.
	Max = math.MaxInt64
	// Min holds the minimum value.
	Min = math.MinInt64
)

Variables

This section is empty.

Functions

func As

func As[T fixed.Dx, TO xmath.Numeric](f Int[T]) TO

As returns the equivalent value in the destination type.

func CheckedAs

func CheckedAs[T fixed.Dx, TO xmath.Numeric](f Int[T]) (TO, error)

CheckedAs is the same as As(), except that it returns an error if the value cannot be represented exactly in the requested destination type.

func MaxDecimalDigits

func MaxDecimalDigits[T fixed.Dx]() int

MaxDecimalDigits returns the maximum number of digits after the decimal that will be used.

func Multiplier

func Multiplier[T fixed.Dx]() int64

Multiplier returns the multiplier used.

Types

type Fraction

type Fraction[T fixed.Dx] struct {
	Numerator   Int[T]
	Denominator Int[T]
}

Fraction holds a fractional value.

func NewFraction

func NewFraction[T fixed.Dx](s string) Fraction[T]

NewFraction creates a new fractional value from a string.

func (Fraction[T]) MarshalJSON

func (f Fraction[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Fraction[T]) Normalize

func (f *Fraction[T]) Normalize()

Normalize the fraction, eliminating any division by zero and ensuring a positive denominator.

func (Fraction[T]) String

func (f Fraction[T]) String() string

func (Fraction[T]) StringWithSign

func (f Fraction[T]) StringWithSign() string

StringWithSign returns the same as String(), but prefixes the value with a '+' if it is positive.

func (*Fraction[T]) UnmarshalJSON

func (f *Fraction[T]) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (Fraction[T]) Value

func (f Fraction[T]) Value() Int[T]

Value returns the computed value.

type Int

type Int[T fixed.Dx] int64

Int holds a fixed-point value. Values are truncated, not rounded. Values can be added and subtracted directly. For multiplication and division, the provided Mul() and Div() methods should be used.

func From

func From[T fixed.Dx, FROM xmath.Numeric](value FROM) Int[T]

From creates a new value.

func FromString

func FromString[T fixed.Dx](str string) (Int[T], error)

FromString creates a new value from a string.

func FromStringForced

func FromStringForced[T fixed.Dx](str string) Int[T]

FromStringForced creates a new value from a string.

func MaxSafeMultiply

func MaxSafeMultiply[T fixed.Dx]() Int[T]

MaxSafeMultiply returns the maximum value that can be safely multiplied without overflow.

func (Int[T]) Abs

func (f Int[T]) Abs() Int[T]

Abs returns the absolute value of this value.

func (Int[T]) Add

func (f Int[T]) Add(value Int[T]) Int[T]

Add adds this value to the passed-in value, returning a new value. Note that this method is only provided to make text templates easier to use with these objects, since you can just add two Int[T] values together like they were primitive types.

func (Int[T]) Ceil

func (f Int[T]) Ceil() Int[T]

Ceil returns the value rounded up to the nearest whole number.

func (Int[T]) Comma

func (f Int[T]) Comma() string

Comma returns the same as String(), but with commas for values of 1000 and greater.

func (Int[T]) CommaWithSign

func (f Int[T]) CommaWithSign() string

CommaWithSign returns the same as Comma(), but prefixes the value with a '+' if it is positive

func (Int[T]) Dec

func (f Int[T]) Dec() Int[T]

Dec returns the value decremented by 1.

func (Int[T]) Div

func (f Int[T]) Div(value Int[T]) Int[T]

Div divides this value by the passed-in value, returning a new value.

func (Int[T]) Inc

func (f Int[T]) Inc() Int[T]

Inc returns the value incremented by 1.

func (Int[T]) MarshalJSON

func (f Int[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Int[T]) MarshalText

func (f Int[T]) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Int[T]) MarshalYAML

func (f Int[T]) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler.

func (Int[T]) Max

func (f Int[T]) Max(value Int[T]) Int[T]

Max returns the maximum of this value or its argument.

func (Int[T]) Min

func (f Int[T]) Min(value Int[T]) Int[T]

Min returns the minimum of this value or its argument.

func (Int[T]) Mod

func (f Int[T]) Mod(value Int[T]) Int[T]

Mod returns the remainder after subtracting all full multiples of the passed-in value.

func (Int[T]) Mul

func (f Int[T]) Mul(value Int[T]) Int[T]

Mul multiplies this value by the passed-in value, returning a new value.

func (Int[T]) Round

func (f Int[T]) Round() Int[T]

Round returns the nearest integer, rounding half away from zero.

func (Int[T]) String

func (f Int[T]) String() string

func (Int[T]) StringWithSign

func (f Int[T]) StringWithSign() string

StringWithSign returns the same as String(), but prefixes the value with a '+' if it is positive

func (Int[T]) Sub

func (f Int[T]) Sub(value Int[T]) Int[T]

Sub subtracts the passed-in value from this value, returning a new value. Note that this method is only provided to make text templates easier to use with these objects, since you can just subtract two Int[T] values together like they were primitive types.

func (Int[T]) Trunc

func (f Int[T]) Trunc() Int[T]

Trunc returns a new value which has everything to the right of the decimal place truncated.

func (*Int[T]) UnmarshalJSON

func (f *Int[T]) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Int[T]) UnmarshalText

func (f *Int[T]) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Int[T]) UnmarshalYAML

func (f *Int[T]) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler.

Jump to

Keyboard shortcuts

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