number

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToFloat64

func ToFloat64(n Number) float64

ToFloat64 converts Number to float64.

func ToInt64

func ToInt64(n Number) int64

ToInt64 converts Number to int64.

Types

type Any

type Any interface {
	int64 | float64
}

Any is any of the supported generic Number types.

type Float64Traits

type Float64Traits struct{}

Float64Traits implements Traits[float64].

func (Float64Traits) AddAtomic

func (Float64Traits) AddAtomic(ptr *float64, value float64)

func (Float64Traits) FromNumber

func (Float64Traits) FromNumber(n Number) float64

func (Float64Traits) GetAtomic

func (Float64Traits) GetAtomic(ptr *float64) float64

func (Float64Traits) IsInf

func (Float64Traits) IsInf(value float64) bool

func (Float64Traits) IsNaN

func (Float64Traits) IsNaN(value float64) bool

func (Float64Traits) Kind

func (Float64Traits) Kind() Kind

func (Float64Traits) SetAtomic

func (Float64Traits) SetAtomic(ptr *float64, value float64)

func (Float64Traits) SwapAtomic

func (Float64Traits) SwapAtomic(ptr *float64, value float64) float64

func (Float64Traits) ToNumber

func (Float64Traits) ToNumber(x float64) Number

type Int64Traits

type Int64Traits struct{}

Int64Traits implements Traits[int64].

func (Int64Traits) AddAtomic

func (Int64Traits) AddAtomic(ptr *int64, value int64)

func (Int64Traits) FromNumber

func (Int64Traits) FromNumber(n Number) int64

func (Int64Traits) GetAtomic

func (Int64Traits) GetAtomic(ptr *int64) int64

func (Int64Traits) IsInf

func (Int64Traits) IsInf(_ int64) bool

func (Int64Traits) IsNaN

func (Int64Traits) IsNaN(_ int64) bool

func (Int64Traits) Kind

func (Int64Traits) Kind() Kind

func (Int64Traits) SetAtomic

func (Int64Traits) SetAtomic(ptr *int64, value int64)

func (Int64Traits) SwapAtomic

func (Int64Traits) SwapAtomic(ptr *int64, value int64) int64

func (Int64Traits) ToNumber

func (Int64Traits) ToNumber(x int64) Number

type Kind

type Kind int8

Kind describes the data type of the Number.

const (
	// Int64Kind indicates int64.
	Int64Kind Kind = iota

	// Float64Kind indicates float64.
	Float64Kind
)

func (Kind) String

func (i Kind) String() string

type Number

type Number uint64

Number is a 64bit numeric value, one of the Any interface types.

func (Number) CoerceToFloat64

func (n Number) CoerceToFloat64(k Kind) float64

CoerceToFloat64 converts Number to float64 according to Kind.

type Traits

type Traits[N Any] interface {
	// FromNumber turns a generic 64bits into the correct machine type.
	FromNumber(Number) N

	// ToNumber turns this type into a generic 64bit value.
	ToNumber(value N) Number

	// SetAtomic sets `ptr` to `value`.
	SetAtomic(ptr *N, value N)

	// GetAtomic reads `ptr`.
	GetAtomic(ptr *N) N

	// AddAtomic sets `ptr` to `value+*ptr`.
	AddAtomic(ptr *N, value N)

	// SwapAtomic sets `ptr` to `value` and returns the former value.
	SwapAtomic(ptr *N, value N) N

	// IsNaN indicates whether `math.IsNaN()` is true (impossible for int64).
	IsNaN(value N) bool

	// IsInf indicates whether `math.IsInf()` is true (impossible for int64).
	IsInf(value N) bool

	// Kind returns the number kind of these Traits.
	Kind() Kind
}

Traits is the generic traits interface for numbers used in the SDK.

Jump to

Keyboard shortcuts

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