int alloc_spl (spline_t * spl, int n) { spl->n = n; return MALLOC_FAILED (spl->x, spl->n) || MALLOC_FAILED (spl->f, spl->n) || MALLOC_FAILED (spl->f1, spl->n) || MALLOC_FAILED (spl->f2, spl->n) || MALLOC_FAILED (spl->f3, spl->n); }
void mpfq_p_127_735_field_init(mpfq_p_127_735_dst_field k, mp_limb_t *p) { k->p = (mp_limb_t *)malloc(2*sizeof(mp_limb_t)); k->bigmul_p = (mp_limb_t *)malloc(5*sizeof(mp_limb_t)); if ((!k->p) || (!k->bigmul_p)) MALLOC_FAILED(); { int i; k->p[0] = -735UL; for (i = 1; i < (2-1); ++i) k->p[i] = -1UL; k->p[2-1] = (-1UL) >> 1; // 2^(w-1) - 1 where w is 32 or 64 } k->kl = 2; k->url = 5; k->url_margin = LONG_MAX; k->type = CLASSICAL_REP; mpz_init(k->factor); // precompute bigmul_p = largest multiple of p that fits in an elt_ur // p*Floor( (2^(5*GMP_LIMB_BITS)-1)/p ) { mpfq_p_127_735_elt_ur big; mp_limb_t q[5-2+1], r[2], tmp[5+1]; int i; for (i = 0; i < 5; ++i) big[i] = ~0UL; mpn_tdiv_qr(q, r, 0, big, 5, k->p, 2); mpn_mul(tmp, q, 5-2+1, k->p, 2); for (i = 0; i < 5; ++i) (k->bigmul_p)[i] = tmp[i]; assert (tmp[5] == 0UL); } }
void bitwriter::ensure(uint32_t size) { if (at + size > length) { uint8_t* res = static_cast<uint8_t*>(realloc(static_cast<void*>(to), length * BITWRITER_INCREASE_FACTOR)); if (res == nullptr) { // failed to realloc(), to not free()d MALLOC_FAILED(bitwriter::ensure); } // realloc()ed successfully, to freed to = res; length = length * BITWRITER_INCREASE_FACTOR; } }
int mpfq_p_127_735_read(mpfq_p_127_735_src_field k, mpfq_p_127_735_dst_elt x, const char *str, int base) { int i, n, len; unsigned char *tmp; len = strlen(str); tmp = (unsigned char *) malloc(sizeof(unsigned char)*len); if (!tmp) MALLOC_FAILED(); for (i = 0; i < len; ++i) tmp[i] = (unsigned char)(str[i]-'0'); n = mpn_set_str(x, tmp, len, base); if (n > 2) { fprintf(stderr, "error in read_fp_2, input number is too large\n"); return 0; } for (i = n; i< 2; ++i) x[i] = 0UL; if (mpn_cmp(x,k->p,2) >= 0) { fprintf(stderr, "error in read_fp_2, input number is too large\n"); return 0; } free(tmp); return 1; }