Skip to content

Commit

Permalink
STYLE: NumberToStringGTest: add #include, avoid narrowing conversion pow
Browse files Browse the repository at this point in the history
Added `#include <cmath>`, to ensure that all `std::pow` overloads are included.

Explicitly declared the local `power_of_ten` variables as `TValue` and
prevented a narrowing conversion from those `std::pow` calls, just to be sure.
  • Loading branch information
N-Dekker committed Nov 20, 2022
1 parent ce57f30 commit 8f988d9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Modules/Core/Common/test/itkNumberToStringGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// First include the header file to be tested:
#include "itkNumberToString.h"
#include <gtest/gtest.h>
#include <cmath> // For std::pow.

namespace
{
Expand Down Expand Up @@ -81,7 +82,7 @@ Test_decimal_notation_supports_up_to_twentyone_digits()

for (int8_t exponent{ 20 }; exponent > 0; --exponent)
{
const auto power_of_ten = std::pow(TValue{ 10 }, static_cast<TValue>(exponent));
const TValue power_of_ten{ std::pow(TValue{ 10 }, static_cast<TValue>(exponent)) };

// Test +/- 10 ^ exponent
EXPECT_EQ(numberToString(power_of_ten), '1' + std::string(exponent, '0'));
Expand All @@ -90,7 +91,7 @@ Test_decimal_notation_supports_up_to_twentyone_digits()

for (int8_t exponent{ -6 }; exponent < 0; ++exponent)
{
const auto power_of_ten = std::pow(TValue{ 10 }, static_cast<TValue>(exponent));
const TValue power_of_ten{ std::pow(TValue{ 10 }, static_cast<TValue>(exponent)) };

// Test +/- 10 ^ exponent
EXPECT_EQ(numberToString(power_of_ten), "0." + std::string(-1 - exponent, '0') + '1');
Expand Down

0 comments on commit 8f988d9

Please sign in to comment.