mirror of
https://github.com/godotengine/godot.git
synced 2025-10-28 04:04:24 +00:00
Handle NaN and Infinity in JSON stringify function
This commit is contained in:
parent
73da0d2020
commit
e90cea9250
2 changed files with 33 additions and 0 deletions
|
|
@ -75,6 +75,17 @@ void JSON::_stringify(String &r_result, const Variant &p_var, const String &p_in
|
|||
case Variant::FLOAT: {
|
||||
const double num = p_var;
|
||||
|
||||
// JSON does not support NaN or Infinity, so use extremely large numbers for infinity.
|
||||
if (!Math::is_finite(num)) {
|
||||
if (num == Math::INF) {
|
||||
r_result += "1e99999";
|
||||
} else if (num == -Math::INF) {
|
||||
r_result += "-1e99999";
|
||||
} else {
|
||||
r_result += "\"NaN\"";
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Only for exactly 0. If we have approximately 0 let the user decide how much
|
||||
// precision they want.
|
||||
if (num == double(0.0)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue