strconv

Imports

Imports #

"math/bits"
"math/bits"
"errors"
"internal/stringslite"
"math"
"math/bits"
"math"
"math"
"unicode/utf8"
"internal/stringslite"
"internal/bytealg"

Constants & Variables

ErrRange var #

ErrRange indicates that a value is out of range for the target type.

var ErrRange = *ast.CallExpr

ErrSyntax var #

ErrSyntax indicates that a value does not have the right syntax for the target type.

var ErrSyntax = *ast.CallExpr

IntSize const #

IntSize is the size in bits of an int or uint value.

const IntSize = intSize

detailedPowersOfTen var #

detailedPowersOfTen contains 128-bit mantissa approximations (rounded down) to the powers of 10. For example: - 1e43 ≈ (0xE596B7B0_C643C719 * (2 ** 79)) - 1e43 = (0xE596B7B0_C643C719_6D9CCD05_D0000000 * (2 ** 15)) The mantissas are explicitly listed. The exponents are implied by a linear expression with slope 217706.0/65536.0 ≈ log(10)/log(2). The table was generated by https://github.com/google/wuffs/blob/ba3818cb6b473a2ed0b38ecfc07dbbd3a97e8ae7/script/print-mpb-powers-of-10.go

var detailedPowersOfTen = [...][2]uint64{...}

detailedPowersOfTenMaxExp10 const #

detailedPowersOfTen{Min,Max}Exp10 is the power of 10 represented by the first and last rows of detailedPowersOfTen. Both bounds are inclusive.

const detailedPowersOfTenMaxExp10 = *ast.UnaryExpr

detailedPowersOfTenMinExp10 const #

detailedPowersOfTen{Min,Max}Exp10 is the power of 10 represented by the first and last rows of detailedPowersOfTen. Both bounds are inclusive.

const detailedPowersOfTenMinExp10 = *ast.UnaryExpr

digits const #

const digits = "0123456789abcdefghijklmnopqrstuvwxyz"

fastSmalls const #

const fastSmalls = true

float32info var #

var float32info = floatInfo{...}

float32pow10 var #

var float32pow10 = []float32{...}

float64info var #

var float64info = floatInfo{...}

float64pow10 var #

Exact powers of 10.

var float64pow10 = []float64{...}

fnParseComplex const #

const fnParseComplex = "ParseComplex"

fnParseFloat const #

const fnParseFloat = "ParseFloat"

host32bit const #

const host32bit = *ast.BinaryExpr

intSize const #

const intSize = *ast.BinaryExpr

isGraphic var #

isGraphic lists the graphic runes not matched by IsPrint.

var isGraphic = []uint16{...}

isNotPrint16 var #

var isNotPrint16 = []uint16{...}

isNotPrint32 var #

var isNotPrint32 = []uint16{...}

isPrint16 var #

var isPrint16 = []uint16{...}

isPrint32 var #

var isPrint32 = []uint32{...}

leftcheats var #

var leftcheats = []leftCheat{...}

lowerhex const #

const lowerhex = "0123456789abcdef"

maxShift const #

const maxShift = *ast.BinaryExpr

maxUint64 const #

const maxUint64 = *ast.BinaryExpr

nSmalls const #

const nSmalls = 100

optimize var #

var optimize = true

powtab var #

decimal power of ten to binary power of two.

var powtab = []int{...}

smallsString const #

const smallsString = *ast.BinaryExpr

uint64pow10 var #

var uint64pow10 = [...]uint64{...}

uintSize const #

Maximum shift that we can do in one pass without overflow. A uint has 32 or 64 bits, and we have to be able to accommodate 9<

const uintSize = *ast.BinaryExpr

upperhex const #

const upperhex = "0123456789ABCDEF"

Structs

NumError struct #

A NumError records a failed conversion.

type NumError struct {
Func string
Num string
Err error
}

decimal struct #

type decimal struct {
d [800]byte
nd int
dp int
neg bool
trunc bool
}

decimalSlice struct #

type decimalSlice struct {
d []byte
nd int
dp int
}

floatInfo struct #

TODO: move elsewhere?

type floatInfo struct {
mantbits uint
expbits uint
bias int
}

leftCheat struct #

type leftCheat struct {
delta int
cutoff string
}

Functions

AppendBool function #

AppendBool appends "true" or "false", according to the value of b, to dst and returns the extended buffer.

func AppendBool(dst []byte, b bool) []byte

AppendFloat function #

