|
|
|
|
@@ -457,9 +457,9 @@ TEST_CASE("[String] Erasing") {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[String] Number to string") {
|
|
|
|
|
CHECK(String::num(0) == "0");
|
|
|
|
|
CHECK(String::num(0.0) == "0"); // No trailing zeros.
|
|
|
|
|
CHECK(String::num(-0.0) == "-0"); // Includes sign even for zero.
|
|
|
|
|
CHECK(String::num(0) == "0.0"); // The method takes double, so always add zeros.
|
|
|
|
|
CHECK(String::num(0.0) == "0.0");
|
|
|
|
|
CHECK(String::num(-0.0) == "-0.0"); // Includes sign even for zero.
|
|
|
|
|
CHECK(String::num(3.141593) == "3.141593");
|
|
|
|
|
CHECK(String::num(3.141593, 3) == "3.142");
|
|
|
|
|
CHECK(String::num(42.100023, 4) == "42.1"); // No trailing zeros.
|
|
|
|
|
@@ -494,15 +494,15 @@ TEST_CASE("[String] Number to string") {
|
|
|
|
|
CHECK(String::num_real(3.141593) == "3.141593");
|
|
|
|
|
CHECK(String::num_real(3.141) == "3.141"); // No trailing zeros.
|
|
|
|
|
#ifdef REAL_T_IS_DOUBLE
|
|
|
|
|
CHECK_MESSAGE(String::num_real(123.456789) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(-123.456789) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(Math_PI) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(3.1415f) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(3.1415f)) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
|
|
|
|
|
#else
|
|
|
|
|
CHECK_MESSAGE(String::num_real(123.456789) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(-123.456789) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(Math_PI) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(3.1415f) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
|
|
|
|
|
CHECK_MESSAGE(String::num_real(real_t(3.1415f)) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float.");
|
|
|
|
|
#endif // REAL_T_IS_DOUBLE
|
|
|
|
|
|
|
|
|
|
// Checks doubles with many decimal places.
|
|
|
|
|
@@ -511,7 +511,7 @@ TEST_CASE("[String] Number to string") {
|
|
|
|
|
CHECK(String::num(-0.0000012345432123454321) == "-0.00000123454321");
|
|
|
|
|
CHECK(String::num(-10000.0000012345432123454321) == "-10000.0000012345");
|
|
|
|
|
CHECK(String::num(0.0000000000012345432123454321) == "0.00000000000123");
|
|
|
|
|
CHECK(String::num(0.0000000000012345432123454321, 3) == "0");
|
|
|
|
|
CHECK(String::num(0.0000000000012345432123454321, 3) == "0.0");
|
|
|
|
|
|
|
|
|
|
// Note: When relevant (remainder > 0.5), the last digit gets rounded up,
|
|
|
|
|
// which can also lead to not include a trailing zero, e.g. "...89" -> "...9".
|
|
|
|
|
|