You've already forked godot
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:
@@ -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', ' ');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user