xnumber

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 3 Imported by: 7

README

xnumber

Dependencies

  • xtesting*

Documents

Types
  • type Accuracy func
Variables
  • None
Constants
  • const MinInt8 int8
  • const MinInt16 int16
  • const MinInt32 int32
  • const MinInt64 int64
  • const MinUint8 uint8
  • const MinUint16 uint16
  • const MinUint32 uint32
  • const MinUint64 uint64
  • const MaxInt8 int8
  • const MaxInt16 int16
  • const MaxInt32 int32
  • const MaxInt64 int64
  • const MaxUint8 uint8
  • const MaxUint16 uint16
  • const MaxUint32 uint32
  • const MaxUint64 uint64
  • const MaxFloat32 float32
  • const SmallestNonzeroFloat32 float32
  • const MaxFloat64 float64
  • const SmallestNonzeroFloat64 float64
Functions
Common functions
  • func NewAccuracy(eps float64) Accuracy
  • func EqualInAccuracy(a, b float64) bool
  • func NotEqualInAccuracy(a, b float64) bool
  • func GreaterInAccuracy(a, b float64) bool
  • func LessInAccuracy(a, b float64) bool
  • func GreaterOrEqualInAccuracy(a, b float64) bool
  • func LessOrEqualInAccuracy(a, b float64) bool
  • func RenderByte(bytes float64) string
  • func Bool(b bool) int
  • func IntSize() int
Parse and format functions
  • func ParseInt(s string, base int) (int, error)
  • func ParseInt8(s string, base int) (int8, error)
  • func ParseInt16(s string, base int) (int16, error)
  • func ParseInt32(s string, base int) (int32, error)
  • func ParseInt64(s string, base int) (int64, error)
  • func ParseUint(s string, base int) (uint, error)
  • func ParseUint8(s string, base int) (uint8, error)
  • func ParseUint16(s string, base int) (uint16, error)
  • func ParseUint32(s string, base int) (uint32, error)
  • func ParseUint64(s string, base int) (uint64, error)
  • func ParseFloat32(s string) (float32, error)
  • func ParseFloat64(s string) (float64, error)
  • func ParseIntOr(s string, base int, o int) int
  • func ParseInt8Or(s string, base int, o int8) int8
  • func ParseInt16Or(s string, base int, o int16) int16
  • func ParseInt32Or(s string, base int, o int32) int32
  • func ParseInt64Or(s string, base int, o int64) int64
  • func ParseUintOr(s string, base int, o uint) uint
  • func ParseUint8Or(s string, base int, o uint8) uint8
  • func ParseUint16Or(s string, base int, o uint16) uint16
  • func ParseUint32Or(s string, base int, o uint32) uint32
  • func ParseUint64Or(s string, base int, o uint64) uint64
  • func ParseFloat32Or(s string, o float32) float32
  • func ParseFloat64Or(s string, o float64) float64
  • func Atoi(s string) (int, error)
  • func Atoi8(s string) (int8, error)
  • func Atoi16(s string) (int16, error)
  • func Atoi32(s string) (int32, error)
  • func Atoi64(s string) (int64, error)
  • func Atou(s string) (uint, error)
  • func Atou8(s string) (uint8, error)
  • func Atou16(s string) (uint16, error)
  • func Atou32(s string) (uint32, error)
  • func Atou64(s string) (uint64, error)
  • func Atof32(s string) (float32, error)
  • func Atof64(s string) (float64, error)
  • func AtoiOr(s string, o int) int
  • func Atoi8Or(s string, o int8) int8
  • func Atoi16Or(s string, o int16) int16
  • func Atoi32Or(s string, o int32) int32
  • func Atoi64Or(s string, o int64) int64
  • func AtouOr(s string, o uint) uint
  • func Atou8Or(s string, o uint8) uint8
  • func Atou16Or(s string, o uint16) uint16
  • func Atou32Or(s string, o uint32) uint32
  • func Atou64Or(s string, o uint64) uint64
  • func Atof32Or(s string, o float32) float32
  • func Atof64Or(s string, o float64) float64
  • func FormatInt(i int, base int) string
  • func FormatInt8(i int8, base int) string
  • func FormatInt16(i int16, base int) string
  • func FormatInt32(i int32, base int) string
  • func FormatInt64(i int64, base int) string
  • func FormatUint(u uint, base int) string
  • func FormatUint8(u uint8, base int) string
  • func FormatUint16(u uint16, base int) string
  • func FormatUint32(u uint32, base int) string
  • func FormatUint64(u uint64, base int) string
  • func FormatFloat32(f float32, fmt byte, prec int) string
  • func FormatFloat64(f float64, fmt byte, prec int) string
  • func Itoa(i int) string
  • func I8toa(i int8) string
  • func I16toa(i int16) string
  • func I32toa(i int32) string
  • func I64toa(i int64) string
  • func Utoa(u uint) string
  • func U8toa(u uint8) string
  • func U16toa(u uint16) string
  • func U32toa(u uint32) string
  • func U64toa(u uint64) string
  • func F32toa(f float32) string
  • func F64toa(f float64) string
