diff --git a/iceoryx_hoofs/test/moduletests/test_utility_convert.cpp b/iceoryx_hoofs/test/moduletests/test_utility_convert.cpp index a6e55bc5e9d..b42c5abb8ef 100644 --- a/iceoryx_hoofs/test/moduletests/test_utility_convert.cpp +++ b/iceoryx_hoofs/test/moduletests/test_utility_convert.cpp @@ -683,8 +683,6 @@ TEST_F(convert_test, fromString_Float_EdgeCase_SubNormalFloat_ShouldFail) { ::testing::Test::RecordProperty("TEST_ID", "68d4f096-a93c-406b-b081-fe50e4b1a2c9"); - // strtof will trigger ERANGE if the input is a subnormal float, resulting in a nullopt return value. - // note that for MSVC, sub normal float is a valid input! auto normal_float_min_eps = std::nextafter(std::numeric_limits::min(), 0.0F); std::string source = fp_to_string(std::numeric_limits::min() - normal_float_min_eps); auto float_min_dec_eps = iox::convert::from_string(source.c_str()); @@ -692,28 +690,27 @@ TEST_F(convert_test, fromString_Float_EdgeCase_SubNormalFloat_ShouldFail) GTEST_SKIP() << "@todo iox-#2055 temporarily skipped"; #else ASSERT_THAT(float_min_dec_eps.has_value(), Eq(false)); -#endif } -// TEST_F(convert_test, fromString_Double_EdgeCase_InRange_Success) -// { -// ::testing::Test::RecordProperty("TEST_ID", "d5e5e5ad-92ed-4229-8128-4ee82059fbf7"); +TEST_F(convert_test, fromString_Double_EdgeCase_InRange_Success) +{ + ::testing::Test::RecordProperty("TEST_ID", "d5e5e5ad-92ed-4229-8128-4ee82059fbf7"); std::string source = fp_to_string(std::numeric_limits::min()); auto double_min = iox::convert::from_string(source.c_str()); ASSERT_THAT(double_min.has_value(), Eq(true)); EXPECT_THAT(double_min.value(), DoubleEq(std::numeric_limits::min())); -// source = fp_to_string(std::numeric_limits::lowest()); -// auto double_lowest = iox::convert::from_string(source.c_str()); -// ASSERT_THAT(double_lowest.has_value(), Eq(true)); -// EXPECT_THAT(double_lowest.value(), DoubleEq(std::numeric_limits::lowest())); + source = fp_to_string(std::numeric_limits::lowest()); + auto double_lowest = iox::convert::from_string(source.c_str()); + ASSERT_THAT(double_lowest.has_value(), Eq(true)); + EXPECT_THAT(double_lowest.value(), DoubleEq(std::numeric_limits::lowest())); -// source = fp_to_string(std::numeric_limits::max()); -// auto double_max = iox::convert::from_string(source.c_str()); -// ASSERT_THAT(double_max.has_value(), Eq(true)); -// EXPECT_THAT(double_max.value(), DoubleEq(std::numeric_limits::max())); -// } + source = fp_to_string(std::numeric_limits::max()); + auto double_max = iox::convert::from_string(source.c_str()); + ASSERT_THAT(double_max.has_value(), Eq(true)); + EXPECT_THAT(double_max.value(), DoubleEq(std::numeric_limits::max())); +} TEST_F(convert_test, fromString_Double_EdgeCase_SubNormalDouble_ShouldFailExcept) { @@ -726,7 +723,6 @@ TEST_F(convert_test, fromString_Double_EdgeCase_SubNormalDouble_ShouldFailExcept GTEST_SKIP() << "@todo iox-#2055 temporarily skipped"; #else ASSERT_THAT(double_min_dec_eps.has_value(), Eq(false)); -#endif } TEST_F(convert_test, fromString_LongDouble_EdgeCase_InRange_Success) @@ -761,7 +757,6 @@ TEST_F(convert_test, fromString_LongDouble_EdgeCase_SubNormalLongDouble_ShouldFa GTEST_SKIP() << "@todo iox-#2055 temporarily skipped"; #else ASSERT_THAT(long_double_min_dec_eps.has_value(), Eq(false)); -#endif } /// NORMAL FLOATING POINT TYPE EDGE CASES END diff --git a/iceoryx_hoofs/utility/include/iox/detail/convert.inl b/iceoryx_hoofs/utility/include/iox/detail/convert.inl index b04881c22d3..4c076092b17 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/convert.inl +++ b/iceoryx_hoofs/utility/include/iox/detail/convert.inl @@ -363,7 +363,6 @@ inline bool convert::is_within_range(const SourceType& source_val) noexcept { return true; } - // is_arithmetic_v if constexpr (std::is_floating_point_v) { // special cases for floating point @@ -371,8 +370,13 @@ inline bool convert::is_within_range(const SourceType& source_val) noexcept { return true; } +#ifdef _MSC_VER + if (!std::isnormal(source_val) && (source_val != 0.0)) + { + return false; + } +#endif } - // out of range (upper bound) if (source_val > std::numeric_limits::max()) { @@ -381,7 +385,6 @@ inline bool convert::is_within_range(const SourceType& source_val) noexcept << std::numeric_limits::max()); return false; } - // out of range (lower bound) if (source_val < std::numeric_limits::lowest()) {