Skip to content

Commit

Permalink
Always add decimal when printing float
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Jun 29, 2022
1 parent 26dd474 commit fd7a7f2
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core/math/rect2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re
}

Rect2::operator String() const {
return "[P: " + position.operator String() + ", S: " + size + "]";
return "[P: " + position.operator String() + ", S: " + size.operator String() + "]";
}

Rect2::operator Rect2i() const {
Expand Down
2 changes: 1 addition & 1 deletion core/math/vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {
}

Vector2::operator String() const {
return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ")";
return "(" + String::num_real(x, true) + ", " + String::num_real(y, true) + ")";
}

Vector2::operator Vector2i() const {
Expand Down
2 changes: 1 addition & 1 deletion core/math/vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool Vector3::is_equal_approx(const Vector3 &p_v) const {
}

Vector3::operator String() const {
return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ")";
return "(" + String::num_real(x, true) + ", " + String::num_real(y, true) + ", " + String::num_real(z, true) + ")";
}

Vector3::operator Vector3i() const {
Expand Down
2 changes: 1 addition & 1 deletion core/variant/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ String Variant::stringify(int recursion_count) const {
case INT:
return itos(_data._int);
case FLOAT:
return rtos(_data._float);
return String::num_real(_data._float, true);
case STRING:
return *reinterpret_cast<const String *>(_data._mem);
case VECTOR2:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GDTEST_OK
0
0.0
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ GDTEST_OK

-2.718

36900.9009009009
36900.9
2
8192
-8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GDTEST_OK
8
8.0
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GDTEST_OK
{1:(2, 0)}
{3:(4, 0)}
[[(5, 0)]]
[[(6, 0)]]
[[(7, 0)]]
[X: (8, 9, 7), Y: (0, 1, 0), Z: (0, 0, 1), O: (0, 0, 0)]
{1:(2.0, 0.0)}
{3:(4.0, 0.0)}
[[(5.0, 0.0)]]
[[(6.0, 0.0)]]
[[(7.0, 0.0)]]
[X: (8.0, 9.0, 7.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (0.0, 0.0, 0.0)]
18 changes: 9 additions & 9 deletions modules/gdscript/tests/scripts/runtime/features/stringify.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ hello world
[P: (0, 0), S: (0, 0)]
(0.25, 0.25, 0.25)
(0, 0, 0)
[X: (1, 0), Y: (0, 1), O: (0, 0)]
[N: (1, 2, 3), D: 4]
[X: (1.0, 0.0), Y: (0.0, 1.0), O: (0.0, 0.0)]
[N: (1.0, 2.0, 3.0), D: 4]
(1, 2, 3, 4)
[P: (0, 0, 0), S: (1, 1, 1)]
[X: (1, 0, 0), Y: (0, 1, 0), Z: (0, 0, 1)]
[X: (1, 0, 0), Y: (0, 1, 0), Z: (0, 0, 1), O: (0, 0, 0)]
[P: (0.0, 0.0, 0.0), S: (1.0, 1.0, 1.0)]
[X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0)]
[X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (0.0, 0.0, 0.0)]
(1, 2, 3, 4)
hello
hello/world
Expand All @@ -26,9 +26,9 @@ Node::[signal]property_list_changed
[255, 0, 1]
[-1, 0, 1]
[-1, 0, 1]
[-1, 0, 1]
[-1, 0, 1]
[-1.0, 0.0, 1.0]
[-1.0, 0.0, 1.0]
["hello", "world"]
[(1, 1), (0, 0)]
[(1, 1, 1), (0, 0, 0)]
[(1.0, 1.0), (0.0, 0.0)]
[(1.0, 1.0, 1.0), (0.0, 0.0, 0.0)]
[(1, 0, 0, 1), (0, 0, 1, 1), (0, 1, 0, 1)]
2 changes: 1 addition & 1 deletion tests/core/math/test_aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TEST_CASE("[AABB] Constructor methods") {

TEST_CASE("[AABB] String conversion") {
CHECK_MESSAGE(
String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2, -2.5), S: (4, 5, 6)]",
String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2.0, -2.5), S: (4.0, 5.0, 6.0)]",
"The string representation should match the expected value.");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/math/test_rect2.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TEST_CASE("[Rect2] Constructor methods") {
TEST_CASE("[Rect2] String conversion") {
// Note: This also depends on the Vector2 string representation.
CHECK_MESSAGE(
String(Rect2(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]",
String(Rect2(0, 100, 1280, 720)) == "[P: (0.0, 100.0), S: (1280.0, 720.0)]",
"The string representation should match the expected value.");
}

Expand Down

0 comments on commit fd7a7f2

Please sign in to comment.