AppendFloat appends the string form of the floating-point number f, as generated by [FormatFloat], to dst and returns the extended buffer.

func AppendFloat(dst []byte, f float64, fmt byte, prec int, bitSize int) []byte

AppendInt function #

AppendInt appends the string form of the integer i, as generated by [FormatInt], to dst and returns the extended buffer.

func AppendInt(dst []byte, i int64, base int) []byte

AppendQuote function #

AppendQuote appends a double-quoted Go string literal representing s, as generated by [Quote], to dst and returns the extended buffer.

func AppendQuote(dst []byte, s string) []byte

AppendQuoteRune function #

AppendQuoteRune appends a single-quoted Go character literal representing the rune, as generated by [QuoteRune], to dst and returns the extended buffer.

func AppendQuoteRune(dst []byte, r rune) []byte

AppendQuoteRuneToASCII function #

AppendQuoteRuneToASCII appends a single-quoted Go character literal representing the rune, as generated by [QuoteRuneToASCII], to dst and returns the extended buffer.

func AppendQuoteRuneToASCII(dst []byte, r rune) []byte

AppendQuoteRuneToGraphic function #

AppendQuoteRuneToGraphic appends a single-quoted Go character literal representing the rune, as generated by [QuoteRuneToGraphic], to dst and returns the extended buffer.

func AppendQuoteRuneToGraphic(dst []byte, r rune) []byte

AppendQuoteToASCII function #

AppendQuoteToASCII appends a double-quoted Go string literal representing s, as generated by [QuoteToASCII], to dst and returns the extended buffer.

func AppendQuoteToASCII(dst []byte, s string) []byte

AppendQuoteToGraphic function #

AppendQuoteToGraphic appends a double-quoted Go string literal representing s, as generated by [QuoteToGraphic], to dst and returns the extended buffer.

func AppendQuoteToGraphic(dst []byte, s string) []byte

AppendUint function #

AppendUint appends the string form of the unsigned integer i, as generated by [FormatUint], to dst and returns the extended buffer.

func AppendUint(dst []byte, i uint64, base int) []byte

Assign method #

Assign v to a.

func (a *decimal) Assign(v uint64)

Atoi function #

Atoi is equivalent to ParseInt(s, 10, 0), converted to type int.

func Atoi(s string) (int, error)

CanBackquote function #

CanBackquote reports whether the string s can be represented unchanged as a single-line backquoted string without control characters other than tab.

func CanBackquote(s string) bool

Error method #

func (e *NumError) Error() string

FormatBool function #

FormatBool returns "true" or "false" according to the value of b.

func FormatBool(b bool) string

FormatComplex function #

FormatComplex converts the complex number c to a string of the form (a+bi) where a and b are the real and imaginary parts, formatted according to the format fmt and precision prec. The format fmt and precision prec have the same meaning as in [FormatFloat]. It rounds the result assuming that the original was obtained from a complex value of bitSize bits, which must be 64 for complex64 and 128 for complex128.

func FormatComplex(c complex128, fmt byte, prec int, bitSize int) string

FormatFloat function #

FormatFloat converts the floating-point number f to a string, according to the format fmt and precision prec. It rounds the result assuming that the original was obtained from a floating-point value of bitSize bits (32 for float32, 64 for float64). The format fmt is one of - 'b' (-ddddp±ddd, a binary exponent), - 'e' (-d.dddde±dd, a decimal exponent), - 'E' (-d.ddddE±dd, a decimal exponent), - 'f' (-ddd.dddd, no exponent), - 'g' ('e' for large exponents, 'f' otherwise), - 'G' ('E' for large exponents, 'f' otherwise), - 'x' (-0xd.ddddp±ddd, a hexadecimal fraction and binary exponent), or - 'X' (-0Xd.ddddP±ddd, a hexadecimal fraction and binary exponent). The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', 'G', 'x', and 'X' formats. For 'e', 'E', 'f', 'x', and 'X', it is the number of digits after the decimal point. For 'g' and 'G' it is the maximum number of significant digits (trailing zeros are removed). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly. The exponent is written as a decimal integer; for all formats other than 'b', it will be at least two digits.

func FormatFloat(f float64, fmt byte, prec int, bitSize int) string

FormatInt function #

FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.

func FormatInt(i int64, base int) string

FormatUint function #

FormatUint returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.

func FormatUint(i uint64, base int) string

IsGraphic function #

IsGraphic reports whether the rune is defined as a Graphic by Unicode. Such characters include letters, marks, numbers, punctuation, symbols, and spaces, from categories L, M, N, P, S, and Zs.

