quad_float log(const quad_float& t) { // Newton method. See Bailey, MPFUN if (t.hi <= 0.0) { Error("log(quad_float): argument must be positive"); } double s1 = log(t.hi); ForceToMem(&s1); // Again, this is fairly paranoid. quad_float s; s = s1; quad_float e; e=exp(s); return s+(t-e)/e; // Newton step }
quad_float sqrt(const quad_float& y) { if (y.hi < 0.0) ArithmeticError("quad_float: square root of negative number"); if (y.hi == 0.0) return quad_float(0.0,0.0); double c; c = sqrt(y.hi); ForceToMem(&c); // This is fairly paranoid, but it doesn't cost too much. START_FIX DOUBLE p,q,hx,tx,u,uu,cc; DOUBLE t1; p = Protect(NTL_QUAD_FLOAT_SPLIT*c); hx = (c-p); hx = hx+p; tx = c-hx; p = Protect(hx*hx); q = Protect(hx*tx); q = q+q; u = p+q; uu = p-u; uu = uu+q; t1 = Protect(tx*tx); uu = uu+t1; cc = y.hi-u; cc = cc-uu; cc = cc+y.lo; t1 = c+c; cc = cc/t1; hx = c+cc; tx = c-hx; tx = tx+cc; END_FIX return quad_float(hx, tx); }
xdouble ceil(const xdouble& aa) { xdouble z; xdouble a = aa; ForceToMem(&a.x); if (a.e == 0) { z.x = ceil(a.x); z.e = 0; z.normalize(); return z; } else if (a.e > 0) { return a; } else { if (a.x < 0) return to_xdouble(0); else return to_xdouble(1); } }