Methods
  • func (eps Accuracy) Equal(a, b float64) bool
  • func (eps Accuracy) NotEqual(a, b float64) bool
  • func (eps Accuracy) Greater(a, b float64) bool
  • func (eps Accuracy) Less(a, b float64) bool
  • func (eps Accuracy) GreaterOrEqual(a, b float64) bool
  • func (eps Accuracy) LessOrEqual(a, b float64) bool

Documentation

Index

Constants

View Source
const (
	MinInt8   = int8(-128)                  // -1 << 7,  see math.MinInt8.
	MinInt16  = int16(-32768)               // -1 << 15, see math.MinInt16.
	MinInt32  = int32(-2147483648)          // -1 << 31, see math.MinInt32.
	MinInt64  = int64(-9223372036854775808) // -1 << 63, see math.MinInt64.
	MinUint8  = uint8(0)                    // 0.
	MinUint16 = uint16(0)                   // 0.
	MinUint32 = uint32(0)                   // 0.
	MinUint64 = uint64(0)                   // 0.

	MaxInt8   = int8(127)                    // 1 << 7  - 1, see math.MaxInt8.
	MaxInt16  = int16(32767)                 // 1 << 15 - 1, see math.MaxInt16.
	MaxInt32  = int32(2147483647)            // 1 << 31 - 1, see math.MaxInt32.
	MaxInt64  = int64(9223372036854775807)   // 1 << 63 - 1, see math.MaxInt64.
	MaxUint8  = uint8(255)                   // 1 << 8  - 1, see math.MaxUint8.
	MaxUint16 = uint16(65535)                // 1 << 16 - 1, see math.MaxUint16.
	MaxUint32 = uint32(4294967295)           // 1 << 32 - 1, see math.MaxUint32.
	MaxUint64 = uint64(18446744073709551615) // 1 << 64 - 1, see math.MaxUint64.

	MaxFloat32             = float32(math.MaxFloat32)             // 2**127 * (2**24 - 1) / 2**23, see math.MaxFloat32.
	SmallestNonzeroFloat32 = float32(math.SmallestNonzeroFloat32) // 1 / 2**(127 - 1 + 23), see math.SmallestNonzeroFloat32.
	MaxFloat64             = float64(math.MaxFloat64)             // 2**1023 * (2**53 - 1) / 2**52, see math.MaxFloat64.
	SmallestNonzeroFloat64 = float64(math.SmallestNonzeroFloat64) // 1 / 2**(1023 - 1 + 52), see math.SmallestNonzeroFloat64.
)

Variables

This section is empty.

Functions

func Atof32

func Atof32(s string) (float32, error)

Atof32 parses a string to float32, is same as ParseFloat32.

func Atof32Or added in v1.5.0

