Documentation ¶
Index ¶
- Constants
- Variables
- type Fixed
- func (f Fixed) Abs() Fixed
- func (f Fixed) Add(f0 Fixed) Fixed
- func (f Fixed) Cmp(f0 Fixed) int
- func (f *Fixed) Compose(form byte, negative bool, coefficient []byte, exponent int32) (err error)
- func (f Fixed) Decompose(buf []byte) (form byte, negative bool, coefficient []byte, exponent int32)
- func (f Fixed) Div(f0 Fixed) Fixed
- func (f Fixed) Equal(f0 Fixed) bool
- func (f Fixed) Float() float64
- func (f Fixed) Frac() float64
- func (f Fixed) GreaterThan(f0 Fixed) bool
- func (f Fixed) GreaterThanOrEqual(f0 Fixed) bool
- func (f Fixed) Int() int64
- func (f Fixed) IsNaN() bool
- func (f Fixed) IsZero() bool
- func (f Fixed) LessThan(f0 Fixed) bool
- func (f Fixed) LessThanOrEqual(f0 Fixed) bool
- func (f Fixed) MarshalBinary() (data []byte, err error)
- func (f Fixed) MarshalJSON() ([]byte, error)
- func (f Fixed) Mul(f0 Fixed) Fixed
- func (f Fixed) Round(n int) Fixed
- func (f Fixed) Sign() int
- func (f Fixed) String() string
- func (f Fixed) StringN(decimals int) string
- func (f Fixed) Sub(f0 Fixed) Fixed
- func (f *Fixed) UnmarshalBinary(data []byte) error
- func (f *Fixed) UnmarshalJSON(bytes []byte) error
- func (f Fixed) WriteTo(w io.ByteWriter) error
Constants ¶
const MAX = float64(99999999999.9999999)
Variables ¶
var NaN = Fixed{/* contains filtered or unexported fields */}
var ZERO = Fixed{/* contains filtered or unexported fields */}
Functions ¶
This section is empty.
Types ¶
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 MustParse ¶
MustParse creates a new Fixed from a string, and panics if the string could not be parsed
func NewI ¶
NewI creates a Fixed for an integer, moving the decimal point n places to the left For example, NewI(123,1) becomes 12.3. If n > 7, the value is truncated
func NewSErr ¶
NewSErr creates a new Fixed from a string, returning NaN, and error if the string could not be parsed
func Parse ¶
Parse creates a new Fixed from a string, returning NaN, and error if the string could not be parsed. Same as NewSErr but more standard naming
func ReadFrom ¶
func ReadFrom(r io.ByteReader) (Fixed, error)
ReadFrom reads a Fixed from an io.Reader
func (Fixed) Cmp ¶
Cmp compares two Fixed. If f == f0, return 0. If f > f0, return 1. If f < f0, return -1. If both are NaN, return 0. If f is NaN, return 1. If f0 is NaN, return -1
func (*Fixed) Compose ¶
Compose sets the internal decimal value from parts. If the value cannot be represented then an error should be returned.
func (Fixed) Decompose ¶
Decompose returns the internal decimal state into parts. If the provided buf has sufficient capacity, buf may be returned as the coefficient with the value set and length set as appropriate.
func (Fixed) Equal ¶
Equal returns true if the f == f0. If either operand is NaN, false is returned. Use IsNaN() to test for NaN
func (Fixed) GreaterThanOrEqual ¶
GreaterThaOrEqual tests Cmp() for 1 or 0
func (Fixed) LessThanOrEqual ¶
LessThan tests Cmp() for -1 or 0
func (Fixed) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Fixed) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Fixed) Mul ¶
Mul multiplies f by f0 returning a Fixed. If either operand is NaN, NaN is returned
func (Fixed) StringN ¶
StringN converts a Fixed to a String with a specified number of decimal places, truncating as required
func (Fixed) Sub ¶
Sub subtracts f0 from f producing a Fixed. If either operand is NaN, NaN is returned
func (*Fixed) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface
func (*Fixed) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.