appendNumberLiteral
Appends a JSON number literal, choosing its physical type by the rule exact if possible, narrowest if exact:
An integer that fits
Longbecomes the narrowest ofint8/int16/int32/int64.Anything else that fits MAX_DECIMAL_PRECISION digits with a scale in
[0, MAX_DECIMAL_SCALE]becomes the narrowest ofdecimal4/decimal8/decimal16, exactly.Only what fits neither becomes a
double— the sole lossy path in the codec, and it exists because JSON's number grammar is unbounded while the encoding is not.1e400has to become something, and widening is what every other Variant writer does.
Trailing zeros are stripped first, so 1.500 and 1.5 encode identically, and 1.0e10 becomes the integer 10000000000 rather than a decimal with a negative scale — the format has no negative scales.
Throws
if literal is not a JSON number.