Here's mine (converting from C library %g format to JS toString format):
class Float
def cbor_diagnostic # do a little bit of JSON.stringify
gaming (ECMA-262-2015, 7.1.12.1)
a = abs
if a < 1 && a >= 1e-6
inspect.sub(/(\d)[.](\d+)e-(\d+)/) {"0.#{"0" * ($3.to_i -
1)}#{$1}#{$2}"}
else
inspect.sub(/(e[+-])0+/) {$1}
end
end
end
Apart from selecting the shortest representation, you need to select
details of the exponent format etc. But the biggest problem with number
c14n in JSON is that the last digit may not be uniquely determined
(i.e., there are a number of shortest-form decimal numbers that map to
the same binary64).
Grüße, Carsten
_______________________________________________
jose mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/jose