// Text converts the floating-point number x to a string according // to the given format and precision prec. The format is one of: // // 'e' -d.dddde±dd, decimal exponent, at least two (possibly 0) exponent digits // 'E' -d.ddddE±dd, decimal exponent, at least two (possibly 0) exponent digits // 'f' -ddddd.dddd, no exponent // 'g' like 'e' for large exponents, like 'f' otherwise // 'G' like 'E' for large exponents, like 'f' otherwise // 'x' -0xd.dddddp±dd, hexadecimal mantissa, decimal power of two exponent // 'p' -0x.dddp±dd, hexadecimal mantissa, decimal power of two exponent (non-standard) // 'b' -ddddddp±dd, decimal mantissa, decimal power of two exponent (non-standard) // // For the power-of-two exponent formats, the mantissa is printed in normalized form: // // 'x' hexadecimal mantissa in [1, 2), or 0 // 'p' hexadecimal mantissa in [½, 1), or 0 // 'b' decimal integer mantissa using x.Prec() bits, or 0 // // Note that the 'x' form is the one used by most other languages and libraries. // // If format is a different character, Text returns a "%" followed by the // unrecognized format character. // // The precision prec controls the number of digits (excluding the exponent) // printed by the 'e', 'E', 'f', 'g', 'G', and 'x' formats. // For 'e', 'E', 'f', and 'x', it is the number of digits after the decimal point. // For 'g' and 'G' it is the total number of digits. A negative precision selects // the smallest number of decimal digits necessary to identify the value x uniquely // using x.Prec() mantissa bits. // The prec value is ignored for the 'b' and 'p' formats. func (x *Float) Text(format byte, prec int) string { … } // String formats x like x.Text('g', 10). // (String must be called explicitly, [Float.Format] does not support %s verb.) func (x *Float) String() string { … } // Append appends to buf the string form of the floating-point number x, // as generated by x.Text, and returns the extended buffer. func (x *Float) Append(buf []byte, fmt byte, prec int) []byte { … } func roundShortest(d *decimal, x *Float) { … } // %e: d.ddddde±dd func fmtE(buf []byte, fmt byte, prec int, d decimal) []byte { … } // %f: ddddddd.ddddd func fmtF(buf []byte, prec int, d decimal) []byte { … } // fmtB appends the string of x in the format mantissa "p" exponent // with a decimal mantissa and a binary exponent, or "0" if x is zero, // and returns the extended buffer. // The mantissa is normalized such that is uses x.Prec() bits in binary // representation. // The sign of x is ignored, and x must not be an Inf. // (The caller handles Inf before invoking fmtB.) func (x *Float) fmtB(buf []byte) []byte { … } // fmtX appends the string of x in the format "0x1." mantissa "p" exponent // with a hexadecimal mantissa and a binary exponent, or "0x0p0" if x is zero, // and returns the extended buffer. // A non-zero mantissa is normalized such that 1.0 <= mantissa < 2.0. // The sign of x is ignored, and x must not be an Inf. // (The caller handles Inf before invoking fmtX.) func (x *Float) fmtX(buf []byte, prec int) []byte { … } // fmtP appends the string of x in the format "0x." mantissa "p" exponent // with a hexadecimal mantissa and a binary exponent, or "0" if x is zero, // and returns the extended buffer. // The mantissa is normalized such that 0.5 <= 0.mantissa < 1.0. // The sign of x is ignored, and x must not be an Inf. // (The caller handles Inf before invoking fmtP.) func (x *Float) fmtP(buf []byte) []byte { … } var _ … // Format implements [fmt.Formatter]. It accepts all the regular // formats for floating-point numbers ('b', 'e', 'E', 'f', 'F', // 'g', 'G', 'x') as well as 'p' and 'v'. See (*Float).Text for the // interpretation of 'p'. The 'v' format is handled like 'g'. // Format also supports specification of the minimum precision // in digits, the output field width, as well as the format flags // '+' and ' ' for sign control, '0' for space or zero padding, // and '-' for left or right justification. See the fmt package // for details. func (x *Float) Format(s fmt.State, format rune) { … }