numconv

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package numconv implements the conversions between JavaScript numbers and strings, the integer and binary16 conversions of numbers, and arithmetic of numbers and BigInts.

Index

Constants

View Source
const MaxBigIntBits = 1 << 30

MaxBigIntBits is the largest number of bits of the magnitude of a BigInt.

View Source
const MaxSafeInteger = 1<<53 - 1

MaxSafeInteger is 2**53 - 1.

Variables

View Source
var (
	// ErrNotBigInt is the error of a string that is not a BigInt literal.
	ErrNotBigInt = errors.New("numconv: not a BigInt literal")
	// ErrBigIntTooLarge is the error of a BigInt literal with too many bits.
	ErrBigIntTooLarge = errors.New("numconv: BigInt too large")
)

Errors of StringToBigInt.

Functions

func AppendNumber

func AppendNumber(dst []byte, n float64) []byte

AppendNumber appends the result of Number::toString for radix 10 to dst.

func BigIntDigitsTooLarge

func BigIntDigitsTooLarge(s string, radix int, poll func()) bool

BigIntDigitsTooLarge reports whether the integer of the valid digits s in the radix, which is from 2 to 36, has more than MaxBigIntBits bits. poll, which may be nil, is called between the steps of a long check and may stop it by panicking.

func DigitValue

func DigitValue(c byte) int

DigitValue returns the base-36 value of an ASCII digit (0-9) or letter (A-Z or a-z). It returns 36 for any other byte.

func ExpBigInt

func ExpBigInt(r, a *big.Int, n int64, poll func())

ExpBigInt sets r, which is not a, to a to the power of the non-negative n. poll, which may be nil, is called between the steps of a long exponentiation and may stop it by panicking.

func Float16Bits

func Float16Bits(f float64) uint16

Float16Bits returns the binary16 encoding of f rounded to binary16.

func Float16FromBits

func Float16FromBits(h uint16) float64

Float16FromBits returns the number that the binary16 encoding h stands for.

func FormatBigInt

func FormatBigInt(x *big.Int, radix int, poll func()) wtf8.String

FormatBigInt returns the digits of x in the radix, which is from 2 to 36, as big.Int.Text does. poll, which may be nil, is called between the steps of a long conversion and may stop it by panicking.

func InInt64Range

func InInt64Range(f float64) bool

InInt64Range reports whether int64(f) is f rounded toward zero. Then ToInt32(f) is int32(int64(f)) and ToUint32(f) is uint32(int64(f)).

func MulBigInt

func MulBigInt(x, y *big.Int, poll func()) *big.Int

MulBigInt returns x × y. poll, which may be nil, is called between the steps of a long multiplication and may stop it by panicking.

func NumberPow

func NumberPow(x, y float64) float64

NumberPow implements Number::exponentiate.

func NumberToRadixString

func NumberToRadixString(n float64, radix int) wtf8.String

NumberToRadixString implements Number::toString for a radix other than 10.

func NumberToString

func NumberToString(n float64) wtf8.String

NumberToString implements Number::toString for radix 10.

func ParseBigInt

func ParseBigInt(s string, radix int, poll func()) (*big.Int, bool)

ParseBigInt returns the integer that the digits s denote in the radix, which is from 2 to 36. It reports false when s is empty or has a character other than such a digit. poll, which may be nil, is called between the steps of a long conversion and may stop it by panicking.

func ParseDecimal

func ParseDecimal(s string, poll func()) float64

ParseDecimal returns the value of s, a StrDecimalLiteral other than Infinity, rounded to the nearest number. poll is as for StringToNumber.

func ParseFloat

func ParseFloat(str wtf8.String, poll func()) float64

ParseFloat implements parseFloat: the longest prefix of str that is a decimal literal. poll is as for StringToNumber.

func ParseInt

func ParseInt(str wtf8.String, radix int, poll func()) float64

ParseInt implements parseInt. poll is as for StringToNumber.

func ParseRadixDigits

func ParseRadixDigits(s string, radix int, poll func()) (f float64, ok bool)

ParseRadixDigits returns the value of s, which consists of digits of the given radix, rounded to the nearest number. ok is false when s is empty or has another character. poll is as for StringToNumber.

func Pow10

func Pow10(n int) float64

Pow10 returns the double nearest to 10**n.

func PowBitLen

func PowBitLen(a *big.Int, n int64) int64

PowBitLen returns the bit length of a to the power of n, for |a| > 1 and n ≥ 0, or a number at most two below it. It is exact when a is a power of two.

func QuoRemBigInt

func QuoRemBigInt(x, y *big.Int, poll func()) (*big.Int, *big.Int)

QuoRemBigInt returns the quotient truncated toward zero and the remainder of x / y as big.Int.QuoRem does, for y that is not zero. poll, which may be nil, is called between the steps of a long division and may stop it by panicking.

func RelativeIndex

func RelativeIndex(f float64, length int) int

RelativeIndex resolves an index argument that counts from the end when negative against a length, clamping the result to the range from 0 to length.

func RoundFloat16

func RoundFloat16(f float64) float64

RoundFloat16 returns f rounded to the nearest binary16 value, ties to even.

func StringToBigInt

func StringToBigInt(str wtf8.String, maxBits int, poll func()) (*big.Int, error)

StringToBigInt implements StringToBigInt. It returns ErrNotBigInt when str is not a BigInt literal, and -1 or 1, the sign of the value, with ErrBigIntTooLarge when the value has more than maxBits bits. poll, which may be nil, is called between the steps of a long conversion and may stop it by panicking.

func StringToNumber

func StringToNumber(str wtf8.String, poll func()) float64

StringToNumber implements StringToNumber. poll, which may be nil, is called now and then during the conversion of a long string, and may stop it by panicking.

func ToInt32

func ToInt32(f float64) int32

ToInt32 implements ToInt32 for a number.

func ToIntegerOrInfinity

func ToIntegerOrInfinity(f float64) float64

ToIntegerOrInfinity implements ToIntegerOrInfinity for a number.

func ToLength

func ToLength(f float64) int64

ToLength implements ToLength for a number.

func ToUint8Clamp

func ToUint8Clamp(f float64) byte

ToUint8Clamp implements ToUint8Clamp for a number.

func ToUint32

func ToUint32(f float64) uint32

ToUint32 implements ToUint32 for a number.

Types

This section is empty.

Jump to

Keyboard shortcuts

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