func IsGraphic(r rune) bool

IsPrint function #

IsPrint reports whether the rune is defined as printable by Go, with the same definition as [unicode.IsPrint]: letters, numbers, punctuation, symbols and ASCII space.

func IsPrint(r rune) bool

Itoa function #

Itoa is equivalent to [FormatInt](int64(i), 10).

func Itoa(i int) string

ParseBool function #

ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.

func ParseBool(str string) (bool, error)

ParseComplex function #

ParseComplex converts the string s to a complex number with the precision specified by bitSize: 64 for complex64, or 128 for complex128. When bitSize=64, the result still has type complex128, but it will be convertible to complex64 without changing its value. The number represented by s must be of the form N, Ni, or N±Ni, where N stands for a floating-point number as recognized by [ParseFloat], and i is the imaginary component. If the second N is unsigned, a + sign is required between the two components as indicated by the ±. If the second N is NaN, only a + sign is accepted. The form may be parenthesized and cannot contain any spaces. The resulting complex number consists of the two components converted by ParseFloat. The errors that ParseComplex returns have concrete type [*NumError] and include err.Num = s. If s is not syntactically well-formed, ParseComplex returns err.Err = ErrSyntax. If s is syntactically well-formed but either component is more than 1/2 ULP away from the largest floating point number of the given component's size, ParseComplex returns err.Err = ErrRange and c = ±Inf for the respective component.

func ParseComplex(s string, bitSize int) (complex128, error)

ParseFloat function #

ParseFloat converts the string s to a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64. When bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value. ParseFloat accepts decimal and hexadecimal floating-point numbers as defined by the Go syntax for [floating-point literals]. If s is well-formed and near a valid floating-point number, ParseFloat returns the nearest floating-point number rounded using IEEE754 unbiased rounding. (Parsing a hexadecimal floating-point value only rounds when there are more bits in the hexadecimal representation than will fit in the mantissa.) The errors that ParseFloat returns have concrete type *NumError and include err.Num = s. If s is not syntactically well-formed, ParseFloat returns err.Err = ErrSyntax. If s is syntactically well-formed but is more than 1/2 ULP away from the largest floating point number of the given size, ParseFloat returns f = ±Inf, err.Err = ErrRange. ParseFloat recognizes the string "NaN", and the (possibly signed) strings "Inf" and "Infinity" as their respective special floating point values. It ignores case when matching. [floating-point literals]: https://go.dev/ref/spec#Floating-point_literals

func ParseFloat(s string, bitSize int) (float64, error)

ParseInt function #

ParseInt interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i. The string may begin with a leading sign: "+" or "-". If the base argument is 0, the true base is implied by the string's prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise. Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for [integer literals]. The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64. If bitSize is below 0 or above 64, an error is returned. The errors that ParseInt returns have concrete type [*NumError] and include err.Num = s. If s is empty or contains invalid digits, err.Err = [ErrSyntax] and the returned value is 0; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = [ErrRange] and the returned value is the maximum magnitude integer of the appropriate bitSize and sign. [integer literals]: https://go.dev/ref/spec#Integer_literals

func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseUint function #

ParseUint is like [ParseInt] but for unsigned numbers. A sign prefix is not permitted.

func ParseUint(s string, base int, bitSize int) (uint64, error)

Quote function #

Quote returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by [IsPrint].

func Quote(s string) string

QuoteRune function #

QuoteRune returns a single-quoted Go character literal representing the rune. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by [IsPrint]. If r is not a valid Unicode code point, it is interpreted as the Unicode replacement character U+FFFD.

func QuoteRune(r rune) string

QuoteRuneToASCII function #

QuoteRuneToASCII returns a single-quoted Go character literal representing the rune. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters as defined by [IsPrint]. If r is not a valid Unicode code point, it is interpreted as the Unicode replacement character U+FFFD.

func QuoteRuneToASCII(r rune) string

QuoteRuneToGraphic function #

QuoteRuneToGraphic returns a single-quoted Go character literal representing the rune. If the rune is not a Unicode graphic character, as defined by [IsGraphic], the returned string will use a Go escape sequence (\t, \n, \xFF, \u0100). If r is not a valid Unicode code point, it is interpreted as the Unicode replacement character U+FFFD.

func QuoteRuneToGraphic(r rune) string

QuoteToASCII function #

QuoteToASCII returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters as defined by [IsPrint].

func QuoteToASCII(s string) string

