|
18 | 18 |
|
19 | 19 | // First include the header file to be tested: |
20 | 20 | #include "itkNumberToString.h" |
| 21 | +#include "itkMath.h" |
21 | 22 | #include <gtest/gtest.h> |
22 | | -#include <cmath> // For std::pow. |
23 | 23 |
|
24 | 24 | namespace |
25 | 25 | { |
@@ -91,22 +91,22 @@ Test_decimal_notation_supports_up_to_twentyone_digits() |
91 | 91 | const itk::NumberToString<TValue> numberToString{}; |
92 | 92 | const auto message = std::string("Floating point type: ") + floatingPointTypeName<TValue>; |
93 | 93 |
|
94 | | - for (int8_t exponent{ 20 }; exponent > 0; --exponent) |
| 94 | + for (uint64_t exponent{ 20 }; exponent > 0; --exponent) |
95 | 95 | { |
96 | | - const TValue power_of_ten{ std::pow(TValue{ 10 }, static_cast<TValue>(exponent)) }; |
| 96 | + const TValue power_of_ten{ static_cast<TValue>(itk::Math::UnsignedPower(10, exponent - 1)) * TValue{ 10 } }; |
97 | 97 |
|
98 | 98 | // Test +/- 10 ^ exponent |
99 | 99 | EXPECT_EQ(numberToString(power_of_ten), '1' + std::string(exponent, '0')) << message; |
100 | 100 | EXPECT_EQ(numberToString(-power_of_ten), "-1" + std::string(exponent, '0')) << message; |
101 | 101 | } |
102 | 102 |
|
103 | | - for (int8_t exponent{ -6 }; exponent < 0; ++exponent) |
| 103 | + for (uint64_t exponent{ 6 }; exponent > 0; --exponent) |
104 | 104 | { |
105 | | - const TValue power_of_ten{ std::pow(TValue{ 10 }, static_cast<TValue>(exponent)) }; |
| 105 | + const TValue power_of_ten{ TValue{ 1 } / static_cast<TValue>(itk::Math::UnsignedPower(10, exponent)) }; |
106 | 106 |
|
107 | | - // Test +/- 10 ^ exponent |
108 | | - EXPECT_EQ(numberToString(power_of_ten), "0." + std::string(-1 - exponent, '0') + '1') << message; |
109 | | - EXPECT_EQ(numberToString(-power_of_ten), "-0." + std::string(-1 - exponent, '0') + '1') << message; |
| 107 | + // Test +/- 10 ^ -exponent |
| 108 | + EXPECT_EQ(numberToString(power_of_ten), "0." + std::string(exponent - 1, '0') + '1') << message; |
| 109 | + EXPECT_EQ(numberToString(-power_of_ten), "-0." + std::string(exponent - 1, '0') + '1') << message; |
110 | 110 | } |
111 | 111 | } |
112 | 112 |
|
|
0 commit comments