func Atof32Or(s string, o float32) float32

Atof32Or parses a string to float32 with a fallback value.

func Atof64

func Atof64(s string) (float64, error)

Atof64 parses a string to float32, is same as ParseFloat64.

func Atof64Or added in v1.5.0

func Atof64Or(s string, o float64) float64

Atof64Or parses a string to float32 with a fallback value.

func Atoi

func Atoi(s string) (int, error)

Atoi parses a string to int in base 10.

func Atoi16

func Atoi16(s string) (int16, error)

Atoi16 parses a string to int8 in base 10.

func Atoi16Or added in v1.5.0

func Atoi16Or(s string, o int16) int16

Atoi16Or parses a string to int8 in base 10 with a fallback value.

func Atoi32

func Atoi32(s string) (int32, error)

Atoi32 parses a string to int32 in base 10.

func Atoi32Or added in v1.5.0

func Atoi32Or(s string, o int32) int32

Atoi32Or parses a string to int32 in base 10 with a fallback value.

func Atoi64

func Atoi64(s string) (int64, error)

Atoi64 parses a string to int64 in base 10.

func Atoi64Or added in v1.5.0

func Atoi64Or(s string, o int64) int64

Atoi64Or parses a string to int64 in base 10 with a fallback value.

func Atoi8

func Atoi8(s string) (int8, error)

Atoi8 parses a string to int8 in base 10.

func Atoi8Or added in v1.5.0

func Atoi8Or(s string, o int8) int8

Atoi8Or parses a string to int8 in base 10 with a fallback value.

func AtoiOr added in v1.5.0

func AtoiOr(s string, o int) int

AtoiOr parses a string to int in base 10 with a fallback value.

func Atou

func Atou(s string) (uint, error)

Atou parses a string to uint in base 10.

func Atou16

func Atou16(s string) (uint16, error)

Atou16 parses a string to uint16 in base 10.

func Atou16Or added in v1.5.0

func Atou16Or(s string, o uint16) uint16

Atou16Or parses a string to uint16 in base 10 with a fallback value.

func Atou32

func Atou32(s string) (uint32, error)

Atou32 parses a string to uint32 in base 10.

func Atou32Or added in v1.5.0

func Atou32Or(s string, o uint32) uint32

Atou32Or parses a string to uint32 in base 10 with a fallback value.

func Atou64

func Atou64(s string) (uint64, error)

Atou64 parses a string to uint64 in base 10.

func Atou64Or added in v1.5.0

func Atou64Or(s string, o uint64) uint64

Atou64Or parses a string to uint64 in base 10 with a fallback value.

func Atou8

func Atou8(s string) (uint8, error)

Atou8 parses a string to uint8 in base 10.

func Atou8Or added in v1.5.0

func Atou8Or(s string, o uint8) uint8

Atou8Or parses a string to uint8 in base 10 with a fallback value.

func AtouOr added in v1.5.0

func AtouOr(s string, o uint) uint

AtouOr parses a string to uint in base 10 with a fallback value.

func Bool added in v1.3.3

func Bool(b bool) int

Bool returns 1 if value is true, otherwise returns 0.

func EqualInAccuracy added in v1.5.0

func EqualInAccuracy(a, b float64) bool

EqualInAccuracy checks eq between two float64 in default Accuracy: 1e-3.

func F32toa

func F32toa(f float32) string

F32toa formats a float32 to string using default format.

func F64toa

func F64toa(f float64) string

F64toa formats a float64 to string using default format.

func FormatFloat32

func FormatFloat32(f float32, fmt byte, prec int) string

FormatFloat32 formats a float32 to string using given format and precision.

func FormatFloat64

func FormatFloat64(f float64, fmt byte, prec int) string

FormatFloat64 formats a float64 to string using given format and precision.

func FormatInt

func FormatInt(i int, base int) string

FormatInt formats a int to string using given base.

func FormatInt16

