gnum

package
v0.0.0-...-047dcd9 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Billion = 1000000000
	Million = 1000000
	Kilo    = 1000
)
View Source
const (
	GoldenRatio = 0.618
)

Variables

View Source
var (
	PosInf = math.Inf(1)
	NegInf = math.Inf(-1)
)

Functions

func AddSS

func AddSS(inReal0, inReal1 []float64) []float64

func AddSV

func AddSV(inReal []float64, v float64) []float64

func Avg

func Avg(inReal []float64, timePeriod int) []float64

Avg - Vector average

func BaseConvert

func BaseConvert(num string, fromBase, toBase int) (string, error)

func BigIntToFloat64

func BigIntToFloat64(it *big.Int) float64

func BiggerEqualThan

func BiggerEqualThan(left, right *big.Int) bool

func BiggerThan

func BiggerThan(left, right *big.Int) bool

func BoundUint32

func BoundUint32(min, toBound, max uint32) uint32

给toBound划界,不超过[min, max]的范围

func CmpInt64Array

func CmpInt64Array(a, b []int64) bool

func ContainsInt

func ContainsInt(src []int, toFind int) bool

func DetectMaxPrec

func DetectMaxPrec(vals []ElegantFloat, humanReadPrec int) int

func DetectMaxPrecRaw

func DetectMaxPrecRaw(vals []float64, humanReadPrec int) int

func DetectPrecByHumanReadPrec

func DetectPrecByHumanReadPrec(val float64, humanReadPrec int) int

func ElegantFloatArrayToFloatArray

func ElegantFloatArrayToFloatArray(in []ElegantFloat) []float64

func Fibonacci

func Fibonacci(n int) int

func Float64ToByte

func Float64ToByte(f float64) []byte

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 Float64ToByteLE

func Float64ToByteLE(f float64) []byte

little endian

func FloatAlmostEqual

func FloatAlmostEqual(a, b float64) bool

func FloatsEqual

func FloatsEqual(a, b []float64) bool

func FloatsPtrToFloats

func FloatsPtrToFloats(in []*float64) []float64

func FloatsToFloatsPtr

func FloatsToFloatsPtr(in []float64) []*float64

func Format

func Format(num interface{}, base int) (string, error)

func FormatAnySys

func FormatAnySys(numberSystemDigits []rune, n big.Int) string

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 FormatFloat64(f float64, prec int) string

func FormatInt

func FormatInt(i int) string

func FormatInt64

func FormatInt64(i int64) string

func FormatUint16

func FormatUint16(u uint16) string

func FormatUint32

func FormatUint32(u uint32) string

func FormatUint64

func FormatUint64(u uint64) string

func FormatUint8

func FormatUint8(u uint8) string

func GetDefaultDigits

func GetDefaultDigits() []rune

func GetLast1

func GetLast1(v int) int

199012 -> 2

func GetLast2

func GetLast2(v int) int

199012 -> 12

func IsDigit

func IsDigit(s string) bool

123 00123 +123 -123 123.456 2.07539829195e-05

func IsEvenInt64

func IsEvenInt64(n int64) bool

func IsEvenUint64

func IsEvenUint64(n uint64) bool

func IsOddInt64

func IsOddInt64(n int64) bool

func IsOddUint64

func IsOddUint64(n uint64) bool

func IsZero

func IsZero(val *big.Int) bool

func JoinFormatInt

func JoinFormatInt(sep string, num ...int) string

func MaxFloat

func MaxFloat(args ...float64) float64

func MaxFloat64

func MaxFloat64(first float64, args ...float64) float64

func MaxInt

func MaxInt(first int, args ...int) int

func MaxInt64

func MaxInt64(first int64, args ...int64) int64

func MaxSS

func MaxSS(inReal0, inReal1 []float64) []float64

func MaxSV

func MaxSV(inReal []float64, inTimePeriod int) []float64

func MaxUint32

func MaxUint32(first uint32, args ...uint32) uint32

func MaxUint64

func MaxUint64(first uint64, args ...uint64) uint64

func Mean

func Mean(values []float64) float64

Mean (均值)

func MinFloat

func MinFloat(args ...float64) float64

func MinFloat64

func MinFloat64(first float64, args ...float64) float64

func MinInt

func MinInt(first int, args ...int) int

func MinInt64

func MinInt64(first int64, args ...int64) int64

func MinSS

func MinSS(inReal0, inReal1 []float64) []float64

func MinSV

func MinSV(inReal []float64, inTimePeriod int) []float64

func MinUint32

func MinUint32(first uint32, args ...uint32) uint32

func MinUint64

func MinUint64(first uint64, args ...uint64) uint64

func MinUintArray

func MinUintArray(args []uint) uint

func MulSS

func MulSS(inReal0, inReal1 []float64) []float64

func MulSV

func MulSV(inReal []float64, v float64) []float64

func ParseAnySys

func ParseAnySys(numberSystemDigits []rune, s string) (*big.Int, error)

Parse string as specified number system.

func ParseBigInt

func ParseBigInt(num string, base int) (big.Int, error)

func ParseFloat64

func ParseFloat64(s string) (float64, error)

func RealGoldenRatio

func RealGoldenRatio() float64

func RemoveDuplicate

func RemoveDuplicate(elements []int) []int

func RemoveLast1

func RemoveLast1(v int) int

199012 -> 19901

func RemoveLast2

func RemoveLast2(v int) int

199012 -> 1990

func RemoveUint

func RemoveUint(src []uint, toRemove uint, removeCount int) []uint

func ReverseBigFloats

func ReverseBigFloats(in []big.Float)

func ReverseBigInts

func ReverseBigInts(in []big.Int)

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 SetHead0

func SetHead0(inReal []float64, count int)

func Slice

func Slice(v int64, begin, len int) (int64, error)

SliceBetweenEqual(19901201, 4, 2) -> 12 SliceBetweenEqual(-19901201, 4, 2) -> 12

func SmallerEqualThan

func SmallerEqualThan(left, right *big.Int) bool

func SmallerThan

func SmallerThan(left, right *big.Int) bool

func SortBigFloats

func SortBigFloats(in []big.Float)

func SortBigInts

func SortBigInts(in []big.Int)

func SortFloats

func SortFloats(in []float64)

func SortInt64s

func SortInt64s(in []int64)

func SortInts

func SortInts(in []int)

func SortUints

func SortUints(in []uint)

func Std

func Std(values []float64, ddof int) float64

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 SubSS

func SubSS(inReal0, inReal1 []float64) []float64

func SubSV

func SubSV(inReal []float64, v float64) []float64

func Sum

func Sum(values []float64) float64

Sum (和)

func SumFloat

func SumFloat(args ...float64) float64

func ToString

func ToString(x interface{}) string

Types

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 (*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

Jump to

Keyboard shortcuts

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