fixed

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

README

FixedNumber

codecov Go Report Card Build Status

Documentation

Index

Constants

View Source
const Fixed64Zero = Fixed64(0)

Fixed64Zero is the zero value of fixed number

View Source
const MaxFixed64 = Fixed64((1 << 63) - 1)

MaxFixed64 is the maximum number of fixed points,and its value is 2**(63 - Precision) + 2 ** Precision - 2

View Source
const PrecisionNumber = Fixed64(1)

PrecisionNumber is the minimum precision value of a fixed-point number, and its value is 1 / 2**Precision

View Source
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

View Source
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

func Uint64Bits(v uint64) (r []byte)

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

func Float64ToFixed64(value float64) Fixed64

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

func SafeFloat64ToFixed64(value float64) (Fixed64, error)

SafeFloat64ToFixed64 checks NaN and Inf before floating point conversion, which guarantees some accuracy

func Str2Fixed64

func Str2Fixed64(value string) (Fixed64, error)

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+)

func (Fixed64) Abs

func (fixed Fixed64) Abs() Fixed64

func (Fixed64) Add

func (fixed Fixed64) Add(oth Fixed64) Fixed64

func (Fixed64) Div

func (fixed Fixed64) Div(oth Fixed64) Fixed64

func (Fixed64) Equal

func (fixed Fixed64) Equal(oth Fixed64) bool

func (Fixed64) Float64

func (fixed Fixed64) Float64() float64

Converts Fixed64 To float64

func (Fixed64) Great

func (fixed Fixed64) Great(oth Fixed64) bool

func (Fixed64) Int64

func (fixed Fixed64) Int64() int64

func (Fixed64) Less

func (fixed Fixed64) Less(oth Fixed64) bool

func (Fixed64) Mul

func (fixed Fixed64) Mul(oth Fixed64) Fixed64

func (Fixed64) Round

func (fixed Fixed64) Round() int64

func (Fixed64) String

func (fixed Fixed64) String() string

func (Fixed64) Sub

func (fixed Fixed64) Sub(oth Fixed64) Fixed64

func (Fixed64) ToBase10

func (fixed Fixed64) ToBase10() string

5 decimal places are retained by default

func (Fixed64) ToBase10N

func (fixed Fixed64) ToBase10N(n uint) string

the maximum support is 18 decimals

Jump to

Keyboard shortcuts

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