mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix GncInt128 shift operators when shift amount will clear a leg.
This commit is contained in:
parent
4a134ae0b1
commit
570c8a8d60
@ -309,11 +309,17 @@ GncInt128::operator<<= (unsigned int i) noexcept
|
|||||||
m_lo = 0;
|
m_lo = 0;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
if (i < legbits)
|
||||||
|
{
|
||||||
uint64_t carry {(m_lo & (((UINT64_C(1) << i) - 1) << (legbits - i)))};
|
uint64_t carry {(m_lo & (((UINT64_C(1) << i) - 1) << (legbits - i)))};
|
||||||
m_lo <<= i;
|
m_lo <<= i;
|
||||||
m_hi <<= i;
|
m_hi <<= i;
|
||||||
m_hi += carry;
|
m_hi += carry;
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
m_hi = m_lo << (i - legbits);
|
||||||
|
m_lo = 0;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GncInt128&
|
GncInt128&
|
||||||
@ -326,11 +332,17 @@ GncInt128::operator>>= (unsigned int i) noexcept
|
|||||||
m_lo = 0;
|
m_lo = 0;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
if (i < legbits)
|
||||||
|
{
|
||||||
uint64_t carry {(m_hi & ((UINT64_C(1) << i) - 1))};
|
uint64_t carry {(m_hi & ((UINT64_C(1) << i) - 1))};
|
||||||
m_lo >>= i;
|
m_lo >>= i;
|
||||||
m_hi >>= i;
|
m_hi >>= i;
|
||||||
m_lo += (carry << (legbits - i));
|
m_lo += (carry << (legbits - i));
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
m_lo = m_hi >> (i - legbits);
|
||||||
|
m_hi = 0;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GncInt128&
|
GncInt128&
|
||||||
|
Loading…
Reference in New Issue
Block a user