SMaP_Number operator*(const SMaP_Number &lhs, const SMaP_Number &rhs)
{
    SMaP_Number result = SMaP_Number();
    __int32 lhsVal = lhs.val;
    __int32 rhsVal = rhs.val;

    //preconditional overflow test
    unsigned __int8 lhsBits = highestOneBitPosition(lhsVal);
    unsigned __int8 rhsBits = highestOneBitPosition(rhsVal);

    if (lhsBits + rhsBits > VAL_SIZE)
    {
        result.dataRange = true;
    }
    //TODO: get logic to find case where result would be too small
    else
    {
        result = SMaP_Number(lhsVal * rhsVal);
    }

    return result;
}
Exemple #2
0
bool multiplication_is_safe(const unsigned long long a,const  unsigned long long b) {
    size_t a_bits=highestOneBitPosition(a), b_bits=highestOneBitPosition(b);
    return (a_bits+b_bits<=n_bits);
}
bool ms(unsigned long long a, unsigned long long b) {
    int a_bits=highestOneBitPosition(a), b_bits=highestOneBitPosition(b);
    return (a_bits+b_bits <= 64);
}
bool addition_is_safe(uint16_t a, uint16_t b) {
    size_t a_bits=highestOneBitPosition(a), b_bits=highestOneBitPosition(b);
    return (a_bits<32 && b_bits<32);
}