int main(void) { int i, result; flint_rand_t state; flint_randinit(state); printf("sdiv_qrnnd...."); fflush(stdout); for (i = 0; i < 1000000; i++) { mp_limb_signed_t d, nh, nl, q, r, ph, pl; do { d = n_randtest_not_zero(state); nh = n_randtest(state); } while (FLINT_ABS(nh) >= FLINT_ABS(d)/2); nl = n_randtest(state); sdiv_qrnnd(q, r, nh, nl, d); smul_ppmm(ph, pl, d, q); if (r < 0L) sub_ddmmss(ph, pl, ph, pl, 0UL, -r); else add_ssaaaa(ph, pl, ph, pl, 0UL, r); result = ((ph == nh) && (pl == nl)); if (!result) { printf("FAIL:\n"); printf("nh = %lu, nl = %lu, d = %lu\n", nh, nl, d); printf("ph = %lu, pl = %lu\n", ph, pl); abort(); } } flint_randclear(state); printf("PASS\n"); return 0; }
static _rs_inline obj int_mul( INT_32 a, INT_32 b ) { INT_32 p_hi, p_lo; INT_64 a2, b2; #ifdef smul_ppmm smul_ppmm( p_hi, p_lo, a, b ); #else union { int i32[2]; long long int i64; } u; u.i64 = (long long int) a * (long long int) b; # if __BYTE_ORDER == __LITTLE_ENDIAN p_hi = u.i32[0]; p_lo = u.i32[1]; # else p_hi = u.i32[1]; p_lo = u.i32[0]; # endif #endif if (p_hi == 0) { if (p_lo < HIGHBIT) { return int2fx( p_lo ); } } else if (p_hi == -1) { if (p_lo >= -HIGHBIT) { return int2fx( p_lo ); } } a2 = int_32_to_int_64(a); b2 = int_32_to_int_64(b); return int_64_compact( int_64_mul( a2, b2 ) ); }