QuoteToGraphic function #

QuoteToGraphic returns a double-quoted Go string literal representing s. The returned string leaves Unicode graphic characters, as defined by [IsGraphic], unchanged and uses Go escape sequences (\t, \n, \xFF, \u0100) for non-graphic characters.

func QuoteToGraphic(s string) string

QuotedPrefix function #

QuotedPrefix returns the quoted string (as understood by [Unquote]) at the prefix of s. If s does not start with a valid quoted string, QuotedPrefix returns an error.

func QuotedPrefix(s string) (string, error)

Round method #

Round a to nd digits (or fewer). If nd is zero, it means we're rounding just to the left of the digits, as in 0.09 -> 0.1.

func (a *decimal) Round(nd int)

RoundDown method #

Round a down to nd digits (or fewer).

func (a *decimal) RoundDown(nd int)

RoundUp method #

Round a up to nd digits (or fewer).

func (a *decimal) RoundUp(nd int)

RoundedInteger method #

Extract integer part, rounded appropriately. No guarantees about overflow.

func (a *decimal) RoundedInteger() uint64

Shift method #

Binary shift left (k > 0) or right (k < 0).

func (a *decimal) Shift(k int)

String method #

func (a *decimal) String() string

Unquote function #

Unquote interprets s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes. (If s is single-quoted, it would be a Go character literal; Unquote returns the corresponding one-character string. For an empty character literal Unquote returns the empty string.)

func Unquote(s string) (string, error)

UnquoteChar function #

UnquoteChar decodes the first character or byte in the escaped string or character literal represented by the string s. It returns four values: 1. value, the decoded Unicode code point or byte value; 2. multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation; 3. tail, the remainder of the string after the character; and 4. an error that will be nil if the character is syntactically valid. The second argument, quote, specifies the type of literal being parsed and therefore which escaped quote character is permitted. If set to a single quote, it permits the sequence \' and disallows unescaped '. If set to a double quote, it permits \" and disallows unescaped ". If set to zero, it does not permit either escape and allows both quote characters to appear unescaped.

func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error)

Unwrap method #

func (e *NumError) Unwrap() error

appendEscapedRune function #

func appendEscapedRune(buf []byte, r rune, quote byte, ASCIIonly bool, graphicOnly bool) []byte

appendQuotedRuneWith function #

func appendQuotedRuneWith(buf []byte, r rune, quote byte, ASCIIonly bool, graphicOnly bool) []byte

appendQuotedWith function #

func appendQuotedWith(buf []byte, s string, quote byte, ASCIIonly bool, graphicOnly bool) []byte

atof32 function #

func atof32(s string) (f float32, n int, err error)

atof32exact function #

If possible to compute mantissa*10^exp to 32-bit float f exactly, entirely in floating-point math, do so, avoiding the machinery above.

func atof32exact(mantissa uint64, exp int, neg bool) (f float32, ok bool)

atof64 function #

func atof64(s string) (f float64, n int, err error)

atof64exact function #

If possible to convert decimal representation to 64-bit float f exactly, entirely in floating-point math, do so, avoiding the expense of decimalToFloatBits. Three common cases: value is exact integer value is exact integer * exact power of ten value is exact integer / exact power of ten These all produce potentially inexact but correctly rounded answers.

func atof64exact(mantissa uint64, exp int, neg bool) (f float64, ok bool)

atofHex function #

atofHex converts the hex floating-point string s to a rounded float32 or float64 value (depending on flt==&float32info or flt==&float64info) and returns it as a float64. The string s has already been parsed into a mantissa, exponent, and sign (neg==true for negative). If trunc is true, trailing non-zero bits have been omitted from the mantissa.

func atofHex(s string, flt *floatInfo, mantissa uint64, exp int, neg bool, trunc bool) (float64, error)

baseError function #

func baseError(fn string, str string, base int) *NumError

bigFtoa function #

bigFtoa uses multiprecision computations to format a float.

func bigFtoa(dst []byte, prec int, fmt byte, neg bool, mant uint64, exp int, flt *floatInfo) []byte

bitSizeError function #

func bitSizeError(fn string, str string, bitSize int) *NumError

bsearch function #

bsearch is semantically the same as [slices.BinarySearch] (without NaN checks) We copied this function because we can not import "slices" here.

func bsearch(s S, v E) (int, bool)

commonPrefixLenIgnoreCase function #

commonPrefixLenIgnoreCase returns the length of the common prefix of s and prefix, with the character case of s ignored. The prefix argument must be all lower-case.