func FormatInt16(i int16, base int) string

FormatInt16 formats a int16 to string using given base.

func FormatInt32

func FormatInt32(i int32, base int) string

FormatInt32 formats a int32 to string using given base.

func FormatInt64

func FormatInt64(i int64, base int) string

FormatInt64 formats a int64 to string using given base.

func FormatInt8

func FormatInt8(i int8, base int) string

FormatInt8 formats a int8 to string using given base.

func FormatUint

func FormatUint(u uint, base int) string

FormatUint formats a uint to string using given base.

func FormatUint16

func FormatUint16(u uint16, base int) string

FormatUint16 formats a uint16 to string using given base.

func FormatUint32

func FormatUint32(u uint32, base int) string

FormatUint32 formats a uint32 to string using given base.

func FormatUint64

func FormatUint64(u uint64, base int) string

FormatUint64 formats a uint64 to string using given base.

func FormatUint8

func FormatUint8(u uint8, base int) string

FormatUint8 formats a uint8 to string using given base.

func GreaterInAccuracy added in v1.5.0

func GreaterInAccuracy(a, b float64) bool

GreaterInAccuracy checks gt between two float64 in default Accuracy: 1e-3.

func GreaterOrEqualInAccuracy added in v1.5.0

func GreaterOrEqualInAccuracy(a, b float64) bool

GreaterOrEqualInAccuracy checks gte between two float64 in default Accuracy: 1e-3.

func I16toa

func I16toa(i int16) string

I16toa formats a int16 to string in base 10.

func I32toa

func I32toa(i int32) string

I32toa formats a int32 to string in base 10.

func I64toa

func I64toa(i int64) string

I64toa formats a int64 to string in base 10.

func I8toa

func I8toa(i int8) string

I8toa formats a int8 to string in base 10.

func IntSize added in v1.5.0

func IntSize() int

IntSize returns the int size (32 / 64).

func Itoa

func Itoa(i int) string

Itoa formats a int to string in base 10.

func LessInAccuracy added in v1.5.0

func LessInAccuracy(a, b float64) bool

LessInAccuracy checks lt between two float64 in default Accuracy: 1e-3.

func LessOrEqualInAccuracy added in v1.5.0

func LessOrEqualInAccuracy(a, b float64) bool

LessOrEqualInAccuracy checks lte between two float64 in default Accuracy: 1e-3.

func NotEqualInAccuracy added in v1.5.0

func NotEqualInAccuracy(a, b float64) bool

NotEqualInAccuracy checks ne between two float64 in default Accuracy: 1e-3.

func ParseFloat32

func ParseFloat32(s string) (float32, error)

ParseFloat32 parses a string to float32.

func ParseFloat32Or added in v1.5.0

func ParseFloat32Or(s string, o float32) float32

ParseFloat32Or parses a string to float32 with a fallback value.

func ParseFloat64

func ParseFloat64(s string) (float64, error)

ParseFloat64 parses a string to float64.

func ParseFloat64Or added in v1.5.0

func ParseFloat64Or(s string, o float64) float64

ParseFloat64Or parses a string to float64 with a fallback value.

func ParseInt

func ParseInt(s string, base int) (int, error)

ParseInt parses a string to int using given base.

func ParseInt16

func ParseInt16(s string, base int) (int16, error)

ParseInt16 parses a string to int16 using given base.

func ParseInt16Or added in v1.5.0

func ParseInt16Or(s string, base int, o int16) int16

ParseInt16Or parses a string to int16 using given base with a fallback value.

func ParseInt32

func ParseInt32(s string, base int) (int32, error)

ParseInt32 parses a string to int32 using given base.

func ParseInt32Or added in v1.5.0

func ParseInt32Or(s string, base int, o int32) int32

ParseInt32Or parses a string to int32 using given base with a fallback value.

func ParseInt64

func ParseInt64(s string, base int) (int64, error)

ParseInt64 parses a string to int64 using given base.

