Documentation ¶
Index ¶
- Constants
- Variables
- func AddSS(inReal0, inReal1 []float64) []float64
- func AddSV(inReal []float64, v float64) []float64
- func Avg(inReal []float64, timePeriod int) []float64
- func BaseConvert(num string, fromBase, toBase int) (string, error)
- func BigIntToFloat64(it *big.Int) float64
- func BiggerEqualThan(left, right *big.Int) bool
- func BiggerThan(left, right *big.Int) bool
- func BoundUint32(min, toBound, max uint32) uint32
- func CmpInt64Array(a, b []int64) bool
- func ContainsInt(src []int, toFind int) bool
- func DetectMaxPrec(vals []ElegantFloat, humanReadPrec int) int
- func DetectMaxPrecRaw(vals []float64, humanReadPrec int) int
- func DetectPrecByHumanReadPrec(val float64, humanReadPrec int) int
- func ElegantFloatArrayToFloatArray(in []ElegantFloat) []float64
- func Fibonacci(n int) int
- func Float64ToByte(f float64) []byte
- func Float64ToByteLE(f float64) []byte
- func FloatAlmostEqual(a, b float64) bool
- func FloatsEqual(a, b []float64) bool
- func FloatsPtrToFloats(in []*float64) []float64
- func FloatsToFloatsPtr(in []float64) []*float64
- func Format(num any, base int) (string, error)
- func FormatAnySys(numberSystemDigits []rune, n big.Int) string
- func FormatFloat64(f float64, prec int) string
- func FormatInt(i int) string
- func FormatInt64(i int64) string
- func FormatUint16(u uint16) string
- func FormatUint32(u uint32) string
- func FormatUint64(u uint64) string
- func FormatUint8(u uint8) string
- func GetDefaultDigits() []rune
- func GetLast1(v int) int
- func GetLast2(v int) int
- func IsDigit(s string) bool
- func IsEvenInt64(n int64) bool
- func IsEvenUint64(n uint64) bool
- func IsOddInt64(n int64) bool
- func IsOddUint64(n uint64) bool
- func IsZero(val *big.Int) bool
- func JoinFormatInt(sep string, num ...int) string
- func Max(numTypeSample any) (any, error)
- func MaxFloat(args ...float64) float64
- func MaxFloat64(first float64, args ...float64) float64
- func MaxInt(first int, args ...int) int
- func MaxInt64(first int64, args ...int64) int64
- func MaxPrec(in []Decimal) int
- func MaxSS(inReal0, inReal1 []float64) []float64
- func MaxSV(inReal []float64, inTimePeriod int) []float64
- func MaxUint32(first uint32, args ...uint32) uint32
- func MaxUint64(first uint64, args ...uint64) uint64
- func Mean(values []float64) float64
- func Min(numTypeSample any) (any, error)
- func MinFloat(args ...float64) float64
- func MinFloat64(first float64, args ...float64) float64
- func MinInt(first int, args ...int) int
- func MinInt64(first int64, args ...int64) int64
- func MinSS(inReal0, inReal1 []float64) []float64
- func MinSV(inReal []float64, inTimePeriod int) []float64
- func MinUint32(first uint32, args ...uint32) uint32
- func MinUint64(first uint64, args ...uint64) uint64
- func MinUintArray(args []uint) uint
- func MulSS(inReal0, inReal1 []float64) []float64
- func MulSV(inReal []float64, v float64) []float64
- func MustMax(numTypeSample any) any
- func MustMin(numTypeSample any) any
- func ParseAnySys(numberSystemDigits []rune, s string) (*big.Int, error)
- func ParseBigInt(num string, base int) (big.Int, error)
- func ParseFloat64(s string) (float64, error)
- func RealGoldenRatio() float64
- func RemoveDuplicate(elements []int) []int
- func RemoveLast1(v int) int
- func RemoveLast2(v int) int
- func RemoveUint(src []uint, toRemove uint, removeCount int) []uint
- func ReverseBigFloats(in []big.Float)
- func ReverseBigInts(in []big.Int)
- func ReverseFloats(in []float64)
- func ReverseInt64s(in []int64)
- func ReverseInts(in []int)
- func ReverseUints(in []uint)
- func SetHead0(inReal []float64, count int)
- func Slice(v int64, begin, len int) (int64, error)
- func SmallerEqualThan(left, right *big.Int) bool
- func SmallerThan(left, right *big.Int) bool
- func SortBigFloats(in []big.Float)
- func SortBigInts(in []big.Int)
- func SortFloats(in []float64)
- func SortInt64s(in []int64)
- func SortInts(in []int)
- func SortUints(in []uint)
- func Std(values []float64, ddof int) float64
- func SubSS(inReal0, inReal1 []float64) []float64
- func SubSV(inReal []float64, v float64) []float64
- func Sum(values []float64) float64
- func SumFloat(args ...float64) float64
- func ToFloat64s(in []Decimal) []float64
- type Decimal
- func MaxDecimal(first Decimal, args ...Decimal) Decimal
- func MinDecimal(first Decimal, args ...Decimal) Decimal
- func NewDecimalFromAny(val any) (*Decimal, error)
- func NewDecimalFromBigFloat(val big.Float) (Decimal, error)
- func NewDecimalFromBigInt(val big.Int) Decimal
- func NewDecimalFromDecimal(d2 decimal.Decimal) Decimal
- func NewDecimalFromFloat32(val float32) Decimal
- func NewDecimalFromFloat64(val float64) Decimal
- func NewDecimalFromInt(val int) Decimal
- func NewDecimalFromInt16(val int16) Decimal
- func NewDecimalFromInt32(val int32) Decimal
- func NewDecimalFromInt64(val int64) Decimal
- func NewDecimalFromInt8(val int8) Decimal
- func NewDecimalFromString(val string) (Decimal, error)
- func NewDecimalFromStringEx(val string, prec int) (Decimal, error)
- func NewDecimalFromUint(val uint) Decimal
- func NewDecimalFromUint16(val uint16) Decimal
- func NewDecimalFromUint32(val uint32) Decimal
- func NewDecimalFromUint64(val uint64) Decimal
- func NewDecimalFromUint8(val uint8) Decimal
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(d2 Decimal) Decimal
- func (d Decimal) AddFloat64(n float64) Decimal
- func (d Decimal) AddInt(n int) Decimal
- func (d Decimal) BitsAfterDecimalPoint(countTail0 bool) int
- func (d *Decimal) Conv(sample any, allowFractionalLoss bool) (any, error)
- func (d Decimal) Div(d2 Decimal) Decimal
- func (d Decimal) DivFloat64(n float64) Decimal
- func (d Decimal) DivInt(n int) Decimal
- func (d Decimal) DivRound(d2 Decimal, precision int) Decimal
- func (d Decimal) DivRoundDown(d2 Decimal, precision int) Decimal
- func (d Decimal) DivRoundFloat64(d2 float64, precision int) Decimal
- func (d Decimal) DivRoundInt(d2 int, precision int) Decimal
- func (d Decimal) Equal(cmp Decimal) bool
- func (d Decimal) EqualFloat64(cmp float64) bool
- func (d Decimal) EqualInt(cmp int) bool
- func (d Decimal) Float64() float64
- func (d Decimal) Float64Ex() (val float64, exact bool)
- func (d Decimal) GreaterThan(cmp Decimal) bool
- func (d Decimal) GreaterThanFloat64(cmp float64) bool
- func (d Decimal) GreaterThanInt(cmp int) bool
- func (d Decimal) GreaterThanOrEqual(cmp Decimal) bool
- func (d Decimal) GreaterThanOrEqualFloat64(cmp float64) bool
- func (d Decimal) GreaterThanOrEqualInt(cmp int) bool
- func (d Decimal) Int64Part() int64
- func (d Decimal) IntPart() int
- func (d Decimal) IsInterger() bool
- func (d Decimal) IsNegative() bool
- func (d Decimal) IsPositive() bool
- func (d Decimal) IsZero() bool
- func (d Decimal) LessThan(cmp Decimal) bool
- func (d Decimal) LessThanFloat64(cmp float64) bool
- func (d Decimal) LessThanInt(cmp int) bool
- func (d Decimal) LessThanOrEqual(cmp Decimal) bool
- func (d Decimal) LessThanOrEqualFloat64(cmp float64) bool
- func (d Decimal) LessThanOrEqualInt(cmp int) bool
- func (d Decimal) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (d Decimal) MarshalBinary() (data []byte, err error)
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) MarshalJSONWithoutQuotes() ([]byte, error)
- func (d Decimal) MarshalText() (text []byte, err error)
- func (d Decimal) Mul(d2 Decimal) Decimal
- func (d Decimal) MulFloat64(n float64) Decimal
- func (d Decimal) MulInt(n int) Decimal
- func (d *Decimal) SetFloat64(val float64)
- func (d *Decimal) SetInt(val int)
- func (d Decimal) String() string
- func (d Decimal) Sub(d2 Decimal) Decimal
- func (d Decimal) SubFloat64(n float64) Decimal
- func (d Decimal) SubInt(n int) Decimal
- func (d *Decimal) ToBSONDecimal128() (primitive.Decimal128, error)
- func (d *Decimal) ToElegantFloat() ElegantFloat
- func (d Decimal) Trunc(prec int, step float64) Decimal
- func (d Decimal) Trunc2(min Decimal, step float64) Decimal
- func (d Decimal) TurnPositiveNegative() Decimal
- func (d *Decimal) UnmarshalBSONValue(t bsontype.Type, data []byte) error
- func (d *Decimal) UnmarshalBinary(b []byte) error
- func (d *Decimal) UnmarshalJSON(b []byte) error
- func (d *Decimal) UnmarshalText(text []byte) error
- func (d Decimal) WithPrec(prec int) Decimal
- type ElegantFloat
- func NewElegantFloat(val float64, prec int) ElegantFloat
- func NewElegantFloatArray(vals []float64, prec int) []ElegantFloat
- func NewElegantFloatPtrArray(vals []*float64, prec int) []*ElegantFloat
- func NewElegantFloatPtrArray2(vals []float64, prec int) []*ElegantFloat
- func NewElegantFloatPtrArray3(vals []float64, prec int, nilVal float64) []*ElegantFloat
- func ToElegantFloat64s(in []Decimal) []ElegantFloat
- func (t *ElegantFloat) JSON(fmtNaNasNull bool) ([]byte, error)
- func (t ElegantFloat) MarshalJSON() ([]byte, error)
- func (t *ElegantFloat) Raw() float64
- func (t *ElegantFloat) SetHumanReadPrec(humanReadPrec int)
- func (t *ElegantFloat) SetPrec(prec int)
- func (t *ElegantFloat) String() string
- func (t *ElegantFloat) UnmarshalJSON(b []byte) error
- type Uint24
Constants ¶
const ( Billion = 1000000000 Million = 1000000 Kilo = 1000 )
const (
GoldenRatio = 0.618
)
const (
// MaxUint24 maximum value of uint24 variable
MaxUint24 = 1<<24 - 1
)
Variables ¶
var ( Decimal0 = Decimal(decimal.Zero) Decimal1 = NewDecimalFromInt(1) )
var ( PosInf = math.Inf(1) NegInf = math.Inf(-1) )
Functions ¶
func BigIntToFloat64 ¶
func BiggerEqualThan ¶
func BiggerThan ¶
func CmpInt64Array ¶
func ContainsInt ¶
func DetectMaxPrec ¶
func DetectMaxPrec(vals []ElegantFloat, humanReadPrec int) int
func DetectMaxPrecRaw ¶
func ElegantFloatArrayToFloatArray ¶
func ElegantFloatArrayToFloatArray(in []ElegantFloat) []float64
func Float64ToByte ¶
Converts the float64 into an uint64 without changing the bits, it's the way the bits are interpreted that change. big endian references: https://stackoverflow.com/questions/37758267/golang-float64bits https://stackoverflow.com/questions/43693360/convert-float64-to-byte-array
func FloatAlmostEqual ¶
func FloatsEqual ¶
func FloatsPtrToFloats ¶
func FloatsToFloatsPtr ¶
func FormatAnySys ¶
Format number to string in specified number system. Length of 'numberSystemDigits' is number system length. Reference: https://github.com/kenticny/numconvert/blob/master/converter.go
func FormatFloat64 ¶
func FormatInt64 ¶
func FormatUint16 ¶
func FormatUint32 ¶
func FormatUint64 ¶
func FormatUint8 ¶
func GetDefaultDigits ¶
func GetDefaultDigits() []rune
func IsEvenInt64 ¶
func IsEvenUint64 ¶
func IsOddInt64 ¶
func IsOddUint64 ¶
func JoinFormatInt ¶
func MaxFloat64 ¶
func MinFloat64 ¶
func MinUintArray ¶
func ParseAnySys ¶
Parse string as specified number system.
func ParseFloat64 ¶
func RealGoldenRatio ¶
func RealGoldenRatio() float64
func RemoveDuplicate ¶
func ReverseBigFloats ¶
func ReverseBigInts ¶
func ReverseFloats ¶
func ReverseFloats(in []float64)
func ReverseInt64s ¶
func ReverseInt64s(in []int64)
func ReverseInts ¶
func ReverseInts(in []int)
func ReverseUints ¶
func ReverseUints(in []uint)
func SmallerEqualThan ¶
func SmallerThan ¶
func SortBigFloats ¶
func SortBigInts ¶
func SortFloats ¶
func SortFloats(in []float64)
func SortInt64s ¶
func SortInt64s(in []int64)
func Std ¶
Standard Deviation (均方差) ddof: Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
func ToFloat64s ¶
Types ¶
type Decimal ¶
func MaxDecimal ¶
func MinDecimal ¶
func NewDecimalFromAny ¶
func NewDecimalFromDecimal ¶
func NewDecimalFromFloat32 ¶
func NewDecimalFromFloat64 ¶
func NewDecimalFromInt ¶
func NewDecimalFromInt16 ¶
func NewDecimalFromInt32 ¶
func NewDecimalFromInt64 ¶
func NewDecimalFromInt8 ¶
func NewDecimalFromString ¶
func NewDecimalFromUint ¶
func NewDecimalFromUint16 ¶
func NewDecimalFromUint32 ¶
func NewDecimalFromUint64 ¶
func NewDecimalFromUint8 ¶
func (Decimal) AddFloat64 ¶
func (Decimal) BitsAfterDecimalPoint ¶
BitsAfterDecimalPoint returns decimal precision. NOTE: When countTail0 is true, the 0 in the tail is also counted as precision.
func (Decimal) DivFloat64 ¶
func (Decimal) DivRoundFloat64 ¶
func (Decimal) EqualFloat64 ¶
func (Decimal) GreaterThan ¶
func (Decimal) GreaterThanFloat64 ¶
func (Decimal) GreaterThanInt ¶
func (Decimal) GreaterThanOrEqual ¶
func (Decimal) GreaterThanOrEqualFloat64 ¶
func (Decimal) GreaterThanOrEqualInt ¶
func (Decimal) IsInterger ¶
func (Decimal) IsNegative ¶
func (Decimal) IsPositive ¶
func (Decimal) LessThanFloat64 ¶
func (Decimal) LessThanInt ¶
func (Decimal) LessThanOrEqual ¶
func (Decimal) LessThanOrEqualFloat64 ¶
func (Decimal) LessThanOrEqualInt ¶
func (Decimal) MarshalBSONValue ¶
in BSON, Decimal128 could has 34 numbers after decimal point, it will loss precision if more than 34 numbers after decimal point so we serialize Decimal into string, just like in JSON. in BSON, omitempty of Decimal works reference: https://github.com/hackeryard/configcenter/blob/a9638f554b4cf47fb13c37c5c3611e1e0696fd25/src/common/metadata/time.go#L94
func (Decimal) MarshalBinary ¶
func (Decimal) MarshalJSON ¶
NOTE: if omitempty required in JSON, use *Decimal in your structure, no other way to implement this even you change source code MarshalJSON function in shopsprint/decimal
func (Decimal) MarshalJSONWithoutQuotes ¶
WARNING: this is dangerous for decimals with many digits, since many JSON unmarshallers (ex: Javascript's) will unmarshal JSON numbers to IEEE 754 double-precision floating point numbers, which means you can potentially silently lose precision.
func (Decimal) MarshalText ¶
func (Decimal) MulFloat64 ¶
func (*Decimal) SetFloat64 ¶
func (Decimal) SubFloat64 ¶
func (*Decimal) ToBSONDecimal128 ¶
func (d *Decimal) ToBSONDecimal128() (primitive.Decimal128, error)
WARN: BSON Decimal128 has max 34 number after "." but Decimal doesn't have this limit (limited by your memory)
func (*Decimal) ToElegantFloat ¶
func (d *Decimal) ToElegantFloat() ElegantFloat
func (Decimal) TurnPositiveNegative ¶
func (*Decimal) UnmarshalBSONValue ¶
func (*Decimal) UnmarshalBinary ¶
func (*Decimal) UnmarshalJSON ¶
func (*Decimal) UnmarshalText ¶
type ElegantFloat ¶
type ElegantFloat struct {
// contains filtered or unexported fields
}
original -> prec: 2 -> humanReadPrec: 2 37 -> 37.00 -> 37.00 12237.89374 -> 12237.89 -> 12237.89 3.3483300000000003 -> 3.35 -> 3.35 0.00883300000000003 -> 0.01 -> 0.0088 0.000012800003 -> 0.00 -> 0.000013
func NewElegantFloat ¶
func NewElegantFloat(val float64, prec int) ElegantFloat
func NewElegantFloatArray ¶
func NewElegantFloatArray(vals []float64, prec int) []ElegantFloat
func NewElegantFloatPtrArray ¶
func NewElegantFloatPtrArray(vals []*float64, prec int) []*ElegantFloat
func NewElegantFloatPtrArray2 ¶
func NewElegantFloatPtrArray2(vals []float64, prec int) []*ElegantFloat
func NewElegantFloatPtrArray3 ¶
func NewElegantFloatPtrArray3(vals []float64, prec int, nilVal float64) []*ElegantFloat
func ToElegantFloat64s ¶
func ToElegantFloat64s(in []Decimal) []ElegantFloat
func (*ElegantFloat) JSON ¶
func (t *ElegantFloat) JSON(fmtNaNasNull bool) ([]byte, error)
What will happen if value is math.NaN? it will output bytes buffer `"NaN"`
func (ElegantFloat) MarshalJSON ¶
func (t ElegantFloat) MarshalJSON() ([]byte, error)
MarshalJSON will marshal using 2006-01-02T15:04:05+07:00 layout
FIXME if t.val = math.NaN and t.JSON(false), json.Marshal(t) will output error: json: error calling MarshalJSON for type *gnum.ElegantFloat: invalid character 'N' looking for beginning of value why and how to fix?
func (*ElegantFloat) Raw ¶
func (t *ElegantFloat) Raw() float64
func (*ElegantFloat) SetHumanReadPrec ¶
func (t *ElegantFloat) SetHumanReadPrec(humanReadPrec int)
func (*ElegantFloat) SetPrec ¶
func (t *ElegantFloat) SetPrec(prec int)
func (*ElegantFloat) String ¶
func (t *ElegantFloat) String() string
func (*ElegantFloat) UnmarshalJSON ¶
func (t *ElegantFloat) UnmarshalJSON(b []byte) error
TODO: NaN +-Inf会被ParseFloat64认为是错误吗,需要测试一下 UnmarshalJSON will unmarshal using 2006-01-02T15:04:05+07:00 layout