MCPcopy Create free account
hub / github.com/dolthub/doltgresql / Format

Method Format

postgres/parser/sem/tree/datum.go:435–461  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

433
434// Format implements the NodeFormatter interface.
435func (d *DFloat) Format(ctx *FmtCtx) {
436 fl := float64(*d)
437
438 disambiguate := ctx.flags.HasFlags(fmtDisambiguateDatumTypes)
439 parsable := ctx.flags.HasFlags(FmtParsableNumerics)
440 quote := parsable && (math.IsNaN(fl) || math.IsInf(fl, 0))
441 // We need to use Signbit here and not just fl < 0 because of -0.
442 needParens := !quote && (disambiguate || parsable) && math.Signbit(fl)
443 // If the number is negative, we need to use parens or the `:::INT` type hint
444 // will take precedence over the negation sign.
445 if quote {
446 ctx.WriteByte('\'')
447 } else if needParens {
448 ctx.WriteByte('(')
449 }
450 if _, frac := math.Modf(fl); frac == 0 && -1000000 < *d && *d < 1000000 {
451 // d is a small whole number. Ensure it is printed using a decimal point.
452 ctx.Printf("%.1f", fl)
453 } else {
454 ctx.Printf("%g", fl)
455 }
456 if quote {
457 ctx.WriteByte('\'')
458 } else if needParens {
459 ctx.WriteByte(')')
460 }
461}
462
463// Size implements the Datum interface.
464func (d *DFloat) Size() uintptr {

Callers

nothing calls this directly

Calls 2

PrintfMethod · 0.80
HasFlagsMethod · 0.45

Tested by

no test coverage detected