#include #include #include typedef long unsigned int uL; typedef struct{uL q; uL r;} res; res divq(res, uL); res mulq(uL, uL); res addq(res, res); int min(int a, int b){return a>64-n):0),v.r<=(1L<<(52+rs))?quo+1:quo; b = min(b, qb); // crude and safe estimate int splitpoint = 52+rs-b; int td = nnp>>splitpoint; uL nx = nnp - ((uL)td<=den; // not used soon; part of result b = bi; int N = tab[(den>>(64-(lts+1)))-ts]; uL nn = N*(num>>(64-53)), nd = N*(den>>(64-53)); if(0) printf("nd=%016lx\n", nd); assert(nd< 0x3fffffffffffffffL); delta = (1L<<(52+rs))-nd; return rd(nn, 0, 53-big);} uL dvg(uL const num, uL const den){ return divq(llls(coer(num>>11), 52+(num>11).q;} void tsd(uL n, uL d){ uL qg= dvg(n, d), qt = dv(n, d); assert(qt == qg);} uL r52(){return (random()^((((uL)random())<<21) | (1L<<52)))<<11;} int main (){ {int const mg = lts+rs; int j=ts; int y = 1<