static inline void FoldBoolean(mpz_t res, bool val) { if (val) mpz_set_si(res, 1); else mpz_set_si(res, 0); }
static object integer_log_op2(fixnum op,object x,enum type tx,object y,enum type ty) { object u=big_fixnum1; object ux=tx==t_bignum ? x : (mpz_set_si(MP(big_fixnum2),fix(x)), big_fixnum2); object uy=ty==t_bignum ? y : (mpz_set_si(MP(big_fixnum3),fix(y)), big_fixnum3); switch(op) { case BOOLCLR: mpz_set_si(MP(u),0);break; case BOOLSET: mpz_set_si(MP(u),-1);break; case BOOL1: mpz_set(MP(u),MP(ux));break; case BOOL2: mpz_set(MP(u),MP(uy));break; case BOOLC1: mpz_com(MP(u),MP(ux));break; case BOOLC2: mpz_com(MP(u),MP(uy));break; case BOOLAND: mpz_and(MP(u),MP(ux),MP(uy));break; case BOOLIOR: mpz_ior(MP(u),MP(ux),MP(uy));break; case BOOLXOR: mpz_xor(MP(u),MP(ux),MP(uy));break; case BOOLEQV: mpz_xor(MP(u),MP(ux),MP(uy));mpz_com(MP(u),MP(u));break; case BOOLNAND: mpz_and(MP(u),MP(ux),MP(uy));mpz_com(MP(u),MP(u));break; case BOOLNOR: mpz_ior(MP(u),MP(ux),MP(uy));mpz_com(MP(u),MP(u));break; case BOOLANDC1:mpz_com(MP(u),MP(ux));mpz_and(MP(u),MP(u),MP(uy));break; case BOOLANDC2:mpz_com(MP(u),MP(uy));mpz_and(MP(u),MP(ux),MP(u));break; case BOOLORC1: mpz_com(MP(u),MP(ux));mpz_ior(MP(u),MP(u),MP(uy));break; case BOOLORC2: mpz_com(MP(u),MP(uy));mpz_ior(MP(u),MP(ux),MP(u));break; default:break;/*FIXME error*/ } return u; }
int main(int argc, const char * argv[]) { char *filePath = NULL; PathInit(argv[0]); PathForFile("w256-001.gp", &filePath); assert(filePath != NULL); CurveRef curve = CurveCreateFromFile(filePath); assert(curve != NULL); PointRef g = curve->g; mpz_t m; mpz_init_set_str(m, "888493310283202167031085660111238327945443791805939712000426466539273165903", 10); PointRef g2 = PointCreateMultiple(g, m, curve); mpz_t xr, yr; mpz_init_set_str(xr, "5441683091496050436439782524673611468679503009264125966279940185557193452058", 10); mpz_init_set_str(yr, "126373273530397135676109694298926901726086297191360274402845796485476517565", 10); assert(mpz_cmp(g2->x, xr) == 0); assert(mpz_cmp(g2->y, yr) == 0); mpz_set_si(m, 0); PointRef g3 = PointCreateMultiple(g, m, curve); assert(PointIsTeta(g3)); mpz_set_si(m, 1); PointRef g4 = PointCreateMultiple(g, m, curve); assert(PointEqual(g4, g)); return 0; }
int main(void) { field_t c; field_t Z19; element_t P, Q, R; mpz_t q, z; element_t a; int i; mpz_init(q); mpz_init(z); mpz_set_ui(q, 19); field_init_fp(Z19, q); element_init(a, Z19); field_init_curve_singular_with_node(c, Z19); element_init(P, c); element_init(Q, c); element_init(R, c); //(3,+/-6) is a generator //we have an isomorphism from E_ns to F_19^* // (3,6) --> 3 //(generally (x,y) --> (y+x)/(y-x) curve_set_si(R, 3, 6); for (i=1; i<=18; i++) { mpz_set_si(z, i); element_mul_mpz(Q, R, z); element_printf("%dR = %B\n", i, Q); } mpz_set_ui(z, 6); element_mul_mpz(P, R, z); //P has order 3 element_printf("P = %B\n", P); for (i=1; i<=3; i++) { mpz_set_si(z, i); element_mul_mpz(Q, R, z); tate_3(a, P, Q, R); element_printf("e_3(P,%dP) = %B\n", i, a); } element_double(P, R); //P has order 9 element_printf("P = %B\n", P); for (i=1; i<=9; i++) { mpz_set_si(z, i); element_mul_mpz(Q, P, z); tate_9(a, P, Q, R); element_printf("e_9(P,%dP) = %B\n", i, a); } return 0; }
/// @brief Create an isl map from a OpenScop matrix. /// /// @param m The OpenScop matrix to translate. /// @param Space The dimensions that are contained in the OpenScop matrix. /// /// @return An isl map representing m. isl_map *mapFromMatrix(scoplib_matrix_p m, __isl_take isl_space *Space, unsigned scatteringDims) { isl_basic_map *bmap = isl_basic_map_universe(isl_space_copy(Space)); for (unsigned i = 0; i < m->NbRows; ++i) { isl_constraint *c; c = constraintFromMatrixRow(m->p[i], isl_space_copy(Space)); mpz_t minusOne; mpz_init(minusOne); mpz_set_si(minusOne, -1); isl_constraint_set_coefficient(c, isl_dim_out, i, minusOne); bmap = isl_basic_map_add_constraint(bmap, c); } for (unsigned i = m->NbRows; i < scatteringDims; i++) { isl_constraint *c; c = isl_equality_alloc(isl_local_space_from_space(isl_space_copy(Space))); mpz_t One; mpz_init(One); mpz_set_si(One, 1); isl_constraint_set_coefficient(c, isl_dim_out, i, One); bmap = isl_basic_map_add_constraint(bmap, c); } isl_space_free(Space); return isl_map_from_basic_map(bmap); }
void check_samples (void) { { long y; mpz_set_ui (x, 1L); y = 0; mpz_mul_si (got, x, y); mpz_set_si (want, y); compare_si (y); mpz_set_ui (x, 1L); y = 1; mpz_mul_si (got, x, y); mpz_set_si (want, y); compare_si (y); mpz_set_ui (x, 1L); y = -1; mpz_mul_si (got, x, y); mpz_set_si (want, y); compare_si (y); mpz_set_ui (x, 1L); y = LONG_MIN; mpz_mul_si (got, x, y); mpz_set_si (want, y); compare_si (y); mpz_set_ui (x, 1L); y = LONG_MAX; mpz_mul_si (got, x, y); mpz_set_si (want, y); compare_si (y); } { unsigned long y; mpz_set_ui (x, 1L); y = 0; mpz_mul_ui (got, x, y); mpz_set_ui (want, y); compare_ui (y); mpz_set_ui (x, 1L); y = 1; mpz_mul_ui (got, x, y); mpz_set_ui (want, y); compare_ui (y); mpz_set_ui (x, 1L); y = ULONG_MAX; mpz_mul_ui (got, x, y); mpz_set_ui (want, y); compare_ui (y); } }
void Lib_Mpq_Set_Si64(MpqPtr x, int64_t p) { mpz_set_si( mpq_numref((mpq_ptr) x), p); mpz_set_si( mpq_denref((mpq_ptr) x), 1); // Lib_Mpz_Set_Si64( mpq_numref((mpq_ptr) x), p); // Lib_Mpz_Set_Si( mpq_denref((mpq_ptr) x), 1); }
int qsieve_getinvers(int x, int y) { if(x == 0) return y; mpz_set_si(TB, x); mpz_set_si(TC, y); mpz_invert(TD, TB, TC); return qsieve_getsize(TD); }
void random::randominteger(int & r,int a,int b) { mpz_t rr,bound; mpz_init(rr);mpz_init(bound); mpz_set_si(rr,r);mpz_set_si(bound,b-a+1); mpz_urandomm(rr,rstate,bound); r=mpz_get_si(rr); r=r+a; mpz_clear(rr);mpz_clear(bound); return ; }
int getRecurringDigits(int n){ int count = 1; mpz_set_si(num, n); mpz_set_si(powTen,10); while(1){ mpz_sub_ui(powTenMinusOne, powTen, 1UL); mpz_tdiv_r(rem, powTenMinusOne, num); if(mpz_cmp_ui(rem,0)==0) { break; } mpz_mul_ui(powTen,powTen,10); count++; } return count; }
/* exercise the case where mpz_clrbit or mpz_combit ends up extending a value like -2^(k*GMP_NUMB_BITS-1) when clearing bit k*GMP_NUMB_BITS-1. */ void check_clr_extend (void) { mpz_t got, want; unsigned long i; int f; mpz_init (got); mpz_init (want); for (i = 1; i < 5; i++) { for (f = 0; f <= 1; f++) { /* lots of 1 bits in _mp_d */ mpz_set_ui (got, 1L); mpz_mul_2exp (got, got, 10*GMP_NUMB_BITS); mpz_sub_ui (got, got, 1L); /* value -2^(n-1) representing ..11100..00 */ mpz_set_si (got, -1L); mpz_mul_2exp (got, got, i*GMP_NUMB_BITS-1); /* complement bit n, giving ..11000..00 which is -2^n */ if (f == 0) mpz_clrbit (got, i*GMP_NUMB_BITS-1); else mpz_combit (got, i*GMP_NUMB_BITS-1); MPZ_CHECK_FORMAT (got); mpz_set_si (want, -1L); mpz_mul_2exp (want, want, i*GMP_NUMB_BITS); if (mpz_cmp (got, want) != 0) { if (f == 0) printf ("mpz_clrbit: "); else printf ("mpz_combit: "); printf ("wrong after extension\n"); mpz_trace ("got ", got); mpz_trace ("want", want); abort (); } } } mpz_clear (got); mpz_clear (want); }
/* * sac_to_gmp() assumes that the incoming integer really is a bignum and is * not representable as a machine precision integer. If the argument sac is * machine precision, the while loop becomes infinite (this is bad). * * On entry I also assume that the caller has initialized gmp_int. */ static void sac_to_gmp(mpz_ptr gmp_int, Word sac) { short set_neg_flag = -1; /* when set, this will be 0 or 1 */ MP_INT pwr, temp; Word lsac, d; #ifdef MP_DEBUG fprintf(stderr, "sac_to_gmp: entering, the bignum here is "); IWRITE(sac);printf("\n"); fflush(stderr); #endif if (ISATOM(sac)) { if (sac < 0) { set_neg_flag = 1; sac = -sac; } else set_neg_flag = 0; mpz_set_si(gmp_int, (int) sac); if (set_neg_flag) mpz_neg(gmp_int, gmp_int); return; } ADV(sac, &d, &lsac); mpz_init(&pwr); mpz_set_si(&pwr, 1); if (d != 0) { set_neg_flag = (d < 0) ? 1 : 0; if (set_neg_flag) d = -d; } mpz_set_si(gmp_int, d); mpz_init(&temp); while (!ISNIL(lsac)) { mpz_mul_ui(&pwr, &pwr, BETA); ADV(lsac, &d, &lsac); if (d != 0) { mpz_clear(&temp); /* Argh!! We need to keep checking because we may have had all leading zeroes to this point! */ if (set_neg_flag == -1) set_neg_flag = (d < 0) ? 1 : 0; if (set_neg_flag) d = -d; mpz_mul_ui(&temp, &pwr, d); mpz_add(gmp_int, gmp_int, &temp); } } if (set_neg_flag) mpz_neg(gmp_int, gmp_int); #ifdef MP_DEBUG fprintf(stderr,"sac_to_gmp: exiting\n");fflush(stderr); #endif return; }
static void check_nan_inf_mpq (void) { mpfr_t mpfr_value, mpfr_cmp; mpq_t mpq_value; int status; mpfr_init2 (mpfr_value, MPFR_PREC_MIN); mpq_init (mpq_value); mpq_set_si (mpq_value, 0, 0); mpz_set_si (mpq_denref (mpq_value), 0); status = mpfr_set_q (mpfr_value, mpq_value, MPFR_RNDN); if ((status != 0) || (!MPFR_IS_NAN (mpfr_value))) { mpfr_init2 (mpfr_cmp, MPFR_PREC_MIN); mpfr_set_nan (mpfr_cmp); printf ("mpfr_set_q with a NAN mpq value returned a wrong value :\n" " waiting for "); mpfr_print_binary (mpfr_cmp); printf (" got "); mpfr_print_binary (mpfr_value); printf ("\n trinary value is %d\n", status); exit (1); } mpq_set_si (mpq_value, -1, 0); mpz_set_si (mpq_denref (mpq_value), 0); status = mpfr_set_q (mpfr_value, mpq_value, MPFR_RNDN); if ((status != 0) || (!MPFR_IS_INF (mpfr_value)) || (MPFR_SIGN(mpfr_value) != mpq_sgn(mpq_value))) { mpfr_init2 (mpfr_cmp, MPFR_PREC_MIN); mpfr_set_inf (mpfr_cmp, -1); printf ("mpfr_set_q with a -INF mpq value returned a wrong value :\n" " waiting for "); mpfr_print_binary (mpfr_cmp); printf (" got "); mpfr_print_binary (mpfr_value); printf ("\n trinary value is %d\n", status); exit (1); } mpq_clear (mpq_value); mpfr_clear (mpfr_value); }
int64_t xgcd_mpz_s64(int64_t* out_s, int64_t* out_t, const int64_t in_u, const int64_t in_v) { // NOTE: We hack the structure of an mpz_t so that // it uses stack memory. We use 128-bits instead of 64-bits // since it seems that some intermediate numbers use more than // 64-bits. We hope that 128-bits is enough. mpz_t g; mpz_t s; mpz_t t; mpz_t u; mpz_t v; uint64_t g_[2]; uint64_t s_[2]; uint64_t t_[2]; uint64_t u_[2]; uint64_t v_[2]; g->_mp_alloc = 128 / GMP_LIMB_BITS; g->_mp_size = 0; g->_mp_d = (mp_limb_t*)g_; s->_mp_alloc = 128 / GMP_LIMB_BITS; s->_mp_size = 0; s->_mp_d = (mp_limb_t*)s_; t->_mp_alloc = 128 / GMP_LIMB_BITS; t->_mp_size = 0; t->_mp_d = (mp_limb_t*)t_; u->_mp_alloc = 128 / GMP_LIMB_BITS; u->_mp_size = 0; u->_mp_d = (mp_limb_t*)u_; v->_mp_alloc = 128 / GMP_LIMB_BITS; v->_mp_size = 0; v->_mp_d = (mp_limb_t*)v_; mpz_set_ui(g, 0); mpz_set_ui(s, 0); mpz_set_ui(t, 0); mpz_set_si(u, in_u); mpz_set_si(v, in_v); mpz_gcdext(g, s, t, u, v); *out_s = mpz_get_si(s); *out_t = mpz_get_si(t); return mpz_get_si(g); }
int main(int argc, const char * argv[]) { mpz_t a[7], mod, n; mpz_inits(a[0], a[1], a[2], a[3], a[4], a[5], a[6], n, NULL); mpz_init_set_si(mod, 5); mpz_set_si(a[4], 1); mpz_set_si(n, 5); PointRef g = PointCreateFromInt(0,1); PointRef p = PointCreateFromInt(2,4); PointRef q = PointCreateFromInt(3,1); PointRef pTeta = PointCreateTeta(); PointRef qTeta = PointCreateTeta(); PointRef p2 = PointCreateFromInt(3,2); PointRef p2Inv = PointCreateFromInt(3,3); CurveRef curve = CurveCreate(mod, n, a, g); assert(curve != NULL); assert(curve->a[4] != NULL); assert(curve->a[6] != NULL); assert(curve->g != NULL); assert(curve->mod != NULL); addPoints(p, q, curve); addDoublePoint(p2, p2, curve); addPteta(pTeta, q, curve); addQteta(p, qTeta, curve); addResultTeta(p2, p2Inv, curve); mpz_clears(mod, a[0], a[1], a[2], a[3], a[4], a[5], a[6], NULL); PointDestroy(g); PointDestroy(p); PointDestroy(q); PointDestroy(pTeta); PointDestroy(qTeta); PointDestroy(p2); PointDestroy(p2Inv); CurveDestroy(curve); return 0; }
void insert_constraint_into_matrix (CloogMatrix *m, int row, ppl_const_Constraint_t cstr) { ppl_Coefficient_t c; ppl_dimension_type i, dim, nb_cols = m->NbColumns; ppl_Constraint_space_dimension (cstr, &dim); ppl_new_Coefficient (&c); for (i = 0; i < dim; i++) { ppl_Constraint_coefficient (cstr, i, c); ppl_Coefficient_to_mpz_t (c, m->p[row][i + 1]); } for (i = dim; i < nb_cols - 1; i++) mpz_set_si (m->p[row][i + 1], 0); ppl_Constraint_inhomogeneous_term (cstr, c); ppl_Coefficient_to_mpz_t (c, m->p[row][nb_cols - 1]); mpz_set_si (m->p[row][0], 1); switch (ppl_Constraint_type (cstr)) { case PPL_CONSTRAINT_TYPE_LESS_THAN: oppose_constraint (m, row); case PPL_CONSTRAINT_TYPE_GREATER_THAN: mpz_sub_ui (m->p[row][nb_cols - 1], m->p[row][nb_cols - 1], 1); break; case PPL_CONSTRAINT_TYPE_LESS_OR_EQUAL: oppose_constraint (m, row); case PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL: break; case PPL_CONSTRAINT_TYPE_EQUAL: mpz_set_si (m->p[row][0], 0); break; default: /* Not yet implemented. */ gcc_unreachable(); } ppl_delete_Coefficient (c); }
static void get_array_index (gfc_array_ref *ar, mpz_t *offset) { gfc_expr *e; int i; mpz_t delta; mpz_t tmp; mpz_init (tmp); mpz_set_si (*offset, 0); mpz_init_set_si (delta, 1); for (i = 0; i < ar->dimen; i++) { e = gfc_copy_expr (ar->start[i]); gfc_simplify_expr (e, 1); if ((gfc_is_constant_expr (ar->as->lower[i]) == 0) || (gfc_is_constant_expr (ar->as->upper[i]) == 0) || (gfc_is_constant_expr (e) == 0)) gfc_error ("non-constant array in DATA statement %L", &ar->where); mpz_set (tmp, e->value.integer); gfc_free_expr (e); mpz_sub (tmp, tmp, ar->as->lower[i]->value.integer); mpz_mul (tmp, tmp, delta); mpz_add (*offset, tmp, *offset); mpz_sub (tmp, ar->as->upper[i]->value.integer, ar->as->lower[i]->value.integer); mpz_add_ui (tmp, tmp, 1); mpz_mul (delta, tmp, delta); } mpz_clear (delta); mpz_clear (tmp); }
void mpq_set_si (MP_RAT *dest, signed long int num, unsigned long int den) { unsigned long int abs_num; if (GMP_NUMB_BITS < BITS_PER_ULONG) { if (num == 0) /* Canonicalize 0/d to 0/1. */ den = 1; mpz_set_si (mpq_numref (dest), num); mpz_set_ui (mpq_denref (dest), den); return; } abs_num = ABS_CAST (unsigned long, num); if (num == 0) { /* Canonicalize 0/d to 0/1. */ den = 1; dest->_mp_num._mp_size = 0; } else { dest->_mp_num._mp_d[0] = abs_num; dest->_mp_num._mp_size = num > 0 ? 1 : -1; } dest->_mp_den._mp_d[0] = den; dest->_mp_den._mp_size = (den != 0); }
static void mpz_set_PyInt(mpz_t rop, PyObject *obj) { assert(PyInt_Check(obj)); mpz_set_si(rop, PyInt_AsLong(obj)); return; }
void mpq_set_si (mpq_ptr dest, mpir_si num, mpir_ui den) { mpir_ui abs_num; if (GMP_NUMB_BITS < BITS_PER_UI) { if (num == 0) /* Canonicalize 0/d to 0/1. */ den = 1; mpz_set_si (mpq_numref (dest), num); mpz_set_ui (mpq_denref (dest), den); return; } abs_num = ABS (num); if (num == 0) { /* Canonicalize 0/d to 0/1. */ den = 1; dest->_mp_num._mp_size = 0; } else { dest->_mp_num._mp_d[0] = abs_num; dest->_mp_num._mp_size = num > 0 ? 1 : -1; } dest->_mp_den._mp_d[0] = den; dest->_mp_den._mp_size = (den != 0); }
// // ( n ) ( n ) (n+1)-k // return ( ) == ( ) ------- // ( k ) (k-1) k // void binomialCoefficient(mpz_t b, long n, long k) { mpz_set_ui(b,0); if(k>n || k<0) return; mpz_set_si(b,n); mpz_bin_ui(b,b,k); }
ring_elem RingZZ::from_int(int n) const { mpz_ptr result = new_elem(); mpz_set_si(result, n); return ring_elem(result); }
static void lst_scale (lst_p lst, lst_p stmt, mpz_t factor) { mpz_t x; ppl_Coefficient_t one; int outer_depth = lst_depth (lst); poly_bb_p pbb = LST_PBB (stmt); ppl_Polyhedron_t poly = PBB_TRANSFORMED_SCATTERING (pbb); ppl_dimension_type outer_dim = psct_dynamic_dim (pbb, outer_depth); ppl_Linear_Expression_t expr; ppl_dimension_type dim; mpz_init (x); mpz_set_si (x, 1); ppl_new_Coefficient (&one); ppl_assign_Coefficient_from_mpz_t (one, x); ppl_Polyhedron_space_dimension (poly, &dim); ppl_new_Linear_Expression_with_dimension (&expr, dim); /* outer_dim = factor * outer_dim. */ ppl_set_coef_gmp (expr, outer_dim, factor); ppl_Polyhedron_affine_image (poly, outer_dim, expr, one); ppl_delete_Linear_Expression (expr); mpz_clear (x); ppl_delete_Coefficient (one); }
void mpq_set_si (MP_RAT *dest, signed long int num, unsigned long int den) { unsigned long int abs_num; if (GMP_NUMB_BITS < BITS_PER_ULONG) { if (num == 0) /* Canonicalize 0/d to 0/1. */ den = 1; mpz_set_si (mpq_numref (dest), num); mpz_set_ui (mpq_denref (dest), den); return; } abs_num = ABS_CAST (unsigned long, num); if (num == 0) { /* Canonicalize 0/d to 0/1. */ den = 1; SIZ(NUM(dest)) = 0; } else { PTR(NUM(dest))[0] = abs_num; SIZ(NUM(dest)) = num > 0 ? 1 : -1; } PTR(DEN(dest))[0] = den; SIZ(DEN(dest)) = (den != 0); }
mpz_class renf_elem_class::num() const noexcept { mpz_class x; if (nf == nullptr) { fmpz_get_mpz(x.__get_mp(), fmpq_numref(b)); return x; } else if (nf->renf_t()->nf->flag & NF_LINEAR) fmpz_get_mpz(x.__get_mp(), LNF_ELEM_NUMREF(a->elem)); else if (nf->renf_t()->nf->flag & NF_QUADRATIC) { assert(fmpz_is_zero(QNF_ELEM_NUMREF(a->elem) + 1) && "renf_elem_class not a rational"); fmpz_get_mpz(x.__get_mp(), QNF_ELEM_NUMREF(a->elem)); } else { if (fmpq_poly_length(NF_ELEM(a->elem)) == 0) mpz_set_si(x.__get_mp(), 0); else { assert(fmpq_poly_length(NF_ELEM(a->elem)) == 1 && "renf_elem_class not a rational"); fmpz_get_mpz(x.__get_mp(), NF_ELEM_NUMREF(a->elem)); } } return x; }
static void lst_linearized_niter (lst_p lst, mpz_t res) { int i; lst_p l; mpz_t n; mpz_init (n); mpz_set_si (res, 0); FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l) if (LST_LOOP_P (l)) { lst_linearized_niter (l, n); mpz_add (res, res, n); } if (LST_LOOP_P (lst)) { lst_niter_for_loop (lst, n); if (mpz_cmp_si (res, 0) != 0) mpz_mul (res, res, n); else mpz_set (res, n); } mpz_clear (n); }
VAL GETBIG(VM * vm, VAL x) { idris_requireAlloc(IDRIS_MAXGMP); if (ISINT(x)) { mpz_t* bigint; VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0); idris_doneAlloc(); bigint = (mpz_t*)(((char*)cl) + sizeof(Closure)); mpz_init(*bigint); mpz_set_si(*bigint, GETINT(x)); SETTY(cl, CT_BIGINT); cl -> info.ptr = (void*)bigint; return cl; } else { idris_doneAlloc(); switch(GETTY(x)) { case CT_FWD: return GETBIG(vm, x->info.ptr); default: return x; } } }
TEST(RingRRR, power) { RRR *R = RRR::create(100); mpz_t gmp1; mpz_init(gmp1); RingElementGenerator<RRR> gen(*R); for (int i=0; i<ntrials; i++) { ring_elem a = gen.nextElement(); //TODO: what should the answer here be? //EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too? EXPECT_TRUE(R->is_equal(R->power(a, 1), a)); int e1 = rawRandomInt(10) + 1; int e2 = rawRandomInt(10) + 1; //std::cout << "(" << e1 << "," << e2 << ")" << std::endl; ring_elem b = R->power(a, e1); ring_elem c = R->power(a, e2); ring_elem d = R->power(a, e1+e2); EXPECT_TRUE(almostEqual(R,96,R->mult(b,c),d)); // Make sure that powers via mpz work (at least for small exponents) mpz_set_si(gmp1, e1); ring_elem b1 = R->power(a, gmp1); EXPECT_TRUE(R->is_equal(b1, b)); } mpz_clear(gmp1); }
static void check0 (void) { mpz_t y; mpfr_t x; int inexact, r; mpfr_exp_t e; /* Check for +0 */ mpfr_init (x); mpz_init (y); mpz_set_si (y, 0); for (r = 0; r < MPFR_RND_MAX; r++) { e = randexp (); inexact = mpfr_set_z_2exp (x, y, e, (mpfr_rnd_t) r); if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact) { printf ("mpfr_set_z_2exp(x,0,e) failed for e="); if (e < LONG_MIN) printf ("(<LONG_MIN)"); else if (e > LONG_MAX) printf ("(>LONG_MAX)"); else printf ("%ld", (long) e); printf (", rnd=%s\n", mpfr_print_rnd_mode ((mpfr_rnd_t) r)); exit (1); } } mpfr_clear(x); mpz_clear(y); }
static void lst_offset (lst_p stmt, mpz_t offset) { lst_p inner = LST_LOOP_FATHER (stmt); poly_bb_p pbb = LST_PBB (stmt); ppl_Polyhedron_t poly = PBB_TRANSFORMED_SCATTERING (pbb); int inner_depth = lst_depth (inner); ppl_dimension_type inner_dim = psct_dynamic_dim (pbb, inner_depth); ppl_Linear_Expression_t expr; ppl_dimension_type dim; ppl_Coefficient_t one; mpz_t x; mpz_init (x); mpz_set_si (x, 1); ppl_new_Coefficient (&one); ppl_assign_Coefficient_from_mpz_t (one, x); ppl_Polyhedron_space_dimension (poly, &dim); ppl_new_Linear_Expression_with_dimension (&expr, dim); ppl_set_coef (expr, inner_dim, 1); ppl_set_inhomogeneous_gmp (expr, offset); ppl_Polyhedron_affine_image (poly, inner_dim, expr, one); ppl_delete_Linear_Expression (expr); ppl_delete_Coefficient (one); }