bool Decimal::operator<(Decimal rhs) const { Decimal lhs = *this; lhs.rationalize(); rhs.rationalize(); if (lhs.m_places == rhs.m_places) { return lhs.m_intval < rhs.m_intval; } bool const left_is_longer = (lhs.m_places > rhs.m_places); Decimal const *const shorter = (left_is_longer? &rhs: &lhs); Decimal const *const longer = (left_is_longer? &lhs: &rhs); places_type const target_places = shorter->m_places; int_type longers_revised_intval = longer->m_intval; int_type const shorters_intval = shorter->m_intval; bool const longer_is_negative = (longers_revised_intval < 0); for ( places_type longers_places = longer->m_places; longers_places != target_places; --longers_places ) { JEWEL_ASSERT (s_base > 0); JEWEL_ASSERT (!division_is_unsafe(longers_revised_intval, s_base)); longers_revised_intval /= s_base; JEWEL_ASSERT (longers_places > 0); } bool longer_is_smaller = ( longer_is_negative? (longers_revised_intval <= shorters_intval): (longers_revised_intval < shorters_intval) ); return ( &lhs == (longer_is_smaller? longer: shorter) ); }
bool Decimal::operator==(Decimal rhs) const { Decimal temp_lhs = *this; temp_lhs.rationalize(); rhs.rationalize(); return ( temp_lhs.m_intval == rhs.m_intval && temp_lhs.m_places == rhs.m_places ); }