Documentation ¶
Index ¶
- Constants
- Variables
- func SetPrecisionOnce(precision uint64)
- func Uint64Bits(v uint64) (r []byte)
- type Fixed64
- func (fixed Fixed64) Abs() Fixed64
- func (fixed Fixed64) Add(oth Fixed64) Fixed64
- func (fixed Fixed64) Div(oth Fixed64) Fixed64
- func (fixed Fixed64) Equal(oth Fixed64) bool
- func (fixed Fixed64) Float64() float64
- func (fixed Fixed64) Great(oth Fixed64) bool
- func (fixed Fixed64) Int64() int64
- func (fixed Fixed64) Less(oth Fixed64) bool
- func (fixed Fixed64) Mul(oth Fixed64) Fixed64
- func (fixed Fixed64) Round() int64
- func (fixed Fixed64) String() string
- func (fixed Fixed64) Sub(oth Fixed64) Fixed64
- func (fixed Fixed64) ToBase10() string
- func (fixed Fixed64) ToBase10N(n uint) string
Constants ¶
const Fixed64Zero = Fixed64(0)
Fixed64Zero is the zero value of fixed number
const MaxFixed64 = Fixed64((1 << 63) - 1)
MaxFixed64 is the maximum number of fixed points,and its value is 2**(63 - Precision) + 2 ** Precision - 2
const PrecisionNumber = Fixed64(1)
PrecisionNumber is the minimum precision value of a fixed-point number, and its value is 1 / 2**Precision
const SmallestFixed64 = ^Fixed64(0)
SmallestFixed64 is the minimum value of a fixed-point number, and its value is 1/2**Precision - 2**(63-precisionBitsNum)
Variables ¶
var Precision int64
Precision is the bit Precision of a fixed-point number
Functions ¶
func SetPrecisionOnce ¶
func SetPrecisionOnce(precision uint64)
SetPrecisionOnce can only be successfully set once
func Uint64Bits ¶
Types ¶
type Fixed64 ¶
type Fixed64 uint64
Fixed64 uses uint64 type to facilitate bit conversion.Fixed64 can use +-0. Range: [-(2**(63 - Precision) + 2 ** Precision - 2), 2**(63 - Precision) + 2 ** Precision - 2].
func Float64ToFixed64 ¶
Float64ToFixed64 can convert the normalized number and normalized number conforming to IEEE 754 double precision floating-point number standard to fixed-point number. When the function processes Nan and Inf, there may be a panic
func SafeFloat64ToFixed64 ¶
SafeFloat64ToFixed64 checks NaN and Inf before floating point conversion, which guarantees some accuracy
func Str2Fixed64 ¶
Str2Fixed64 produces the result by converting the string value to a two-part float, and then performing a combination of division and addition.The efficiency of the function may not be high, there should be a better implementation.
Note: the function only supports processing data in (%d+.%d+)