MCPcopy Index your code
hub / github.com/dropbox/godropbox / BuildNumeric

Function BuildNumeric

database/sqltypes/sqltypes.go:435–450  ·  view source on GitHub ↗

BuildNumeric builds a Numeric type that represents any whole number. It normalizes the representation to ensure 1:1 mapping between the number and its representation.

(val string)

Source from the content-addressed store, hash-verified

433// It normalizes the representation to ensure 1:1 mapping between the
434// number and its representation.
435func BuildNumeric(val string) (n Value, err error) {
436 if val[0] == '-' || val[0] == '+' {
437 signed, err := strconv.ParseInt(val, 0, 64)
438 if err != nil {
439 return Value{}, err
440 }
441 n = Value{Numeric(strconv.AppendInt(nil, signed, 10))}
442 } else {
443 unsigned, err := strconv.ParseUint(val, 0, 64)
444 if err != nil {
445 return Value{}, err
446 }
447 n = Value{Numeric(strconv.AppendUint(nil, unsigned, 10))}
448 }
449 return n, nil
450}
451
452func writeBinary(typ ValueType, data []byte) ([]byte, error) {
453 var scratch [binary.MaxVarintLen64]byte

Callers 1

TestBuildNumericFunction · 0.85

Calls 1

NumericTypeAlias · 0.85

Tested by 1

TestBuildNumericFunction · 0.68