22 static std::pair<LongIntType, LongIntType>
rat_approx(
double f,
24 if (fabs(f) < 1.0 / md) {
25 return std::pair<LongIntType, LongIntType>(0, 1);
34 return std::pair<LongIntType, LongIntType>((
LongIntType)f, 1);
42 while (f != floor(f)) {
50 for (i = 0; i < 64; i++) {
62 if (k[1] * a + k[0] >= md) {
63 x = (md - k[0]) / k[1];
64 if (x * 2 >= a || k[1] >= md)
70 h[2] = x * h[1] + h[0];
73 k[2] = x * k[1] + k[0];
77 return std::pair<LongIntType, LongIntType>(neg ? -h[1] : h[1], k[1]);