fixed

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: MPL-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Max holds the maximum fixed-point value.
	Max = Fixed(1<<63 - 1)
	// Min holds the minimum fixed-point value.
	Min = Fixed(-1 << 63)
)

Variables

This section is empty.

Functions

func SetDigitsAfterDecimal

func SetDigitsAfterDecimal(digits int)

SetDigitsAfterDecimal controls the number of digits after the decimal place that are tracked. WARNING: This has a global effect on all fixed-point values and should only be set once prior to use of this package. Changes to this value invalidate any fixed-point values there were created prior to the call -- there is no enforcement of this, however, so use of a pre-existing value will quietly generate bad results.

Types

type Fixed

type Fixed int64

Fixed holds a fixed-point value that contains up to N decimal places, where N is the value passed to SetDigitsAfterDecimal (default is 4). 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 FromFloat64

func FromFloat64(value float64) Fixed

FromFloat64 creates a new fixed-point value from a float64.

func FromInt

func FromInt(value int) Fixed

FromInt creates a new fixed-point value from an int.

func New

func New(value float64) Fixed

New creates a new fixed-point value. Deprecated: Use FromFloat64() instead.

func Parse

func Parse(str string) (Fixed, error)

Parse a string to extract a fixed-point value from it.

func (Fixed) Comma

func (fxd Fixed) Comma() string

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

func (Fixed) Div

func (fxd Fixed) Div(value Fixed) Fixed

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

func (Fixed) Float64

func (fxd Fixed) Float64() float64

Float64 returns the floating-point equivalent to this fixed-point value.

func (Fixed) Int64

func (fxd Fixed) Int64() int64

Int64 returns the truncated equivalent integer to this fixed-point value.

func (*Fixed) MarshalJSON

func (fxd *Fixed) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. Note that this intentionally generates a string where necessary to ensure the correct value is retained.

func (*Fixed) MarshalText

func (fxd *Fixed) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Fixed) MarshalYAML

func (fxd Fixed) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface. Note that this intentionally generates a string where necessary to ensure the correct value is retained.

func (Fixed) Mul

func (fxd Fixed) Mul(value Fixed) Fixed

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

func (Fixed) String

func (fxd Fixed) String() string

func (Fixed) Trunc

func (fxd Fixed) Trunc() Fixed

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

func (*Fixed) UnmarshalJSON

func (fxd *Fixed) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Fixed) UnmarshalText

func (fxd *Fixed) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Fixed) UnmarshalYAML

func (fxd *Fixed) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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