var floatZero … // SetString sets z to the value of s and returns z and a boolean indicating // success. s must be a floating-point number of the same format as accepted // by [Float.Parse], with base argument 0. The entire string (not just a prefix) must // be valid for success. If the operation failed, the value of z is undefined // but the returned value is nil. func (z *Float) SetString(s string) (*Float, bool) { … } // scan is like Parse but reads the longest possible prefix representing a valid // floating point number from an io.ByteScanner rather than a string. It serves // as the implementation of Parse. It does not recognize ±Inf and does not expect // EOF at the end. func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error) { … } var pow5tab … // pow5 sets z to 5**n and returns z. // n must not be negative. func (z *Float) pow5(n uint64) *Float { … } // Parse parses s which must contain a text representation of a floating- // point number with a mantissa in the given conversion base (the exponent // is always a decimal number), or a string representing an infinite value. // // For base 0, an underscore character “_” may appear between a base // prefix and an adjacent digit, and between successive digits; such // underscores do not change the value of the number, or the returned // digit count. Incorrect placement of underscores is reported as an // error if there are no other errors. If base != 0, underscores are // not recognized and thus terminate scanning like any other character // that is not a valid radix point or digit. // // It sets z to the (possibly rounded) value of the corresponding floating- // point value, and returns z, the actual base b, and an error err, if any. // The entire string (not just a prefix) must be consumed for success. // If z's precision is 0, it is changed to 64 before rounding takes effect. // The number must be of the form: // // number = [ sign ] ( float | "inf" | "Inf" ) . // sign = "+" | "-" . // float = ( mantissa | prefix pmantissa ) [ exponent ] . // prefix = "0" [ "b" | "B" | "o" | "O" | "x" | "X" ] . // mantissa = digits "." [ digits ] | digits | "." digits . // pmantissa = [ "_" ] digits "." [ digits ] | [ "_" ] digits | "." digits . // exponent = ( "e" | "E" | "p" | "P" ) [ sign ] digits . // digits = digit { [ "_" ] digit } . // digit = "0" ... "9" | "a" ... "z" | "A" ... "Z" . // // The base argument must be 0, 2, 8, 10, or 16. Providing an invalid base // argument will lead to a run-time panic. // // For base 0, the number prefix determines the actual base: A prefix of // “0b” or “0B” selects base 2, “0o” or “0O” selects base 8, and // “0x” or “0X” selects base 16. Otherwise, the actual base is 10 and // no prefix is accepted. The octal prefix "0" is not supported (a leading // "0" is simply considered a "0"). // // A "p" or "P" exponent indicates a base 2 (rather than base 10) exponent; // for instance, "0x1.fffffffffffffp1023" (using base 0) represents the // maximum float64 value. For hexadecimal mantissae, the exponent character // must be one of 'p' or 'P', if present (an "e" or "E" exponent indicator // cannot be distinguished from a mantissa digit). // // The returned *Float f is nil and the value of z is valid but not // defined if an error is reported. func (z *Float) Parse(s string, base int) (f *Float, b int, err error) { … } // ParseFloat is like f.Parse(s, base) with f set to the given precision // and rounding mode. func ParseFloat(s string, base int, prec uint, mode RoundingMode) (f *Float, b int, err error) { … } var _ … // Scan is a support routine for [fmt.Scanner]; it sets z to the value of // the scanned number. It accepts formats whose verbs are supported by // [fmt.Scan] for floating point values, which are: // 'b' (binary), 'e', 'E', 'f', 'F', 'g' and 'G'. // Scan doesn't handle ±Inf. func (z *Float) Scan(s fmt.ScanState, ch rune) error { … }