#include <int.hpp>
Definition at line 759 of file int.hpp.
static bool reconstruct | ( | typename signed_of_helper< U >::type & | n, | |
typename signed_of_helper< U >::type & | d, | |||
const U & | u, | |||
const U & | m, | |||
const U & | N, | |||
const U & | D | |||
) | [inline, static] |
Definition at line 760 of file int.hpp.
References mmx::abs(), ASSERT, mmx::gcd(), mmx::I(), and mmx::rem().
00761 { 00762 /* Return in r = n / d such that abs (n) <= N, 0 < d <= D, gcd (n, d) = 1, 00763 and n / d = u mod m. If such a rational exists then the function returns 00764 true and false otherwise. */ 00765 ASSERT (m > u, "invalid input"); 00766 ASSERT (N > 0, "invalid input"); 00767 ASSERT (D > 0, "invalid input"); 00768 U aux= N * D; 00769 ASSERT (aux / D == N && (aux << 1) / 2 == aux && (aux << 1) < m, 00770 "invalid input"); 00771 U r0= m, t0= 0; 00772 U r1= u, t1= 1; 00773 U q; 00774 while (r1 > N) { 00775 U aux= rem (r0, r1, q); 00776 r0= r1; r1= aux; 00777 aux= t0; 00778 t0= t1; t1= aux - q * t1; 00779 } 00780 n= (I) r1; d= (I) t1; 00781 if (d < 0) { n= -n; d= -d; } 00782 if ((U) d > D) return false; 00783 return abs (gcd (n, d)) == 1; }