Skip to content

Commit f5d6d63

Browse files
committed
Use single arg check_non_finite decimal_fast32_t
1 parent c3ce315 commit f5d6d63

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
221221
template <typename Decimal>
222222
friend constexpr Decimal detail::check_non_finite(Decimal lhs, Decimal rhs) noexcept;
223223

224+
template <typename Decimal>
225+
friend constexpr Decimal detail::check_non_finite(Decimal x) noexcept;
226+
224227
public:
225228
constexpr decimal_fast32_t() noexcept = default;
226229

@@ -1007,7 +1010,7 @@ constexpr auto operator+(const decimal_fast32_t lhs, const Integer rhs) noexcept
10071010
#ifndef BOOST_DECIMAL_FAST_MATH
10081011
if (!isfinite(lhs))
10091012
{
1010-
return lhs;
1013+
return detail::check_non_finite(lhs);
10111014
}
10121015
#endif
10131016

@@ -1059,7 +1062,7 @@ constexpr auto operator-(const decimal_fast32_t lhs, const Integer rhs) noexcept
10591062
#ifndef BOOST_DECIMAL_FAST_MATH
10601063
if (!isfinite(lhs))
10611064
{
1062-
return lhs;
1065+
return detail::check_non_finite(lhs);
10631066
}
10641067
#endif
10651068

@@ -1085,7 +1088,7 @@ constexpr auto operator-(const Integer lhs, const decimal_fast32_t rhs) noexcept
10851088
#ifndef BOOST_DECIMAL_FAST_MATH
10861089
if (!isfinite(rhs))
10871090
{
1088-
return rhs;
1091+
return detail::check_non_finite(rhs);
10891092
}
10901093
#endif
10911094

@@ -1128,7 +1131,7 @@ constexpr auto operator*(const decimal_fast32_t lhs, const Integer rhs) noexcept
11281131
#ifndef BOOST_DECIMAL_FAST_MATH
11291132
if (!isfinite(lhs))
11301133
{
1131-
return lhs;
1134+
return detail::check_non_finite(lhs);
11321135
}
11331136
#endif
11341137

@@ -1259,7 +1262,6 @@ constexpr auto operator/(const decimal_fast32_t lhs, const Integer rhs) noexcept
12591262
#ifndef BOOST_DECIMAL_FAST_MATH
12601263
// Check pre-conditions
12611264
constexpr decimal_fast32_t zero {0, 0};
1262-
constexpr decimal_fast32_t nan {direct_init(detail::d32_fast_qnan, UINT8_C(0), false)};
12631265
constexpr decimal_fast32_t inf {direct_init(detail::d32_fast_inf, UINT8_C(0), false)};
12641266

12651267
const bool sign {lhs.isneg() != (rhs < 0)};
@@ -1269,9 +1271,9 @@ constexpr auto operator/(const decimal_fast32_t lhs, const Integer rhs) noexcept
12691271
switch (lhs_fp)
12701272
{
12711273
case FP_NAN:
1272-
return nan;
1274+
return issignaling(lhs) ? nan_conversion(lhs) : lhs;
12731275
case FP_INFINITE:
1274-
return inf;
1276+
return lhs;
12751277
case FP_ZERO:
12761278
return sign ? -zero : zero;
12771279
default:
@@ -1300,20 +1302,16 @@ constexpr auto operator/(const Integer lhs, const decimal_fast32_t rhs) noexcept
13001302
#ifndef BOOST_DECIMAL_FAST_MATH
13011303
// Check pre-conditions
13021304
constexpr decimal_fast32_t zero {0, 0};
1303-
constexpr decimal_fast32_t nan {direct_init(detail::d32_fast_qnan, UINT8_C(0), false)};
13041305
constexpr decimal_fast32_t inf {direct_init(detail::d32_fast_inf, UINT8_C(0), false)};
13051306

13061307
const bool sign {(lhs < 0) != rhs.isneg()};
13071308

13081309
const auto rhs_fp {fpclassify(rhs)};
13091310

1310-
if (rhs_fp == FP_NAN)
1311-
{
1312-
return nan;
1313-
}
1314-
13151311
switch (rhs_fp)
13161312
{
1313+
case FP_NAN:
1314+
return issignaling(rhs) ? nan_conversion(rhs) : rhs;
13171315
case FP_INFINITE:
13181316
return sign ? -zero : zero;
13191317
case FP_ZERO:

test/test_nan_conversions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ int main()
250250
generate_mixed_tests<decimal64_t>();
251251
generate_mixed_tests<decimal128_t>();
252252

253-
//generate_mixed_tests<decimal_fast32_t>();
253+
generate_mixed_tests<decimal_fast32_t>();
254254
//generate_mixed_tests<decimal_fast64_t>();
255255
//generate_mixed_tests<decimal_fast128_t>();
256256

0 commit comments

Comments
 (0)