BigFloat BigFloat::add(const BigFloat &x,size_t p) const{ // Addition // The target precision is p. // If (p = 0), then no truncation is done. The entire operation is done // at maximum precision with no data loss. // Same sign. Add. if (sign == x.sign) return uadd(x,p); // this > x if (ucmp(x) > 0) return usub(x,p); // this < x return x.usub(*this,p); }
BigFloat BigFloat::sub(const BigFloat &x,size_t p) const{ // Subtraction // The target precision is p. // If (p = 0), then no truncation is done. The entire operation is done // at maximum precision with no data loss. // Different sign. Add. if (sign != x.sign) return uadd(x,p); // this > x if (ucmp(x) > 0) return usub(x,p); // this < x BigFloat z = x.usub(*this,p); z.negate(); return z; }