From fd7a7f22a5850df165939d7f83dab7fcc2501f64 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 27 Jun 2021 00:35:36 +0200 Subject: [PATCH] Always add decimal when printing float --- core/math/rect2.cpp | 2 +- core/math/vector2.cpp | 2 +- core/math/vector3.cpp | 2 +- core/variant/variant.cpp | 2 +- .../features/class_inference_is_weak.out | 2 +- .../parser/features/nested_arithmetic.out | 2 +- .../parser/features/operator_assign.out | 2 +- .../features/chain_assignment_works.out | 12 ++++++------ .../scripts/runtime/features/stringify.out | 18 +++++++++--------- tests/core/math/test_aabb.h | 2 +- tests/core/math/test_rect2.h | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp index 9e78ead816c2..827e872da162 100644 --- a/core/math/rect2.cpp +++ b/core/math/rect2.cpp @@ -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 { diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index d9b5d55454e7..61fe6f712fbb 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -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 { diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index d71d3650534a..41a02a191ba2 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -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 { diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index ae92d7b5c445..ab28c12ca99f 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -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(_data._mem); case VECTOR2: diff --git a/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out index 94e2ec2af87f..fb616f1e94a3 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out +++ b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out @@ -1,2 +1,2 @@ GDTEST_OK -0 +0.0 diff --git a/modules/gdscript/tests/scripts/parser/features/nested_arithmetic.out b/modules/gdscript/tests/scripts/parser/features/nested_arithmetic.out index 048cfbdfaecd..4c2326554132 100644 --- a/modules/gdscript/tests/scripts/parser/features/nested_arithmetic.out +++ b/modules/gdscript/tests/scripts/parser/features/nested_arithmetic.out @@ -76,7 +76,7 @@ GDTEST_OK -2.718 -36900.9009009009 +36900.9 2 8192 -8 diff --git a/modules/gdscript/tests/scripts/parser/features/operator_assign.out b/modules/gdscript/tests/scripts/parser/features/operator_assign.out index b0cb63ef59d2..29910adf38d7 100644 --- a/modules/gdscript/tests/scripts/parser/features/operator_assign.out +++ b/modules/gdscript/tests/scripts/parser/features/operator_assign.out @@ -1,2 +1,2 @@ GDTEST_OK -8 +8.0 diff --git a/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out b/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out index 5e7ccf534ab4..76dd6b3fcab7 100644 --- a/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out +++ b/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out @@ -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)] diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.out b/modules/gdscript/tests/scripts/runtime/features/stringify.out index d4468737a5c4..37333897dcca 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.out +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.out @@ -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 @@ -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)] diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h index 526972a82f1e..a5d70e02ca5c 100644 --- a/tests/core/math/test_aabb.h +++ b/tests/core/math/test_aabb.h @@ -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."); } diff --git a/tests/core/math/test_rect2.h b/tests/core/math/test_rect2.h index 0b1106ac3cf0..f306d0a9fdc6 100644 --- a/tests/core/math/test_rect2.h +++ b/tests/core/math/test_rect2.h @@ -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."); }