func commonPrefixLenIgnoreCase(s string, prefix string) int

computeBounds function #

computeBounds returns a floating-point vector (l, c, u)×2^e2 where the mantissas are 55-bit (or 26-bit) integers, describing the interval represented by the input float64 or float32.

func computeBounds(mant uint64, exp int, flt *floatInfo) (lower uint64, central uint64, upper uint64, e2 int)

contains function #

contains reports whether the string contains the byte c.

func contains(s string, c byte) bool

convErr function #

convErr splits an error returned by parseFloatPrefix into a syntax or range error for ParseComplex.

func convErr(err error, s string) (syntax error, range_ error)

digitZero function #

func digitZero(dst []byte) int

divisibleByPower5 function #

func divisibleByPower5(m uint64, k int) bool

divmod1e9 function #

divmod1e9 computes quotient and remainder of division by 1e9, avoiding runtime uint64 division on 32-bit platforms.

func divmod1e9(x uint64) (uint32, uint32)

eiselLemire32 function #

func eiselLemire32(man uint64, exp10 int, neg bool) (f float32, ok bool)

eiselLemire64 function #

func eiselLemire64(man uint64, exp10 int, neg bool) (f float64, ok bool)

floatBits method #

func (d *decimal) floatBits(flt *floatInfo) (b uint64, overflow bool)

fmtB function #

%b: -ddddddddp±ddd

func fmtB(dst []byte, neg bool, mant uint64, exp int, flt *floatInfo) []byte

fmtE function #

%e: -d.ddddde±dd

func fmtE(dst []byte, neg bool, d decimalSlice, prec int, fmt byte) []byte

fmtF function #

%f: -ddddddd.ddddd

func fmtF(dst []byte, neg bool, d decimalSlice, prec int) []byte

fmtX function #

%x: -0x1.yyyyyyyyp±ddd or -0x0p+0. (y is hex digit, d is decimal digit)

func fmtX(dst []byte, prec int, fmt byte, neg bool, mant uint64, exp int, flt *floatInfo) []byte

formatBits function #

formatBits computes the string representation of u in the given base. If neg is set, u is treated as negative int64 value. If append_ is set, the string is appended to dst and the resulting byte slice is returned as the first result value; otherwise the string is returned as the second result value.

func formatBits(dst []byte, u uint64, base int, neg bool, append_ bool) (d []byte, s string)

formatDecimal function #

formatDecimal fills d with at most prec decimal digits of mantissa m. The boolean trunc indicates whether m is truncated compared to the original number being formatted.

func formatDecimal(d *decimalSlice, m uint64, trunc bool, roundUp bool, prec int)

formatDigits function #

func formatDigits(dst []byte, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte) []byte

genericFtoa function #

func genericFtoa(dst []byte, val float64, fmt byte, prec int, bitSize int) []byte

index function #

index returns the index of the first instance of c in s, or -1 if missing.

func index(s string, c byte) int

index function #

index returns the index of the first instance of c in s, or -1 if missing.

func index(s string, c byte) int

isInGraphicList function #

isInGraphicList reports whether the rune is in the isGraphic list. This separation from IsGraphic allows quoteWith to avoid two calls to IsPrint. Should be called only if IsPrint fails.

func isInGraphicList(r rune) bool

isPowerOfTwo function #

func isPowerOfTwo(x int) bool

leftShift function #

Binary shift left (* 2) by k bits. k <= maxShift to avoid overflow.

func leftShift(a *decimal, k uint)

lower function #

lower(c) is a lower-case letter if and only if c is either that lower-case letter or the equivalent upper-case letter. Instead of writing c == 'x' || c == 'X' one can write lower(c) == 'x'. Note that lower of non-letters can produce other non-letters.

func lower(c byte) byte

mulByLog10Log2 function #

mulByLog10Log2 returns math.Floor(x * log(10)/log(2)) for an integer x in the range -500 <= x && x <= +500. The range restriction lets us work in faster integer arithmetic instead of slower floating point arithmetic. Correctness is verified by unit tests.

func mulByLog10Log2(x int) int

mulByLog2Log10 function #

mulByLog2Log10 returns math.Floor(x * log(2)/log(10)) for an integer x in the range -1600 <= x && x <= +1600. The range restriction lets us work in faster integer arithmetic instead of slower floating point arithmetic. Correctness is verified by unit tests.

func mulByLog2Log10(x int) int

mult128bitPow10 function #

