fixedpoint

package
v0.0.0-...-8d88297 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: AGPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultPow = 1e8
View Source
const DefaultPrecision = 8
View Source
const MaxPrecision = 12
View Source
const NegInf = Value(math.MinInt64)
View Source
const NegOne = Value(-1e8)
View Source
const One = Value(1e8)
View Source
const PosInf = Value(math.MaxInt64)
View Source
const Zero = Value(0)

Variables

View Source
var ErrPrecisionLoss = errors.New("precision loss")

Functions

func Compare

func Compare(x, y Value) int

func Count

func Count(values []Value, counter Counter) int

func Equal

func Equal(x, y Value) bool

func NegativeTester

func NegativeTester(value Value) bool

func Parse

func Parse(input string) (num int64, numDecimalPoints int, err error)

func PositiveTester

func PositiveTester(value Value) bool

Types

type Ascending

type Ascending []Value

func (Ascending) Len

func (s Ascending) Len() int

func (Ascending) Less

func (s Ascending) Less(i, j int) bool

func (Ascending) Swap

func (s Ascending) Swap(i, j int)

type Counter

type Counter func(a Value) bool

type Descending

type Descending []Value

func (Descending) Len

func (s Descending) Len() int

func (Descending) Less

func (s Descending) Less(i, j int) bool

func (Descending) Swap

func (s Descending) Swap(i, j int)

type Reducer

type Reducer func(prev, curr Value) Value

type RoundingMode

type RoundingMode int
const (
	Up RoundingMode = iota
	Down
	HalfUp
)

type Slice

type Slice []Value

func (Slice) Len

func (s Slice) Len() int

Defaults to ascending sort

func (Slice) Less

func (s Slice) Less(i, j int) bool

func (Slice) Reduce

func (s Slice) Reduce(reducer Reducer, a ...Value) Value

func (Slice) Swap

func (s Slice) Swap(i, j int)

type Tester

type Tester func(value Value) bool

type Value

type Value int64
var (
	Two   Value = NewFromInt(2)
	Three Value = NewFromInt(3)
	Four  Value = NewFromInt(4)
)

func Abs

func Abs(a Value) Value

func Avg

func Avg(values []Value) (avg Value)

func Div

func Div(x, y Value) Value

func Filter

func Filter(values []Value, f Tester) (slice []Value)

func Max

func Max(a, b Value) Value

func Min

func Min(a, b Value) Value

func Mul

func Mul(x, y Value) Value

func Must

func Must(v Value, err error) Value

func MustNewFromBytes

func MustNewFromBytes(input []byte) (v Value)

func MustNewFromString

func MustNewFromString(input string) Value

func NewFromBytes

func NewFromBytes(input []byte) (Value, error)

func NewFromFloat

func NewFromFloat(val float64) Value

func NewFromInt

func NewFromInt(val int64) Value

func NewFromString

func NewFromString(input string) (Value, error)

func Reduce

func Reduce(values []Value, reducer Reducer, a ...Value) Value

func Sum

func Sum(values []Value) (s Value)

func SumReducer

func SumReducer(prev, curr Value) Value

func (Value) Abs

func (v Value) Abs() Value

func (Value) Add

func (v Value) Add(v2 Value) Value

func (*Value) AtomicAdd

func (v *Value) AtomicAdd(v2 Value)

func (*Value) AtomicLoad

func (v *Value) AtomicLoad() Value

func (Value) Ceil

func (v Value) Ceil() Value

func (Value) Compare

func (x Value) Compare(y Value) int

func (Value) Div

func (v Value) Div(v2 Value) Value

func (Value) Eq

func (x Value) Eq(y Value) bool

func (Value) Float64

func (v Value) Float64() float64

func (Value) Floor

func (v Value) Floor() Value

func (Value) FormatPercentage

func (v Value) FormatPercentage(prec int) string

func (Value) FormatString

func (v Value) FormatString(prec int) string

func (Value) Int

func (v Value) Int() int

func (Value) Int64

func (v Value) Int64() int64

func (Value) IsInf

func (a Value) IsInf() bool

func (Value) IsZero

func (v Value) IsZero() bool

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

func (Value) MarshalYAML

func (v Value) MarshalYAML() (interface{}, error)

func (Value) Mul

func (v Value) Mul(v2 Value) Value

func (Value) MulExp

func (a Value) MulExp(exp int) Value

func (Value) Neg

func (v Value) Neg() Value

func (Value) NumFractionalDigits

func (a Value) NumFractionalDigits() int

TODO: speedup

func (Value) NumIntDigits

func (a Value) NumIntDigits() int

func (Value) Percentage

func (v Value) Percentage() string

func (Value) Round

func (v Value) Round(r int, mode RoundingMode) Value

func (*Value) Scan

func (v *Value) Scan(src interface{}) error

func (Value) Sign

func (v Value) Sign() int

TODO inf

func (Value) SignedPercentage

func (v Value) SignedPercentage() string

func (Value) String

func (v Value) String() string

func (Value) Sub

func (v Value) Sub(v2 Value) Value

func (Value) Trunc

func (v Value) Trunc() Value

Trunc returns the integer portion (truncating any fractional part)

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(data []byte) error

func (*Value) UnmarshalYAML

func (v *Value) UnmarshalYAML(unmarshal func(a interface{}) error) (err error)

func (Value) Value

func (v Value) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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