1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Use Grisu2 algorithm in String::num_scientific to fix serializing

This commit is contained in:
Aaron Franke
2024-11-01 02:02:09 -07:00
parent 4a44078451
commit 15de1d6c35
29 changed files with 1560 additions and 200 deletions

View File

@@ -31,10 +31,24 @@
#include "doc_data.h"
String DocData::get_default_value_string(const Variant &p_value) {
if (p_value.get_type() == Variant::ARRAY) {
const Variant::Type type = p_value.get_type();
if (type == Variant::ARRAY) {
return Variant(Array(p_value, 0, StringName(), Variant())).get_construct_string().replace_char('\n', ' ');
} else if (p_value.get_type() == Variant::DICTIONARY) {
} else if (type == Variant::DICTIONARY) {
return Variant(Dictionary(p_value, 0, StringName(), Variant(), 0, StringName(), Variant())).get_construct_string().replace_char('\n', ' ');
} else if (type == Variant::INT) {
return itos(p_value);
} else if (type == Variant::FLOAT) {
// Since some values are 32-bit internally, use 32-bit for all
// documentation values to avoid garbage digits at the end.
const String s = String::num_scientific((float)p_value);
// Use float literals for floats in the documentation for clarity.
if (s != "inf" && s != "-inf" && s != "nan") {
if (!s.contains_char('.') && !s.contains_char('e')) {
return s + ".0";
}
}
return s;
} else {
return p_value.get_construct_string().replace_char('\n', ' ');
}