fixed

package module
v0.0.0-...-8647c43 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 6 Imported by: 0

README

New Readme coming soon.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NaN = &Fixed{
		nan: &ErrNaN{
			reason: errNaNDefault,
		},
	}
	ZERO = &Fixed{fp: 0}
)

Functions

This section is empty.

Types

type ErrFormat

type ErrFormat string

func (ErrFormat) Error

func (e ErrFormat) Error() string

type ErrNaN

type ErrNaN struct {
	// contains filtered or unexported fields
}

func (ErrNaN) Error

func (e ErrNaN) Error() string

type ErrParse

type ErrParse struct {
	// contains filtered or unexported fields
}

func (ErrParse) Error

func (e ErrParse) Error() string

func (ErrParse) MarshalJSON

func (e ErrParse) MarshalJSON() ([]byte, error)

type ErrTooLarge

type ErrTooLarge string

func (ErrTooLarge) Error

func (e ErrTooLarge) Error() string

type Fixed

type Fixed struct {
	// contains filtered or unexported fields
}

Fixed is a fixed precision 38.24 number (supports 11.7 digits). It supports NaN.

func FromFloat

func FromFloat(f float64) *Fixed

FromFloat creates a Fixed from an float64

func FromInt64

func FromInt64(fp, exponent int64) *Fixed

NewI creates a Fixed for an integer, moving the decimal point n places to the left For example, NewI(123,1) becomes 12.3.

func FromNaN

func FromNaN(err *ErrNaN) *Fixed

func FromScientific

func FromScientific(s string) *Fixed

func MustParse

func MustParse(s string) *Fixed

MustParse creates a new Fixed from a string, and panics if the string could not be parsed

func Parse

func Parse(s string) *Fixed

Parse creates a new Fixed from a string, returning NaN, and error if the string could not be parsed.

func (Fixed) Abs

func (f Fixed) Abs() *Fixed

Abs returns the absolute value of f. If f is NaN, NaN is returned

func (Fixed) Add

func (f Fixed) Add(f0 Fixed) *Fixed

Add adds f0 to f producing a Fixed. If either operand is NaN, NaN is returned

func (Fixed) Cmp

func (f Fixed) Cmp(f0 *Fixed) int

Cmp compares two Fixed. Returns:

if f == f0 : 0 if f > f0 : 0 if f < f0 : -1 if both are NaN : 0. if f is NaN : 1 if f0 is NaN, return -1

func (Fixed) Div

func (f Fixed) Div(f0 Fixed) *Fixed

Div divides f by f0 returning a Fixed. If either operand is NaN, NaN is returned

func (Fixed) Equal

func (f Fixed) Equal(f0 *Fixed) bool

Equal returns true if the f == f0. If either operand is NaN, false is returned. Use IsNaN() to test for NaN

func (Fixed) Float

func (f Fixed) Float() float64

Float converts the Fixed to a float64

func (Fixed) Frac

func (f Fixed) Frac() float64

Frac return the fractional portion of the Fixed, or NaN if NaN

func (Fixed) GreaterThan

func (f Fixed) GreaterThan(f0 *Fixed) bool

GreaterThan tests Cmp() for 1

func (Fixed) GreaterThanOrEqual

func (f Fixed) GreaterThanOrEqual(f0 *Fixed) bool

GreaterThaOrEqual tests Cmp() for 1 or 0

func (Fixed) Int

func (f Fixed) Int() int64

Int return the integer portion of the Fixed, or 0 if NaN

func (Fixed) IsNaN

func (f Fixed) IsNaN() bool

func (Fixed) IsZero

func (f Fixed) IsZero() bool

func (Fixed) LessThan

func (f Fixed) LessThan(f0 *Fixed) bool

LessThan tests Cmp() for -1

func (Fixed) LessThanOrEqual

func (f Fixed) LessThanOrEqual(f0 *Fixed) bool

LessThan tests Cmp() for -1 or 0

func (Fixed) MarshalBinary

func (f Fixed) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Fixed) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Fixed) Mul

func (f Fixed) Mul(f0 Fixed) *Fixed

Mul multiplies f by f0 returning a Fixed. If either operand is NaN, NaN is returned

func (Fixed) Round

func (f Fixed) Round(n int) *Fixed

Round returns a rounded Fixed(half-up, away from zero) to n decimal places

func (Fixed) Sign

func (f Fixed) Sign() int64

Sign returns:

-1 if f <  0
 0 if f == 0 or NaN
+1 if f >  0

func (Fixed) String

func (f Fixed) String() string

String converts a Fixed to a string, dropping trailing zeros

func (Fixed) StringN

func (f Fixed) StringN(decimals int) string

StringN converts a Fixed to a String with a specified number of decimal places, truncating as required

func (Fixed) Sub

func (f Fixed) Sub(f0 Fixed) *Fixed

Sub subtracts f0 from f producing a Fixed. If either operand is NaN, NaN is returned

func (*Fixed) UnmarshalBinary

func (f *Fixed) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

func (*Fixed) UnmarshalJSON

func (f *Fixed) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Fixed) WriteTo

func (f Fixed) WriteTo(w io.ByteWriter) error

WriteTo write the Fixed to an io.Writer, returning the number of bytes written

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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