fixedn

package
v0.96.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2021 License: MIT Imports: 6 Imported by: 42

Documentation

Overview

Package fixedn implements fixed point integers with arbitrary precision.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormat = errors.New("invalid decimal format")

ErrInvalidFormat is returned when decimal format is invalid.

Functions

func FromString

func FromString(s string, precision int) (*big.Int, error)

FromString converts string to a big decimal with specified precision.

func ToString

func ToString(bi *big.Int, precision int) string

ToString converts big decimal with specified precision to string.

Types

type Fixed8

type Fixed8 int64

Fixed8 represents a fixed-point number with precision 10^-8.

func Fixed8FromFloat

func Fixed8FromFloat(val float64) Fixed8

Fixed8FromFloat returns a new Fixed8 type multiplied by decimals.

func Fixed8FromInt64

func Fixed8FromInt64(val int64) Fixed8

Fixed8FromInt64 returns a new Fixed8 type multiplied by decimals.

func Fixed8FromString

func Fixed8FromString(s string) (Fixed8, error)

Fixed8FromString parses s which must be a fixed point number with precision up to 10^-8.

func Satoshi

func Satoshi() Fixed8

Satoshi defines the value of a 'Satoshi'.

func (Fixed8) Add

func (f Fixed8) Add(g Fixed8) Fixed8

Add implements Fixd8 addition operator.

func (Fixed8) CompareTo

func (f Fixed8) CompareTo(g Fixed8) int

CompareTo returns the difference between the f and g. difference < 0 implies f < g. difference = 0 implies f = g. difference > 0 implies f > g.

func (*Fixed8) DecodeBinary

func (f *Fixed8) DecodeBinary(r *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (Fixed8) Div

func (f Fixed8) Div(i int64) Fixed8

Div implements Fixd8 division operator.

func (*Fixed8) EncodeBinary

func (f *Fixed8) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

func (Fixed8) Equal

func (f Fixed8) Equal(g Fixed8) bool

Equal implements Fixd8 == operator.

func (Fixed8) FloatValue

func (f Fixed8) FloatValue() float64

FloatValue returns the original value representing Fixed8 as float64.

func (Fixed8) FractionalValue

func (f Fixed8) FractionalValue() int32

FractionalValue returns decimal part of the original value. It has the same sign as f, so that f = f.IntegralValue() + f.FractionalValue().

func (Fixed8) GreaterThan

func (f Fixed8) GreaterThan(g Fixed8) bool

GreaterThan implements Fixd8 < operator.

func (Fixed8) IntegralValue

func (f Fixed8) IntegralValue() int64

IntegralValue returns integer part of the original value representing Fixed8 as int64.

func (Fixed8) LessThan

func (f Fixed8) LessThan(g Fixed8) bool

LessThan implements Fixd8 < operator.

func (Fixed8) MarshalJSON

func (f Fixed8) MarshalJSON() ([]byte, error)

MarshalJSON implements the json marshaller interface.

func (Fixed8) MarshalYAML

func (f Fixed8) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml marshaller interface.

func (Fixed8) String

func (f Fixed8) String() string

String implements the Stringer interface.

func (Fixed8) Sub

func (f Fixed8) Sub(g Fixed8) Fixed8

Sub implements Fixd8 subtraction operator.

func (*Fixed8) UnmarshalJSON

func (f *Fixed8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json unmarshaller interface.

func (*Fixed8) UnmarshalYAML

func (f *Fixed8) 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