Skip to content

Commit

Permalink
Use writer.Double where we can
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Aug 29, 2024
1 parent 647775f commit 0fdd97a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ext/rapidjson/encoder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,19 @@ class RubyObjectEncoder {
}
}
} else {
VALUE str = rb_funcall(v, rb_intern("to_s"), 0);
Check_Type(str, T_STRING);
encode_raw_json_str(str);
//writer.Double(f);
// HACK: for standard notation we can use the RapidJSON
// implementation, but for values we need scientific notation we
// will fallback to Ruby's to_s so that we match JSON's output
// exactly.
//
// Ideally we would just implement both
if (f <= -1.0e15 || f >= 1.0e15 || (f >= -0.0001 && f <= 0.0001)) {
VALUE str = rb_funcall(v, rb_intern("to_s"), 0);
Check_Type(str, T_STRING);
encode_raw_json_str(str);
} else {
writer.Double(f);
}
}
}

Expand Down

0 comments on commit 0fdd97a

Please sign in to comment.