Skip to content
Open
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
2 changes: 1 addition & 1 deletion core/doc_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ String DocData::get_default_value_string(const Variant &p_value) {
// 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 != "INF" && s != "-INF" && s != "NAN") {
if (!s.contains_char('.') && !s.contains_char('e')) {
return s + ".0";
}
Expand Down
8 changes: 7 additions & 1 deletion core/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,13 @@ Variant JSON::_to_native(const Variant &p_json, bool p_allow_objects, int p_dept
return s.substr(2).to_int();
} else if (s.begins_with("f:")) {
const String sub = s.substr(2);
if (sub == "inf") {
if (sub == "INF") {
return Math::INF;
} else if (sub == "-INF") {
return -Math::INF;
} else if (sub == "NAN") {
return Math::NaN;
} else if (sub == "inf") {
return Math::INF;
} else if (sub == "-inf") {
return -Math::INF;
Expand Down
6 changes: 3 additions & 3 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,14 +1405,14 @@ String String::to_lower() const {

String String::num(double p_num, int p_decimals) {
if (Math::is_nan(p_num)) {
return "nan";
return "NAN";
}

if (Math::is_inf(p_num)) {
if (std::signbit(p_num)) {
return "-inf";
return "-INF";
} else {
return "inf";
return "INF";
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/variant/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,7 @@ void Variant::construct_from_string(const String &p_string, Variant &r_value, Ob

String Variant::get_construct_string() const {
String vars;
VariantWriter::write_to_string(*this, vars);
VariantWriter::write_to_string(*this, vars, nullptr, nullptr, false);

return vars;
}
Expand Down
32 changes: 20 additions & 12 deletions core/variant/variant_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ const char *VariantParser::tk_name[TK_MAX] = {
};

static double stor_fix(const String &p_str) {
if (p_str == "inf") {
// Lowercase inf, -inf, inf_neg, and nan kept for compatibility.
if (p_str == "INF" || p_str == "inf") {
return Math::INF;
} else if (p_str == "-inf" || p_str == "inf_neg") {
// inf_neg kept for compatibility.
} else if (p_str == "-INF" || p_str == "-inf" || p_str == "inf_neg") {
return -Math::INF;
} else if (p_str == "nan") {
} else if (p_str == "NAN" || p_str == "nan") {
return Math::NaN;
}
return -1;
Expand Down Expand Up @@ -699,12 +699,14 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = false;
} else if (id == "null" || id == "nil") {
value = Variant();
} else if (id == "inf") {
} else if (id == "INF" || id == "inf") {
// Lowercase inf is kept for compatibility.
value = Math::INF;
} else if (id == "-inf" || id == "inf_neg") {
// inf_neg kept for compatibility.
} else if (id == "-INF" || id == "-inf" || id == "inf_neg") {
// Lowercase -inf and inf_neg are kept for compatibility.
value = -Math::INF;
} else if (id == "nan") {
} else if (id == "NAN" || id == "nan") {
// Lowercase nan is kept for compatibility.
value = Math::NaN;
} else if (id == "Vector2") {
Vector<real_t> args;
Expand Down Expand Up @@ -1987,9 +1989,15 @@ static String rtos_fix(double p_value, bool p_compat) {
if (p_value == 0.0) {
return "0"; // Avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist.
} else if (p_compat) {
// Write old inf_neg for compatibility.
if (std::isinf(p_value) && p_value < 0.0) {
return "inf_neg";
// Write old lowercase and inf_neg for compatibility.
if (std::isnan(p_value)) {
return "nan";
} else if (std::isinf(p_value)) {
if (p_value > 0) {
return "inf";
} else {
return "inf_neg";
}
}
}
// Hack to avoid garbage digits when the underlying float is 32-bit.
Expand Down Expand Up @@ -2024,7 +2032,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const double value = p_variant.operator double();
String s = rtos_fix(value, p_compat);
// Append ".0" to floats to ensure they are float literals.
if (s != "inf" && s != "-inf" && s != "nan" && !s.contains_char('.') && !s.contains_char('e') && !s.contains_char('E')) {
if (s != "INF" && s != "-INF" && s != "NAN" && s != "inf" && s != "inf_neg" && s != "nan" && !s.contains_char('.') && !s.contains_char('e') && !s.contains_char('E')) {
s += ".0";
}
p_store_string_func(p_store_string_ud, s);
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
<constant name="ONE" value="Vector2(1, 1)">
One vector, a vector with all components set to [code]1[/code].
</constant>
<constant name="INF" value="Vector2(inf, inf)">
<constant name="INF" value="Vector2(INF, INF)">
Infinity vector, a vector with all components set to [constant @GDScript.INF].
</constant>
<constant name="LEFT" value="Vector2(-1, 0)">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
<constant name="ONE" value="Vector3(1, 1, 1)">
One vector, a vector with all components set to [code]1[/code].
</constant>
<constant name="INF" value="Vector3(inf, inf, inf)">
<constant name="INF" value="Vector3(INF, INF, INF)">
Infinity vector, a vector with all components set to [constant @GDScript.INF].
</constant>
<constant name="LEFT" value="Vector3(-1, 0, 0)">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
<constant name="ONE" value="Vector4(1, 1, 1, 1)">
One vector, a vector with all components set to [code]1[/code].
</constant>
<constant name="INF" value="Vector4(inf, inf, inf, inf)">
<constant name="INF" value="Vector4(INF, INF, INF, INF)">
Infinity vector, a vector with all components set to [constant @GDScript.INF].
</constant>
</constants>
Expand Down
7 changes: 7 additions & 0 deletions misc/extension_api_validation/4.6-stable/GH-100414.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GH-100414
---------
Validate extension JSON: Error: Field 'builtin_classes/Vector2/constants/INF': value changed value in new API, from "Vector2(inf, inf)" to "Vector2(INF, INF)".
Validate extension JSON: Error: Field 'builtin_classes/Vector3/constants/INF': value changed value in new API, from "Vector3(inf, inf, inf)" to "Vector3(INF, INF, INF)".
Validate extension JSON: Error: Field 'builtin_classes/Vector4/constants/INF': value changed value in new API, from "Vector4(inf, inf, inf, inf)" to "Vector4(INF, INF, INF, INF)".

Infinity is now serialized as "INF" instead of "inf".
4 changes: 2 additions & 2 deletions modules/gdscript/doc_classes/@GDScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@
<constant name="TAU" value="6.28318530717959">
The circle constant, the circumference of the unit circle in radians. This is equivalent to [code]PI * 2[/code], or 360 degrees in rotations.
</constant>
<constant name="INF" value="inf">
<constant name="INF" value="INF">
Positive floating-point infinity. This is the result of floating-point division when the divisor is [code]0.0[/code]. For negative infinity, use [code]-INF[/code]. Dividing by [code]-0.0[/code] will result in negative infinity if the numerator is positive, so dividing by [code]0.0[/code] is not the same as dividing by [code]-0.0[/code] (despite [code]0.0 == -0.0[/code] returning [code]true[/code]).
[b]Warning:[/b] Numeric infinity is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer number by [code]0[/code] will not result in [constant INF] and will result in a run-time error instead.
</constant>
<constant name="NAN" value="nan">
<constant name="NAN" value="NAN">
"Not a Number", an invalid floating-point value. It is returned by some invalid operations, such as dividing floating-point [code]0.0[/code] by [code]0.0[/code].
[constant NAN] has special properties, including that [code]!=[/code] always returns [code]true[/code], while other comparison operators always return [code]false[/code]. This is true even when comparing with itself ([code]NAN == NAN[/code] returns [code]false[/code] and [code]NAN != NAN[/code] returns [code]true[/code]). Due to this, you must use [method @GlobalScope.is_nan] to check whether a number is equal to [constant NAN].
[b]Warning:[/b] "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer [code]0[/code] by [code]0[/code] will not result in [constant NAN] and will result in a run-time error instead.
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/doc_classes/GLTFLight.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
The outer angle of the cone in a spotlight. Must be greater than or equal to the inner angle.
At this angle, the light drops off to zero brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. If this angle is a half turn, then the spotlight emits in all directions. When creating a Godot [SpotLight3D], the outer cone angle is used as the angle of the spotlight.
</member>
<member name="range" type="float" setter="set_range" getter="get_range" default="inf">
<member name="range" type="float" setter="set_range" getter="get_range" default="INF">
The range of the light, beyond which the light has no effect. glTF lights with no range defined behave like physical lights (which have infinite range). When creating a Godot light, the range is clamped to [code]4096.0[/code].
</member>
</members>
Expand Down
6 changes: 3 additions & 3 deletions tests/core/io/test_json_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ TEST_CASE("[JSON][Native] Conversion between native and JSON formats") {
// Numbers and strings (represented as JSON strings).
test(1, R"("i:1")");
test(1.0, R"("f:1.0")");
test(Math::INF, R"("f:inf")");
test(-Math::INF, R"("f:-inf")");
test(Math::NaN, R"("f:nan")");
test(Math::INF, R"("f:INF")");
test(-Math::INF, R"("f:-INF")");
test(Math::NaN, R"("f:NAN")");
test(String("abc"), R"("s:abc")");
test(StringName("abc"), R"("sn:abc")");
test(NodePath("abc"), R"("np:abc")");
Expand Down
12 changes: 6 additions & 6 deletions tests/core/string/test_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ TEST_CASE("[String] Number to string") {
CHECK(String::num_scientific(3e100) == "3e+100");
CHECK(String::num_scientific(7e-100) == "7e-100");
CHECK(String::num_scientific(Math::TAU) == "6.283185307179586");
CHECK(String::num_scientific(Math::INF) == "inf");
CHECK(String::num_scientific(-Math::INF) == "-inf");
CHECK(String::num_scientific(Math::NaN) == "nan");
CHECK(String::num_scientific(Math::INF) == "INF");
CHECK(String::num_scientific(-Math::INF) == "-INF");
CHECK(String::num_scientific(Math::NaN) == "NAN");
CHECK(String::num_scientific(2.0) == "2");
CHECK(String::num_scientific(1.0) == "1");
CHECK(String::num_scientific(0.0) == "0");
Expand Down Expand Up @@ -1048,7 +1048,7 @@ TEST_CASE("[String] sprintf") {
args.push_back(Math::INF);
output = format.sprintf(args, &error);
REQUIRE(error == false);
CHECK(output == String("fish inf frog"));
CHECK(output == String("fish INF frog"));

// Real right-padded.
format = "fish %-11f frog";
Expand Down Expand Up @@ -1166,13 +1166,13 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish ( 19.990000, 1.000000, -2.050000) frog"));

// Vector left-padded with inf/nan
// Vector left-padded with INF/NAN.
format = "fish %11v frog";
args.clear();
args.push_back(Variant(Vector2(Math::INF, Math::NaN)));
output = format.sprintf(args, &error);
REQUIRE(error == false);
CHECK(output == String("fish ( inf, nan) frog"));
CHECK(output == String("fish ( INF, NAN) frog"));

// Vector right-padded.
format = "fish %-11v frog";
Expand Down
4 changes: 2 additions & 2 deletions tests/core/variant/test_variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ TEST_CASE("[Variant] Writer and parser Variant::FLOAT") {
VariantWriter::write_to_string(a64, a64_str);

CHECK_MESSAGE(a64_str == "1.7976931348623157e+308", "Writes in scientific notation.");
CHECK_MESSAGE(a64_str != "inf", "Should not overflow.");
CHECK_MESSAGE(a64_str != "nan", "The result should be defined.");
CHECK_MESSAGE(a64_str != "INF", "Should not overflow.");
CHECK_MESSAGE(a64_str != "NAN", "The result should be defined.");

String errs;
int line;
Expand Down
Loading