dt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 6 Imported by: 0

README

DT

这是一套神奇的数据结构,用于在 Go 范型出现之前统一各种数据类型的表达

本包中定义了若干组 interface,并遵循如下规范

  • interface 名称为 Interface,则其一定实现了 AsInterface 方法

  • 子 Interface 一定实现了父 Interface 的方法

  • Number 所有数字

    • Integer 所有整数
      • Int 有符号整数
        • Int8
        • Int16
        • Int32
        • Int64
        • Int128
      • UInt 无符号整数
        • UInt8
        • UInt16
        • UInt32
        • UInt64
        • UInt128
    • Float 所有浮点数
    • BigDecimal (TODO)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidType = fmt.Errorf("invalid type")
View Source
var ErrTooLarge = fmt.Errorf("value too large")
View Source
var FloatEps = 1e-8 //容忍度

Functions

func CheckOverflowFloat

func CheckOverflowFloat(x float64, k reflect.Kind) bool

func CheckOverflowInt

func CheckOverflowInt(x int64, k reflect.Kind) bool

func CheckOverflowUInt

func CheckOverflowUInt(x uint64, k reflect.Kind) bool

func ConvertFloatToFloat64

func ConvertFloatToFloat64(num interface{}) (float64, bool)

func ConvertSignedIntToInt64

func ConvertSignedIntToInt64(num interface{}) (int64, bool)

func ConvertToReflectType

func ConvertToReflectType(v Value, toType reflect.Kind) (value reflect.Value, ok bool)

func ConvertUnsignedIntToUInt64

func ConvertUnsignedIntToUInt64(num interface{}) (uint64, bool)

func Equal

func Equal(expect, real interface{}) bool

func FloatEqual

func FloatEqual(a, b float64) bool

func FloatEqualC

func FloatEqualC(a, b, eps float64) bool

func FloatIsInt

func FloatIsInt(f float64) bool

func FloatIsInt64

func FloatIsInt64(f float64) bool

func FloatIsIntC

func FloatIsIntC(f, eps float64) bool

func FloatIsUInt64

func FloatIsUInt64(f float64) bool

func FloatToInt64

func FloatToInt64(f float64) int64

func FloatToUInt64

func FloatToUInt64(f float64) uint64

func ParseBool

func ParseBool(b interface{}) (v bool, ok bool)

func ParseBoolFromNumber

func ParseBoolFromNumber(number *GenericNumber) bool

0 = false other = true

func ParseBoolFromString

func ParseBoolFromString(b string) (v bool, ok bool)

func ToString

func ToString(v interface{}) string

Types

type GenericNumber

type GenericNumber struct {
	// contains filtered or unexported fields
}

func BigFloatFromString

func BigFloatFromString(num string) (*GenericNumber, bool)

func BigIntFromString

func BigIntFromString(num string) (*GenericNumber, bool)

func FloatFromString

func FloatFromString(num string) (*GenericNumber, bool)

func IntFromString

func IntFromString(num string) (*GenericNumber, bool)

从字符串中解析整数

func NumberFromBasicFloat

func NumberFromBasicFloat(num interface{}) (*GenericNumber, bool)

func NumberFromBasicInt

func NumberFromBasicInt(num interface{}) (*GenericNumber, bool)

func NumberFromBasicIntType

func NumberFromBasicIntType(num interface{}) (*GenericNumber, bool)

func NumberFromBasicType

func NumberFromBasicType(num interface{}) (*GenericNumber, bool)

func NumberFromBasicUInt

func NumberFromBasicUInt(num interface{}) (*GenericNumber, bool)

func NumberFromString

func NumberFromString(num string) (*GenericNumber, bool)

从字符串获取对应表示的数字值

func ParseNumber

func ParseNumber(num interface{}) (*GenericNumber, bool)

func UIntFromString

func UIntFromString(num string) (*GenericNumber, bool)

func (*GenericNumber) Above64bit

func (num *GenericNumber) Above64bit() bool

func (*GenericNumber) Float

func (num *GenericNumber) Float() bool

func (*GenericNumber) Float64

func (num *GenericNumber) Float64() float64

将值转换为 float64 如果 IsFloat64 == false,则返回结果是不确定的

func (*GenericNumber) Int64

func (num *GenericNumber) Int64() int64

将值转换为 int64 如果 IsInt64 == false,则返回结果是不确定的

func (*GenericNumber) IsFloat64

func (num *GenericNumber) IsFloat64() bool

查看是否可以将值转换成 float64

func (*GenericNumber) IsInt64

func (num *GenericNumber) IsInt64() bool

查看是否可以将值转换成 int64

func (*GenericNumber) IsUInt64

func (num *GenericNumber) IsUInt64() bool

查看是否可以将值转换成 uint64

func (*GenericNumber) String

func (num *GenericNumber) String() string

func (*GenericNumber) UInt64

func (num *GenericNumber) UInt64() uint64

将值转换为 uint64 如果 IsUInt64 == false,则返回结果是不确定的

func (*GenericNumber) Unsigned

func (num *GenericNumber) Unsigned() bool

type Number

type Number interface {
	AsNumber() *GenericNumber
}

type String

type String string

func (String) String

func (s String) String() string

type Stringer

type Stringer = fmt.Stringer

func ToStringer

func ToStringer(v interface{}) Stringer

type Type

type Type uint8
const (
	InvalidType Type = iota
	NilType
	BoolType
	NumberType
	StringType
)

func MapReflectType

func MapReflectType(p reflect.Kind) Type

type Value

type Value interface{}

func AsType

func AsType(value interface{}, checkType Type) (Value, bool)

Jump to

Keyboard shortcuts

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