Listing 2: The new version of function fp::add

fp& fp::add(const fp& f1, const fp& f2)
    {    // set this object to sum of f1 and f2
    if (IS_NAN(f1))
        *this = f1;
    else if (IS_NAN(f2))
        *this = f2;
    else if (IS_INF(f1) && IS_INF(f2) && f1.is_neg != f2.is_neg)
        *this = exception(inv, f1);
    else if (IS_INF(f1))
        *this = f1;
    else if (IS_INF(f2))
        *this = f2;
    else
        {
        long fracr = f1.lf() << P;
        if (f1.exp - f2.exp < P + 2)
            fracr += ((f2.lf() << P) >> (f1.exp - f2.exp));
        normalize(f1.exp, fracr);
        }
    return *this;    
    }