number

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Number

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

Number is a versatile numeric representation that can hold different types of numeric values, such as integers, floating-point numbers, unsigned integers, as well as arbitrary-precision numbers (big integers and big floats).

The actual type of the numeric value stored is determined by the field 't' which is of type ValueType. Depending on this type: - For ValueType 'Int', the 'i' field (of type int) stores the value. - For ValueType 'Float', the 'f' field (of type float64) stores the value. - For ValueType 'Uint', the 'ui' field (of type uint64) stores the value. - For ValueType 'BigInt', the 'bi' field (a pointer to big.Int) stores the value. - For ValueType 'BigFloat', the 'bf' field (a pointer to big.Float) stores the value.

The appropriate field should be accessed based on the ValueType to get the correct numeric value. Methods like I(), F(), Ui(), Bi(), and Bf() are provided to retrieve these values safely.

It's also worth noting that the zero value of this struct isn't a valid representation and would need initialization before use. The FromString function can be used to initialize a Number from its string representation.

func FromString

func FromString(s string, isBig bool) (*Number, error)

FromString creates a new Number from a string representation. It determines the appropriate type of the number based on the provided string and a flag indicating whether it's a big number.

func NewBigFloat

func NewBigFloat(value *big.Float) *Number

NewBigFloat creates a new Number from a *big.Float value.

func NewBigInt

func NewBigInt(value *big.Int) *Number

NewBigInt creates a new Number from a *big.Int value.

func NewFloat

func NewFloat(value float64) *Number

NewFloat creates a new Number from a float64 value.

func NewInt

func NewInt(value int) *Number

NewInt creates a new Number from an int value.

func NewUint

func NewUint(value uint64) *Number

NewUint creates a new Number from a uint64 value.

func (*Number) Bf

func (n *Number) Bf() *big.Float

func (*Number) Bi

func (n *Number) Bi() *big.Int

func (*Number) F

func (n *Number) F() float64

func (*Number) I

func (n *Number) I() int

func (*Number) String

func (n *Number) String() string

func (*Number) T

func (n *Number) T() ValueType

func (*Number) Ui

func (n *Number) Ui() uint64

type ValueType

type ValueType int
const (
	Int ValueType = iota
	Float
	Uint
	BigInt
	BigFloat
)

func (ValueType) String

func (n ValueType) String() string

Jump to

Keyboard shortcuts

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