Documentation ¶
Index ¶
- Constants
- func DecimalPlaces(value float64, prec int) float64
- func DecimalPlacesRound(value float64, rank int) float64
- func FormatFloat(num float64) string
- func FormatInt(i int64, base int) string
- func FormatUint(i uint64, base int) string
- func FromBytes[T constraints.Number](bytes []byte) T
- func GenKey(key int64) int64
- func Mean(data []float64) float64
- func Median(data []float64) float64
- func PackInt(v int) uint64
- func ParseInt(s string, base int, bitSize int) (i int64, err error)
- func ParseUint(s string, base int, bitSize int) (uint64, error)
- func RemoveOutliersAndMean(data []float64) float64
- func SecondKey() int64
- func ToBytes[T constraints.Number](t T) []byte
- func UnpackInt(v uint64) int
- func ValidateKey(key, secretKey int64) float64
- func ValidateSecondKey(key int64) float64
- func ViewBin(v any)
Constants ¶
const ( MinInt48 int64 = -(1 << 47) MaxInt48 int64 = +(1 << 47) - 1 )
Variables ¶
This section is empty.
Functions ¶
func DecimalPlaces ¶
func FormatFloat ¶
func FormatInt ¶
FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.
func FormatUint ¶ added in v0.0.18
FormatUint returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.
func FromBytes ¶ added in v0.0.40
func FromBytes[T constraints.Number](bytes []byte) T
func ParseInt ¶
ParseInt interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.
The string may begin with a leading sign: "+" or "-".
If the base argument is 0, the true base is implied by the string's prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise. Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.
The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64. If bitSize is below 0 or above 64, an error is returned.
The errors that ParseInt returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax and the returned value is 0; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange and the returned value is the maximum magnitude integer of the appropriate bitSize and sign.
func RemoveOutliersAndMean ¶ added in v0.0.40
Remove outliers using the MAD method and calculate the Mean of the remaining data
func ToBytes ¶
func ToBytes[T constraints.Number](t T) []byte
func ValidateKey ¶
func ValidateSecondKey ¶
func ViewBin ¶
func ViewBin(v any)
Sizeof函数返回的大小只包括数据结构中固定的部分,例如字符串对应结构体中的指针和字符串长度部分,但是并不包含指针指向的字符串的内容。Go语言中非聚合类型通常有一个固定的大小,尽管在不同工具链下生成的实际大小可能会有所不同。考虑到可移植性,引用类型或包含引用类型的大小在32位平台上是4个字节,在64位平台上是8个字节。
计算机在加载和保存数据时,如果内存地址合理地对齐的将会更有效率。例如2字节大小的int16类型的变量地址应该是偶数,一个4字节大小的rune类型变量的地址应该是4的倍数,一个8字节大小的float64、uint64或64-bit指针类型变量的地址应该是8字节对齐的。但是对于再大的地址对齐倍数则是不需要的,即使是complex128等较大的数据类型最多也只是8字节对齐。
由于地址对齐这个因素,一个聚合类型(结构体或数组)的大小至少是所有字段或元素大小的总和,或者更大因为可能存在内存空洞。 1字节(byte)=8位(bit) 在16位系统中,1字(word)=2字节(byte)=16位(bit) 在32位系统中,1字(word)=4字节(byte)=32位(bit) 在64位系统中,1字(word)=8字节(byte)=64位(bit)
Types ¶
This section is empty.