Skip to content

Commit 9ffb696

Browse files
committed
Improve operator<=
1 parent 453114e commit 9ffb696

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

include/boost/decimal/decimal32_fast.hpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,30 @@ constexpr auto operator<(decimal32_fast lhs, decimal32_fast rhs) noexcept -> boo
526526
constexpr auto operator<=(decimal32_fast lhs, decimal32_fast rhs) noexcept -> bool
527527
{
528528
#ifndef BOOST_DECIMAL_FAST_MATH
529-
if (isnan(lhs) || isnan(rhs))
529+
if (!isfinite(lhs) || !isfinite(rhs))
530530
{
531-
return false;
531+
if (isnan(lhs) || isnan(rhs) ||
532+
(!lhs.isneg() && rhs.isneg()))
533+
{
534+
return false;
535+
}
536+
else if (lhs.isneg() && !rhs.isneg())
537+
{
538+
return true;
539+
}
540+
else if (isfinite(lhs) && isinf(rhs))
541+
{
542+
return !signbit(rhs);
543+
}
544+
else if (isinf(lhs) && isfinite(rhs))
545+
{
546+
return signbit(rhs);
547+
}
532548
}
533549
#endif
534550

535-
return !(rhs < lhs);
551+
return !fast_type_less_parts_impl(rhs.significand_, rhs.biased_exponent(), rhs.sign_,
552+
lhs.significand_, lhs.biased_exponent(), lhs.sign_);
536553
}
537554

538555
constexpr auto operator>(decimal32_fast lhs, decimal32_fast rhs) noexcept -> bool

0 commit comments

Comments
 (0)