#include <int.hpp>
Definition at line 714 of file int.hpp.
static bool reconstruct | ( | I & | n, | |
I & | d, | |||
const I & | u, | |||
const I & | m, | |||
const I & | N, | |||
const I & | D | |||
) | [inline, static] |
Definition at line 715 of file int.hpp.
References mmx::abs(), ASSERT, mmx::gcd(), mmx::I(), and mmx::rem().
00716 { 00717 /* Return in r = n / d such that abs (n) <= N, 0 < d <= D, gcd (n, d) = 1, 00718 and n / d = u mod m. If such a rational exists then the function returns 00719 true and false otherwise. */ 00720 ASSERT (u >= 0, "invalid input"); 00721 ASSERT (m > u, "invalid input"); 00722 ASSERT (N > 0, "invalid input"); 00723 ASSERT (D > 0, "invalid input"); 00724 I aux= N * D; 00725 ASSERT (aux / D == N && (aux << 1) / 2 == aux && (aux << 1) < m, 00726 "invalid input"); 00727 I r0= m, t0= 0; 00728 I r1= u, t1= 1; 00729 I q; 00730 while (r1 > N) { 00731 I aux= rem (r0, r1, q); 00732 r0= r1; r1= aux; 00733 aux= t0; 00734 t0= t1; t1= aux - q * t1; 00735 } 00736 n= r1; d= t1; 00737 if (d < 0) { n= -n; d= -d; } 00738 if (d > D) return false; 00739 return abs (gcd (n, d)) == 1; }