Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions LEGAL
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ ext/json/ext/vendor/jeaiii-ltoa.h::
This file is adapted from https://github.com/jeaiii/itoa
It is licensed under the MIT License

ext/json/ext/vendor/ryu.h::
This file is adapted from the Ryu algorithm by Ulf Adams https://github.com/ulfjack/ryu.
It is dual-licensed under Apache License 2.0 OR Boost Software License 1.0.
ext/json/ext/vendor/fast_float_parser.h::
This file is adapted from the Fast Float C++ library by The fast_float authors https://github.com/fastfloat/fast_float
It is licensed under the MIT License
2 changes: 1 addition & 1 deletion ext/json/ext/parser/depend
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
parser.o: $(srcdir)/../fbuffer/fbuffer.h
parser.o: $(srcdir)/../json.h
parser.o: $(srcdir)/../simd/simd.h
parser.o: $(srcdir)/../vendor/ryu.h
parser.o: $(srcdir)/../vendor/fast_float_parser.h
parser.o: parser.c
# AUTOGENERATED DEPENDENCIES END
8 changes: 3 additions & 5 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../json.h"
#include "../vendor/ryu.h"
#include "../vendor/fast_float_parser.h"
#include "../simd/simd.h"

static VALUE mJSON, eNestingError, eParserError, Encoding_UTF_8;
Expand Down Expand Up @@ -1111,13 +1111,11 @@ static inline VALUE json_decode_float(JSON_ParserConfig *config, uint64_t mantis
return rb_float_new(negative ? -0.0 : 0.0);
}

// Fall back to rb_cstr_to_dbl for potential subnormals (rare edge case)
// Ryu has rounding issues with subnormals around 1e-310 (< 2.225e-308)
if (RB_UNLIKELY(mantissa_digits > 17 || mantissa_digits + exponent < -307)) {
if (RB_UNLIKELY(mantissa_digits > 18 || mantissa_digits + exponent < -307)) {
return json_decode_large_float(start, end - start);
}

return DBL2NUM(ryu_s2d_from_parts(mantissa, mantissa_digits, (int32_t)exponent, negative));
return DBL2NUM(ffp_s2d(exponent, mantissa, negative));
}

static inline VALUE json_decode_array(JSON_ParserState *state, JSON_ParserConfig *config, long count)
Expand Down
Loading