func ParseInt64Or added in v1.5.0

func ParseInt64Or(s string, base int, o int64) int64

ParseInt64Or parses a string to int64 using given base with a fallback value.

func ParseInt8

func ParseInt8(s string, base int) (int8, error)

ParseInt8 parses a string to int8 using given base.

func ParseInt8Or added in v1.5.0

func ParseInt8Or(s string, base int, o int8) int8

ParseInt8Or parses a string to int8 using given base with a fallback value.

func ParseIntOr added in v1.5.0

func ParseIntOr(s string, base int, o int) int

ParseIntOr parses a string to int using given base with a fallback value.

func ParseUint

func ParseUint(s string, base int) (uint, error)

ParseUint parses a string to uint using given base.

func ParseUint16

func ParseUint16(s string, base int) (uint16, error)

ParseUint16 parses a string to uint16 using given base.

func ParseUint16Or added in v1.5.0

func ParseUint16Or(s string, base int, o uint16) uint16

ParseUint16Or parses a string to uint16 using given base with a fallback value.

func ParseUint32

func ParseUint32(s string, base int) (uint32, error)

ParseUint32 parses a string to uint32 using given base.

func ParseUint32Or added in v1.5.0

func ParseUint32Or(s string, base int, o uint32) uint32

ParseUint32Or parses a string to uint32 using given base with a fallback value.

func ParseUint64

func ParseUint64(s string, base int) (uint64, error)

ParseUint64 parses a string to uint64 using given base.

func ParseUint64Or added in v1.5.0

func ParseUint64Or(s string, base int, o uint64) uint64

ParseUint64Or parses a string to uint64 using given base with a fallback value.

func ParseUint8

func ParseUint8(s string, base int) (uint8, error)

ParseUint8 parses a string to uint8 using given base.

func ParseUint8Or added in v1.5.0

func ParseUint8Or(s string, base int, o uint8) uint8

ParseUint8Or parses a string to uint8 using given base with a fallback value.

func ParseUintOr added in v1.5.0

func ParseUintOr(s string, base int, o uint) uint

ParseUintOr parses a string to uint using given base with a fallback value.

func RenderByte

func RenderByte(bytes float64) string

RenderByte renders a byte size to string (using %.2f), support `B` `KB` `MB` `GB` `TB`.

func U16toa

func U16toa(u uint16) string

U16toa formats a uint16 to string in base 10.

func U32toa

func U32toa(u uint32) string

U32toa formats a uint32 to string in base 10.

func U64toa

func U64toa(u uint64) string

U64toa formats a uint64 to string in base 10.

func U8toa

func U8toa(u uint8) string

U8toa formats a uint8 to string in base 10.

func Utoa

func Utoa(u uint) string

Utoa formats a uint to string in base 10.

Types

type Accuracy

type Accuracy func() float64

Accuracy represents an accuracy with some compare methods in accuracy.

func NewAccuracy

func NewAccuracy(eps float64) Accuracy

NewAccuracy creates an Accuracy, using eps as its accuracy.

func (Accuracy) Equal

func (eps Accuracy) Equal(a, b float64) bool

Equal checks eq between two float64.

func (Accuracy) Greater

func (eps Accuracy) Greater(a, b float64) bool

Greater checks gt between two float64.

func (Accuracy) GreaterOrEqual

func (eps Accuracy) GreaterOrEqual(a, b float64) bool

GreaterOrEqual checks gte between two float64.

func (Accuracy) Less added in v1.5.0

func (eps Accuracy) Less(a, b float64) bool

Less checks lt between two float64.

func (Accuracy) LessOrEqual added in v1.5.0

func (eps Accuracy) LessOrEqual(a, b float64) bool

LessOrEqual checks lte between two float64.

func (Accuracy) NotEqual added in v1.3.4

func (eps Accuracy) NotEqual(a, b float64) bool

NotEqual checks ne between two float64.

Jump to

Keyboard shortcuts

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