Skip to content

Commit 453114e

Browse files
committed
Add fast type implementation of less_parts
1 parent 6caf078 commit 453114e

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

include/boost/decimal/decimal32_fast.hpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -519,30 +519,8 @@ constexpr auto operator<(decimal32_fast lhs, decimal32_fast rhs) noexcept -> boo
519519
}
520520
#endif
521521

522-
if (lhs.significand_ == 0 || rhs.significand_ == 0)
523-
{
524-
if (lhs.significand_ == 0 && rhs.significand_ == 0)
525-
{
526-
#ifndef BOOST_DECIMAL_FAST_MATH
527-
return lhs.sign_ && !rhs.sign_;
528-
#else
529-
return false;
530-
#endif
531-
}
532-
return lhs.significand_ == 0 ? !rhs.sign_ : lhs.sign_;
533-
}
534-
535-
if (lhs.sign_ != rhs.sign_)
536-
{
537-
return lhs.sign_;
538-
}
539-
540-
if (lhs.exponent_ != rhs.exponent_)
541-
{
542-
return lhs.sign_ ? lhs.exponent_ > rhs.exponent_ : lhs.exponent_ < rhs.exponent_;
543-
}
544-
545-
return lhs.sign_ ? lhs.significand_ > rhs.significand_ : lhs.significand_ < rhs.significand_;
522+
return fast_type_less_parts_impl(lhs.significand_, lhs.biased_exponent(), lhs.sign_,
523+
rhs.significand_, rhs.biased_exponent(), rhs.sign_);
546524
}
547525

548526
constexpr auto operator<=(decimal32_fast lhs, decimal32_fast rhs) noexcept -> bool

include/boost/decimal/detail/comparison.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ constexpr auto operator!=(Decimal1 lhs, Decimal2 rhs) noexcept
167167
return !(mixed_decimal_equality_impl(lhs, rhs));
168168
}
169169

170+
template <BOOST_DECIMAL_INTEGRAL T, BOOST_DECIMAL_INTEGRAL U>
171+
BOOST_DECIMAL_FORCE_INLINE constexpr auto fast_type_less_parts_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
172+
T rhs_sig, U rhs_exp, bool rhs_sign) noexcept -> bool
173+
{
174+
if (lhs_sig == 0 || rhs_sig == 0)
175+
{
176+
if (lhs_sig == 0 && rhs_sig == 0)
177+
{
178+
#ifndef BOOST_DECIMAL_FAST_MATH
179+
return lhs_sign && !rhs_sign;
180+
#else
181+
return false;
182+
#endif
183+
}
184+
return lhs_sig == 0 ? !rhs_sign : lhs_sign;
185+
}
186+
187+
if (lhs_sign != rhs_sign)
188+
{
189+
return lhs_sign;
190+
}
191+
192+
if (lhs_exp != rhs_exp)
193+
{
194+
return lhs_sign ? lhs_exp > rhs_exp : lhs_exp < rhs_exp;
195+
}
196+
197+
return lhs_sign ? lhs_sig > rhs_sig : lhs_sig < rhs_sig;
198+
}
199+
170200
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType = decimal32, BOOST_DECIMAL_INTEGRAL T1,
171201
BOOST_DECIMAL_INTEGRAL U1, BOOST_DECIMAL_INTEGRAL T2, BOOST_DECIMAL_INTEGRAL U2>
172202
constexpr auto less_parts_impl(T1 lhs_sig, U1 lhs_exp, bool lhs_sign,

0 commit comments

Comments
 (0)