mult128bitPow10 takes a floating-point input with a 55-bit mantissa and multiplies it with 10^q. The resulting mantissa is m*P >> 119 where P is a 128-bit element of the detailedPowersOfTen tables. It is typically 63 or 64-bit wide. The returned boolean is true is all trimmed bits were zero. That is: m*2^e2 * round(10^q) = resM * 2^resE + ε exact = ε == 0

func mult128bitPow10(m uint64, e2 int, q int) (resM uint64, resE int, exact bool)

mult64bitPow10 function #

mult64bitPow10 takes a floating-point input with a 25-bit mantissa and multiplies it with 10^q. The resulting mantissa is m*P >> 57 where P is a 64-bit element of the detailedPowersOfTen tables. It is typically 31 or 32-bit wide. The returned boolean is true if all trimmed bits were zero. That is: m*2^e2 * round(10^q) = resM * 2^resE + ε exact = ε == 0

func mult64bitPow10(m uint32, e2 int, q int) (resM uint32, resE int, exact bool)

parseFloatPrefix function #

func parseFloatPrefix(s string, bitSize int) (float64, int, error)

prefixIsLessThan function #

Is the leading prefix of b lexicographically less than s?

func prefixIsLessThan(b []byte, s string) bool

quoteRuneWith function #

func quoteRuneWith(r rune, quote byte, ASCIIonly bool, graphicOnly bool) string

quoteWith function #

func quoteWith(s string, quote byte, ASCIIonly bool, graphicOnly bool) string

rangeError function #

func rangeError(fn string, str string) *NumError

readFloat function #

readFloat reads a decimal or hexadecimal mantissa and exponent from a float string representation in s; the number may be followed by other characters. readFloat reports the number of bytes consumed (i), and whether the number is valid (ok).

func readFloat(s string) (mantissa uint64, exp int, neg bool, trunc bool, hex bool, i int, ok bool)

rightShift function #

Binary shift right (/ 2) by k bits. k <= maxShift to avoid overflow.

func rightShift(a *decimal, k uint)

roundShortest function #

roundShortest rounds d (= mant * 2^exp) to the shortest number of digits that will let the original floating point value be precisely reconstructed.

func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo)

ryuDigits function #

func ryuDigits(d *decimalSlice, lower uint64, central uint64, upper uint64, c0 bool, cup bool)

ryuDigits32 function #

ryuDigits32 emits decimal digits for a number less than 1e9.

func ryuDigits32(d *decimalSlice, lower uint32, central uint32, upper uint32, c0 bool, cup bool, endindex int)

ryuFtoaFixed32 function #

ryuFtoaFixed32 formats mant*(2^exp) with prec decimal digits.

func ryuFtoaFixed32(d *decimalSlice, mant uint32, exp int, prec int)

ryuFtoaFixed64 function #

ryuFtoaFixed64 formats mant*(2^exp) with prec decimal digits.

func ryuFtoaFixed64(d *decimalSlice, mant uint64, exp int, prec int)

ryuFtoaShortest function #

ryuFtoaShortest formats mant*2^exp with prec decimal digits.

func ryuFtoaShortest(d *decimalSlice, mant uint64, exp int, flt *floatInfo)

set method #

func (b *decimal) set(s string) (ok bool)

shouldRoundUp function #

If we chop a at nd digits, should we round up?

func shouldRoundUp(a *decimal, nd int) bool

small function #

small returns the string for an i with 0 <= i < nSmalls.

func small(i int) string

special function #

special returns the floating-point value for the special, possibly signed floating-point representations inf, infinity, and NaN. The result is ok if a prefix of s contains one of these representations and n is the length of that prefix. The character case is ignored.

func special(s string) (f float64, n int, ok bool)

syntaxError function #

func syntaxError(fn string, str string) *NumError

trim function #

trim trailing zeros from number. (They are meaningless; the decimal point is tracked independent of the number of digits.)

func trim(a *decimal)

underscoreOK function #

underscoreOK reports whether the underscores in s are allowed. Checking them in this one function lets all the parsers skip over them simply. Underscore must appear only between digits or between a base prefix and a digit.

func underscoreOK(s string) bool

unhex function #

func unhex(b byte) (v rune, ok bool)

unquote function #

unquote parses a quoted string at the start of the input, returning the parsed prefix, the remaining suffix, and any parse errors. If unescape is true, the parsed prefix is unescaped, otherwise the input prefix is provided verbatim.

func unquote(in string, unescape bool) (out string, rem string, err error)

Generated with Arrow