MCPcopy Create free account
hub / github.com/dinedal/textql / BuildNumeric

Function BuildNumeric

sqlparser/sqltypes/sqltypes.go:257–272  ·  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

255// It normalizes the representation to ensure 1:1 mapping between the
256// number and its representation.
257func BuildNumeric(val string) (n Value, err error) {
258 if val[0] == '-' || val[0] == '+' {
259 signed, err := strconv.ParseInt(val, 0, 64)
260 if err != nil {
261 return Value{}, err
262 }
263 n = Value{Numeric(strconv.AppendInt(nil, signed, 10))}
264 } else {
265 unsigned, err := strconv.ParseUint(val, 0, 64)
266 if err != nil {
267 return Value{}, err
268 }
269 n = Value{Numeric(strconv.AppendUint(nil, unsigned, 10))}
270 }
271 return n, nil
272}
273
274func (n Numeric) raw() []byte {
275 return []byte(n)

Callers 1

TestBuildNumericFunction · 0.85

Calls 1

NumericTypeAlias · 0.85

Tested by 1

TestBuildNumericFunction · 0.68