appendNumberLiteral

Appends a JSON number literal, choosing its physical type by the rule exact if possible, narrowest if exact:

  1. An integer that fits Long becomes the narrowest of int8/int16/int32/int64.

  2. Anything else that fits MAX_DECIMAL_PRECISION digits with a scale in [0, MAX_DECIMAL_SCALE] becomes the narrowest of decimal4/decimal8/decimal16, exactly.

  3. 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. 1e400 has 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.