diff options
author | Jean Boussier <[email protected]> | 2025-05-10 11:31:33 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-05-12 11:09:11 +0900 |
commit | af799140028d9600c5c799356da9a4f1f31b2e7e () | |
tree | c6f627f90e41c019f6dd8e54c93d6c0605fedd69 | |
parent | dc5555d74aa75a61813c9cfba52058624bccc63e (diff) |
[ruby/json] Favor decimal notation over scientific notation for floats
e.g. ``` JSON.dump(1746861937.7842371) ``` master: ``` "1.https://.com/ruby/json/commit/746861937784+9" ``` This branch and older json versions: ``` https://.com/ruby/json/commit/1746861937.7842371 ``` In the end it's shorter, and according to `canada.json` benchmark performance is the same. https://.com/ruby/json/commit/866f72a437
-rw-r--r-- | ext/json/vendor/fpconv.c | 2 | ||||
-rwxr-xr-x | test/json/json_generator_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
@@ -340,7 +340,7 @@ static int emit_digits(char* digits, int ndigits, char* dest, int K, bool neg) } /* write decimal w/o scientific notation */ - if(K < 0 && (K > -7 || exp < 4)) { int offset = ndigits - absv(K); /* fp < 1.0 -> write leading zero */ if(offset <= 0) { @@ -771,6 +771,14 @@ class JSONGeneratorTest < Test::Unit::TestCase values = [-1.0, 1.0, 0.0, 12.2, 7.5 / 3.2, 12.0, 100.0, 1000.0] expecteds = ["-1.0", "1.0", "0.0", "12.2", "2.34375", "12.0", "100.0", "1000.0"] values.zip(expecteds).each do |value, expected| assert_equal expected, value.to_json end |