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
- Variables
- func AppendNumber(dst []byte, n float64) []byte
- func BigIntDigitsTooLarge(s string, radix int, poll func()) bool
- func DigitValue(c byte) int
- func ExpBigInt(r, a *big.Int, n int64, poll func())
- func Float16Bits(f float64) uint16
- func Float16FromBits(h uint16) float64
- func FormatBigInt(x *big.Int, radix int, poll func()) wtf8.String
- func InInt64Range(f float64) bool
- func MulBigInt(x, y *big.Int, poll func()) *big.Int
- func NumberPow(x, y float64) float64
- func NumberToRadixString(n float64, radix int) wtf8.String
- func NumberToString(n float64) wtf8.String
- func ParseBigInt(s string, radix int, poll func()) (*big.Int, bool)
- func ParseDecimal(s string, poll func()) float64
- func ParseFloat(str wtf8.String, poll func()) float64
- func ParseInt(str wtf8.String, radix int, poll func()) float64
- func ParseRadixDigits(s string, radix int, poll func()) (f float64, ok bool)
- func Pow10(n int) float64
- func PowBitLen(a *big.Int, n int64) int64
- func QuoRemBigInt(x, y *big.Int, poll func()) (*big.Int, *big.Int)
- func RelativeIndex(f float64, length int) int
- func RoundFloat16(f float64) float64
- func StringToBigInt(str wtf8.String, maxBits int, poll func()) (*big.Int, error)
- func StringToNumber(str wtf8.String, poll func()) float64
- func ToInt32(f float64) int32
- func ToIntegerOrInfinity(f float64) float64
- func ToLength(f float64) int64
- func ToUint8Clamp(f float64) byte
- func ToUint32(f float64) uint32
Constants ¶
const MaxBigIntBits = 1 << 30
MaxBigIntBits is the largest number of bits of the magnitude of a BigInt.
const MaxSafeInteger = 1<<53 - 1
MaxSafeInteger is 2**53 - 1.
Variables ¶
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 ¶
AppendNumber appends the result of Number::toString for radix 10 to dst.
func BigIntDigitsTooLarge ¶
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 ¶
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 ¶
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 ¶
Float16Bits returns the binary16 encoding of f rounded to binary16.
func Float16FromBits ¶
Float16FromBits returns the number that the binary16 encoding h stands for.
func FormatBigInt ¶
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 ¶
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 ¶
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 NumberToRadixString ¶
NumberToRadixString implements Number::toString for a radix other than 10.
func NumberToString ¶
NumberToString implements Number::toString for radix 10.
func ParseBigInt ¶
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 ¶
ParseDecimal returns the value of s, a StrDecimalLiteral other than Infinity, rounded to the nearest number. poll is as for StringToNumber.
func ParseFloat ¶
ParseFloat implements parseFloat: the longest prefix of str that is a decimal literal. poll is as for StringToNumber.
func ParseInt ¶
ParseInt implements parseInt. poll is as for StringToNumber.
func ParseRadixDigits ¶
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 PowBitLen ¶
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 ¶
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 ¶
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 ¶
RoundFloat16 returns f rounded to the nearest binary16 value, ties to even.
func StringToBigInt ¶
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 ¶
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 ToIntegerOrInfinity ¶
ToIntegerOrInfinity implements ToIntegerOrInfinity for a number.
func ToUint8Clamp ¶
ToUint8Clamp implements ToUint8Clamp for a number.
Types ¶
This section is empty.