Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 949 | |
| 950 | // Format implements the NodeFormatter interface. |
| 951 | func (d *DFloat) Format(ctx *FmtCtx) { |
| 952 | fl := float64(*d) |
| 953 | |
| 954 | // TODO(#sql-sessions): formatting float4s are broken here as we cannot |
| 955 | // differentiate float4 vs float8. |
| 956 | // #73743, ##84326, #41689 are partially related. |
| 957 | if ctx.HasFlags(fmtPgwireFormat) { |
| 958 | ctx.Write(PgwireFormatFloat(ctx.scratch[:0], float64(*d), ctx.dataConversionConfig, d.ResolvedType())) |
| 959 | return |
| 960 | } |
| 961 | |
| 962 | disambiguate := ctx.flags.HasFlags(fmtDisambiguateDatumTypes) |
| 963 | parsable := ctx.flags.HasFlags(FmtParsableNumerics) |
| 964 | quote := parsable && (math.IsNaN(fl) || math.IsInf(fl, 0)) |
| 965 | // We need to use Signbit here and not just fl < 0 because of -0. |
| 966 | needParens := !quote && (disambiguate || parsable) && math.Signbit(fl) |
| 967 | // If the number is negative, we need to use parens or the `:::INT` type hint |
| 968 | // will take precedence over the negation sign. |
| 969 | if quote { |
| 970 | ctx.WriteByte('\'') |
| 971 | } else if needParens { |
| 972 | ctx.WriteByte('(') |
| 973 | } |
| 974 | if _, frac := math.Modf(fl); frac == 0 && -1000000 < *d && *d < 1000000 { |
| 975 | // d is a small whole number. Ensure it is printed using a decimal point. |
| 976 | ctx.Printf("%.1f", fl) |
| 977 | } else { |
| 978 | ctx.Printf("%g", fl) |
| 979 | } |
| 980 | if quote { |
| 981 | ctx.WriteByte('\'') |
| 982 | } else if needParens { |
| 983 | ctx.WriteByte(')') |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // Size implements the Datum interface. |
| 988 | func (d *DFloat) Size() uintptr { |
nothing calls this directly
no test coverage detected