Documentation ¶
Index ¶
- Variables
- type Fixed
- func (f Fixed) Add(f0 Fixed) Fixed
- func (f Fixed) Cmp(f0 Fixed) int
- 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) 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) Original() uint64
- 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) UInt() uint64
- func (f *Fixed) UnmarshalBinary(data []byte) error
- func (f *Fixed) UnmarshalJSON(bytes []byte) error
- func (f Fixed) WriteTo(w io.ByteWriter) error
Constants ¶
This section is empty.
Variables ¶
var ( NaN = Fixed{/* contains filtered or unexported fields */} ZERO = Fixed{/* contains filtered or unexported fields */} ONE = Fixed{/* contains filtered or unexported fields */} TWO = Fixed{/* contains filtered or unexported fields */} THREE = Fixed{/* contains filtered or unexported fields */} FOUR = Fixed{/* contains filtered or unexported fields */} FIVE = Fixed{/* contains filtered or unexported fields */} SIX = Fixed{/* contains filtered or unexported fields */} SEVEN = Fixed{/* contains filtered or unexported fields */} EIGHT = Fixed{/* contains filtered or unexported fields */} NINE = Fixed{/* contains filtered or unexported fields */} TEN = Fixed{/* contains filtered or unexported fields */} MAX = 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 10.8 digits). It supports NaN.
func NewFromFloat ¶
NewFromFloat creates a Fixed from an float64, rounding at the 8th decimal place
func NewFromOriginal ¶
NewFromOriginal creates a Fixed for an fixed original integer, moving the decimal point n places to the left For example, NewFromOriginal(123) becomes 0.00000123.
func NewFromString ¶
NewFromString creates a new Fixed from a string, returning NaN if the string could not be parsed
func NewFromStringErr ¶
NewFromStringErr creates a new Fixed from a string, returning NaN, and error if the string could not be parsed
func NewFromUintWithExponent ¶
NewFromUint creates a Fixed for an integer, moving the decimal point n places to the left For example, NewFromUint(123,1) becomes 12.3. If n > 8, the value is truncated
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) 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.