Listing 4: The add function

//    excerpt from fp.cpp

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