Skip to content

Commit

Permalink
#68: single rounding type in one operation
Browse files Browse the repository at this point in the history
  • Loading branch information
vpiotr committed Sep 18, 2024
1 parent 695f5ea commit f61fd94
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions include/decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,13 @@ class decimal {
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal>::type
& operator=(const decimal<Prec2> &rhs) {
& operator=(const decimal<Prec2, RoundPolicy> &rhs) {
m_value = rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
return *this;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
decimal & operator=(const decimal<Prec2> &rhs) {
decimal & operator=(const decimal<Prec2, RoundPolicy> &rhs) {
if (Prec2 > Prec) {
RoundPolicy::div_rounded(m_value, rhs.getUnbiased(),
DecimalFactorDiff<Prec2 - Prec>::value);
Expand Down Expand Up @@ -900,14 +900,14 @@ class decimal {
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
const typename ENABLE_IF<Prec >= Prec2, decimal>::type
operator+(const decimal<Prec2> &rhs) const {
operator+(const decimal<Prec2, RoundPolicy> &rhs) const {
decimal result = *this;
result.m_value += rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
return result;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
const decimal operator+(const decimal<Prec2> &rhs) const {
const decimal operator+(const decimal<Prec2, RoundPolicy> &rhs) const {
decimal result = *this;
if (Prec2 > Prec) {
int64 val;
Expand Down Expand Up @@ -937,13 +937,13 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal>::type
& operator+=(const decimal<Prec2> &rhs) {
& operator+=(const decimal<Prec2, RoundPolicy> &rhs) {
m_value += rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
return *this;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
decimal & operator+=(const decimal<Prec2> &rhs) {
decimal & operator+=(const decimal<Prec2, RoundPolicy> &rhs) {
if (Prec2 > Prec) {
int64 val;
RoundPolicy::div_rounded(val, rhs.getUnbiased(),
Expand Down Expand Up @@ -982,14 +982,14 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
const typename ENABLE_IF<Prec >= Prec2, decimal>::type
operator-(const decimal<Prec2> &rhs) const {
operator-(const decimal<Prec2, RoundPolicy> &rhs) const {
decimal result = *this;
result.m_value -= rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
return result;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
const decimal operator-(const decimal<Prec2> &rhs) const {
const decimal operator-(const decimal<Prec2, RoundPolicy> &rhs) const {
decimal result = *this;
if (Prec2 > Prec) {
int64 val;
Expand Down Expand Up @@ -1019,13 +1019,13 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal>::type
& operator-=(const decimal<Prec2> &rhs) {
& operator-=(const decimal<Prec2, RoundPolicy> &rhs) {
m_value -= rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
return *this;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
decimal & operator-=(const decimal<Prec2> &rhs) {
decimal & operator-=(const decimal<Prec2, RoundPolicy> &rhs) {
if (Prec2 > Prec) {
int64 val;
RoundPolicy::div_rounded(val, rhs.getUnbiased(),
Expand Down Expand Up @@ -1055,15 +1055,15 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
const typename ENABLE_IF<Prec >= Prec2, decimal>::type
operator*(const decimal<Prec2>& rhs) const {
operator*(const decimal<Prec2, RoundPolicy>& rhs) const {
decimal result = *this;
result.m_value = dec_utils<RoundPolicy>::multDiv(result.m_value,
rhs.getUnbiased(), DecimalFactor<Prec2>::value);
return result;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
const decimal operator*(const decimal<Prec2>& rhs) const {
const decimal operator*(const decimal<Prec2, RoundPolicy>& rhs) const {
decimal result = *this;
result.m_value = dec_utils<RoundPolicy>::multDiv(result.m_value,
rhs.getUnbiased(), DecimalFactor<Prec2>::value);
Expand All @@ -1086,14 +1086,14 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal>::type
& operator*=(const decimal<Prec2>& rhs) {
& operator*=(const decimal<Prec2, RoundPolicy>& rhs) {
m_value = dec_utils<RoundPolicy>::multDiv(m_value, rhs.getUnbiased(),
DecimalFactor<Prec2>::value);
return *this;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
decimal & operator*=(const decimal<Prec2>& rhs) {
decimal & operator*=(const decimal<Prec2, RoundPolicy>& rhs) {
m_value = dec_utils<RoundPolicy>::multDiv(m_value, rhs.getUnbiased(),
DecimalFactor<Prec2>::value);
return *this;
Expand All @@ -1117,15 +1117,15 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
const typename ENABLE_IF<Prec >= Prec2, decimal>::type
operator/(const decimal<Prec2>& rhs) const {
operator/(const decimal<Prec2, RoundPolicy>& rhs) const {
decimal result = *this;
result.m_value = dec_utils<RoundPolicy>::multDiv(result.m_value,
DecimalFactor<Prec2>::value, rhs.getUnbiased());
return result;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
const decimal operator/(const decimal<Prec2>& rhs) const {
const decimal operator/(const decimal<Prec2, RoundPolicy>& rhs) const {
decimal result = *this;
result.m_value = dec_utils<RoundPolicy>::multDiv(result.m_value,
DecimalFactor<Prec2>::value, rhs.getUnbiased());
Expand All @@ -1150,15 +1150,15 @@ template<int Prec2>
#if DEC_TYPE_LEVEL == 1
template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal>::type
& operator/=(const decimal<Prec2> &rhs) {
& operator/=(const decimal<Prec2, RoundPolicy> &rhs) {
m_value = dec_utils<RoundPolicy>::multDiv(m_value,
DecimalFactor<Prec2>::value, rhs.getUnbiased());

return *this;
}
#elif DEC_TYPE_LEVEL > 1
template<int Prec2>
decimal & operator/=(const decimal<Prec2> &rhs) {
decimal & operator/=(const decimal<Prec2, RoundPolicy> &rhs) {
m_value = dec_utils<RoundPolicy>::multDiv(m_value,
DecimalFactor<Prec2>::value, rhs.getUnbiased());

Expand Down Expand Up @@ -1197,7 +1197,7 @@ template<int Prec2>
#if DEC_TYPE_LEVEL >= 1
template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal>::type
operator%(const decimal<Prec2> &rhs) const {
operator%(const decimal<Prec2, RoundPolicy> &rhs) const {
int64 rhsInThisPrec = rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
int64 resultPayload = this->m_value;
resultPayload %= rhsInThisPrec;
Expand All @@ -1208,7 +1208,7 @@ template<int Prec2>

template<int Prec2>
typename ENABLE_IF<Prec >= Prec2, decimal &>::type
operator%=(const decimal<Prec2> &rhs) {
operator%=(const decimal<Prec2, RoundPolicy> &rhs) {
int64 rhsInThisPrec = rhs.getUnbiased() * DecimalFactorDiff<Prec - Prec2>::value;
int64 resultPayload = this->m_value;
resultPayload %= rhsInThisPrec;
Expand All @@ -1220,7 +1220,7 @@ template<int Prec2>
#if DEC_TYPE_LEVEL > 1
template<int Prec2>
typename ENABLE_IF<Prec < Prec2, decimal>::type
operator%(const decimal<Prec2> &rhs) const {
operator%(const decimal<Prec2, RoundPolicy> &rhs) const {
int64 thisInRhsPrec = m_value * DecimalFactorDiff<Prec2 - Prec>::value;
int64 resultPayload = thisInRhsPrec % rhs.getUnbiased();
resultPayload /= DecimalFactorDiff<Prec2 - Prec>::value;
Expand All @@ -1231,7 +1231,7 @@ template<int Prec2>

template<int Prec2>
typename ENABLE_IF<Prec < Prec2, decimal>::type
operator%=(const decimal<Prec2> &rhs) {
operator%=(const decimal<Prec2, RoundPolicy> &rhs) {
int64 thisInRhsPrec = m_value * DecimalFactorDiff<Prec2 - Prec>::value;
int64 resultPayload = thisInRhsPrec % rhs.getUnbiased();
resultPayload /= DecimalFactorDiff<Prec2 - Prec>::value;
Expand Down

0 comments on commit f61fd94

Please sign in to comment.