Revision 30849ea7
Added by David Sorber about 4 years ago
| software/fixed/fixed.h | ||
|---|---|---|
|
#endif
|
||
|
|
||
|
#if SUPPORT_128_INTS
|
||
|
#include "Utilities/int128.h"
|
||
|
#include "int128.h"
|
||
|
//~ #include "Utilities/int128.h"
|
||
|
#endif
|
||
|
|
||
|
|
||
| ... | ... | |
|
friend constexpr inline bool operator>=(
|
||
|
const fixed<I, F, STI, STF>& x, const fixed<I, F, STI, STF>& y) noexcept;
|
||
|
|
||
|
// Divide by unsigned int
|
||
|
// Multiply by integer
|
||
|
template<typename I, typename F, typename STI, typename STF>
|
||
|
friend constexpr inline fixed<I, F, STI, STF> operator*(
|
||
|
const fixed<I, F, STI, STF>& x, const int64_t& y);
|
||
|
|
||
|
// Divide by integer
|
||
|
template<typename I, typename F, typename STI, typename STF>
|
||
|
friend constexpr inline fixed<I, F, STI, STF> operator/(
|
||
|
const fixed<I, F, STI, STF>& x, const int64_t& y);
|
||
| ... | ... | |
|
constexpr inline fixed<I, F, STI, STF> operator/(
|
||
|
const fixed<I, F, STI, STF>& x, const fixed<I, F, STI, STF>& y) noexcept = delete;
|
||
|
|
||
|
// Division by unsigned int
|
||
|
// Multiplication by integer
|
||
|
template<typename I, typename F, typename STI, typename STF>
|
||
|
constexpr inline fixed<I, F, STI, STF> operator*(
|
||
|
const fixed<I, F, STI, STF>& x, const int64_t& y)
|
||
|
{
|
||
|
fixed<I, F, STI, STF> newVal;
|
||
|
//~ bool negativeDivisorFlag = (y < 0);
|
||
|
//~ bool negativeDividendFlag = (x.m_integer < 0) ||
|
||
|
//~ (x.m_integer == fixed<I, F, STI, STF>::NEGATIVE_ZERO);
|
||
|
//~ bool negativeZeroFlag = false;
|
||
|
//~ I integerX = x.m_integer;
|
||
|
//~ if (__unlikely((integerX == fixed<I, F, STI, STF>::NEGATIVE_ZERO)))
|
||
|
//~ {
|
||
|
//~ integerX = 0;
|
||
|
//~ negativeZeroFlag = true;
|
||
|
//~ }
|
||
|
|
||
|
// Straight multiply for integer portion
|
||
|
newVal.m_integer = x.m_integer * y;
|
||
|
|
||
|
std::cout << "INTEGER: " << newVal.m_integer << std::endl;
|
||
|
|
||
|
std::cout << "Frac digits: " << fixed<I, F, STI, STF>::fractional_decimal_digits << std::endl;
|
||
|
std::cout << "Half Frac digits: " << (fixed<I, F, STI, STF>::fractional_decimal_digits / 2) << std::endl;
|
||
|
|
||
|
uint32_t index = (fixed<I, F, STI, STF>::fractional_decimal_digits / 2);
|
||
|
|
||
|
#if SUPPORT_128_INTS
|
||
|
uint128_t scaler = fixed<I, F, STI, STF>::SCALE_VALUES[index];
|
||
|
#else
|
||
|
uint64_t scaler = fixed<I, F, STI, STF>::SCALE_VALUES[index];
|
||
|
#endif
|
||
|
|
||
|
// Handle upper and lower portions of fractional value separarely so that
|
||
|
// the integer carry can be handled
|
||
|
std::cout << "[1] FRAC upper: " << (x.m_fractional / scaler) << std::endl;
|
||
|
F fracUpper = (x.m_fractional / scaler) * y;
|
||
|
std::cout << "[2] FRAC upper: " << fracUpper << std::endl;
|
||
|
newVal.m_fractional = (fracUpper % (scaler * 10)) * scaler;
|
||
|
std::cout << "NEW FRAC upper: " << newVal.m_fractional << std::endl;
|
||
|
|
||
|
F carry = (fracUpper / (scaler * 10));
|
||
|
std::cout << "Carry: " << carry << std::endl;
|
||
|
newVal.m_integer += carry;
|
||
|
|
||
|
F fracLower = (x.m_fractional % scaler) * y;
|
||
|
std::cout << "FRAC lower: " << fracLower << std::endl;
|
||
|
newVal.m_fractional += fracLower;
|
||
|
|
||
|
return newVal;
|
||
|
}
|
||
|
|
||
|
// Division by integer
|
||
|
template<typename I, typename F, typename STI, typename STF>
|
||
|
constexpr inline fixed<I, F, STI, STF> operator/(
|
||
|
const fixed<I, F, STI, STF>& x, const int64_t& y)
|
||
Initial version of integer division for the fixed point type.