void ep_rhs(fp_t rhs, const ep_t p) { fp_t t0; fp_t t1; fp_null(t0); fp_null(t1); TRY { fp_new(t0); fp_new(t1); /* t0 = x1^2. */ fp_sqr(t0, p->x); /* t1 = x1^3. */ fp_mul(t1, t0, p->x); /* t1 = x1^3 + a * x1 + b. */ switch (ep_curve_opt_a()) { case OPT_ZERO: break; case OPT_ONE: fp_add(t1, t1, p->x); break; #if FP_RDC != MONTY case OPT_DIGIT: fp_mul_dig(t0, p->x, ep_curve_get_a()[0]); fp_add(t1, t1, t0); break; #endif default: fp_mul(t0, p->x, ep_curve_get_a()); fp_add(t1, t1, t0); break; } switch (ep_curve_opt_b()) { case OPT_ZERO: break; case OPT_ONE: fp_add_dig(t1, t1, 1); break; #if FP_RDC != MONTY case OPT_DIGIT: fp_add_dig(t1, t1, ep_curve_get_b()[0]); break; #endif default: fp_add(t1, t1, ep_curve_get_b()); break; } fp_copy(rhs, t1); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t0); fp_free(t1); } }
fp_t forward_proc_inc2(unsigned char o){ fp_t ord = 0; fp_t sum; unsigned char k,l; if (started == false){ for (l = 0; l < 8; l++){ f2[l] = fp_mul(pi2[l],b2[(o<<3) + l]); // pi*b //f[l] = b[o][l]; } return 0; }else{ for (k = 0; k < 8; k++){ sum = 0; for (l = 0; l < 8; l++){ sum = fp_add(sum, fp_mul(s2[l], a2[(l<<3) + k])); //sum = fp_add(sum, fp_mul(s2[l], b2[(l<<3) +k])); } f2[k] = fp_mul(sum, b2[(o<<3)+k]); //f[k] = fp_mul(sum, b2[o][k]); ord |= f2[k]; } } return ord; }
int fp2_srt(fp2_t c, fp2_t a) { int r = 0; fp_t t1; fp_t t2; fp_t t3; fp_null(t1); fp_null(t2); fp_null(t3); TRY { fp_new(t1); fp_new(t2); fp_new(t3); /* t1 = a[0]^2 - u^2 * a[1]^2 */ fp_sqr(t1, a[0]); fp_sqr(t2, a[1]); for (int i = -1; i > fp_prime_get_qnr(); i--) { fp_add(t1, t1, t2); } for (int i = 0; i <= fp_prime_get_qnr(); i++) { fp_sub(t1, t1, t2); } fp_add(t1, t1, t2); if (fp_srt(t2, t1)) { /* t1 = (a_0 + sqrt(t1)) / 2 */ fp_add(t1, a[0], t2); fp_set_dig(t3, 2); fp_inv(t3, t3); fp_mul(t1, t1, t3); if (!fp_srt(t3, t1)) { /* t1 = (a_0 - sqrt(t1)) / 2 */ fp_sub(t1, a[0], t2); fp_set_dig(t3, 2); fp_inv(t3, t3); fp_mul(t1, t1, t3); fp_srt(t3, t1); } /* c_0 = sqrt(t1) */ fp_copy(c[0], t3); /* c_1 = a_1 / (2 * sqrt(t1)) */ fp_dbl(t3, t3); fp_inv(t3, t3); fp_mul(c[1], a[1], t3); r = 1; } } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t1); fp_free(t2); fp_free(t3); } return r; }
/** * Normalizes a point represented in projective coordinates. * * @param r - the result. * @param p - the point to normalize. */ void ed_norm(ed_t r, const ed_t p) { if (ed_is_infty(p)) { ed_set_infty(r); return; } if (fp_cmp_dig(p->z, 1) == CMP_EQ) { /* If the point is represented in affine coordinates, we just copy it. */ ed_copy(r, p); } else { fp_t z_inv; fp_null(z_inv); fp_new(z_inv); fp_inv(z_inv, p->z); fp_mul(r->x, p->x, z_inv); fp_mul(r->y, p->y, z_inv); #if ED_ADD == EXTND fp_mul(r->t, p->t, z_inv); #endif fp_set_dig(r->z, 1); fp_free(z_inv); } }
//Performs the next iteration of the HMM forward algorithm fp_t forward_proc_inc(char o){ fp_t ord = 0; fp_t sum; char k,l; if (started == false){ for (l = 0; l < 8; l++){ f[l] = b[(o<<3) + l]; // pi*b //f[l] = b[o][l]; } for (l = 1; l < 8; l++){ f[l] = 0; } return 0; }else{ for (k = 0; k < 8; k++){ sum = 0; for (l = 0; l < 8; l++){ //sum = fp_add(sum, fp_mul(s[l], a[(l<<3) + k])); sum = fp_add(sum, fp_mul(s[l], b[(l<<3) +k])); } f[k] = fp_mul(sum, b[(o<<3)+k]); //f[k] = fp_mul(sum, b[o][k]); ord |= f[k]; } } return ord; }
void ed_norm_sim(ed_t *r, const ed_t *t, int n) { int i; fp_t a[n]; for (i = 0; i < n; i++) { fp_null(a[i]); } TRY { for (i = 0; i < n; i++) { fp_new(a[i]); fp_copy(a[i], t[i]->z); } fp_inv_sim(a, (const fp_t *)a, n); for (i = 0; i < n; i++) { fp_mul(r[i]->x, t[i]->x, a[i]); fp_mul(r[i]->y, t[i]->y, a[i]); #if ED_ADD == EXTND fp_mul(r[i]->t, t[i]->t, a[i]); #endif fp_set_dig(r[i]->z, 1); } } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { for (i = 0; i < n; i++) { fp_free(a[i]); } } }
char filter(){ fp_t abs = fp_add(fp_add(fp_mul(acc[0], acc[0]), fp_mul(acc[1], acc[1])), fp_mul(acc[2], acc[2])); //////////////////////////////////////////////////////////////////////////////// //idle state filter if (!(fp_cmp(abs, d2fp(0.32))==1 || fp_cmp(abs, d2fp(0.27))==-1)) { // if between 0.01 - 0.09 return false; } //////////////////////////////////////////////////////////////////////////////// // def = directional equivalence filter fp_t def_sensitivity = d2fp(0.08); if (fp_cmp(acc[0], fp_sub(dir_filter_ref[0], def_sensitivity))==-1 || fp_cmp(acc[0], fp_add(dir_filter_ref[0], def_sensitivity))== 1 || fp_cmp(acc[1], fp_sub(dir_filter_ref[1], def_sensitivity))==-1 || fp_cmp(acc[1], fp_add(dir_filter_ref[1], def_sensitivity))== 1 || fp_cmp(acc[2], fp_sub(dir_filter_ref[2], def_sensitivity))==-1 || fp_cmp(acc[2], fp_add(dir_filter_ref[2], def_sensitivity))==1) { dir_filter_ref[0] = acc[0]; dir_filter_ref[1] = acc[1]; dir_filter_ref[2] = acc[2]; return true; } return false; }
void pp_dbl_k12_basic(fp12_t l, ep2_t r, ep2_t q, ep_t p) { fp2_t s; ep2_t t; int one = 1, zero = 0; fp2_null(s); ep2_null(t); TRY { fp2_new(s); ep2_new(t); ep2_copy(t, q); ep2_dbl_slp_basic(r, s, q); fp12_zero(l); if (ep2_curve_is_twist() == EP_MTYPE) { one ^= 1; zero ^= 1; } fp_mul(l[one][zero][0], s[0], p->x); fp_mul(l[one][zero][1], s[1], p->x); fp2_mul(l[one][one], s, t->x); fp2_sub(l[one][one], t->y, l[one][one]); fp_copy(l[zero][zero][0], p->y); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp2_free(s); ep2_free(t); } }
/** * Normalizes a point represented in projective coordinates. * * @param r - the result. * @param p - the point to normalize. */ static void ep_norm_imp(ep_t r, const ep_t p, int inverted) { if (!p->norm) { fp_t t0, t1; fp_null(t0); fp_null(t1); TRY { fp_new(t0); fp_new(t1); if (inverted) { fp_copy(t1, p->z); } else { fp_inv(t1, p->z); } fp_sqr(t0, t1); fp_mul(r->x, p->x, t0); fp_mul(t0, t0, t1); fp_mul(r->y, p->y, t0); fp_set_dig(r->z, 1); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t0); fp_free(t1); } }
static int tfm_rsa_private_calculate(fp_int * in, fp_int * p, fp_int * q, fp_int * dmp1, fp_int * dmq1, fp_int * iqmp, fp_int * out) { fp_int vp, vq, u; fp_init_multi(&vp, &vq, &u, NULL); /* vq = c ^ (d mod (q - 1)) mod q */ /* vp = c ^ (d mod (p - 1)) mod p */ fp_mod(in, p, &u); fp_exptmod(&u, dmp1, p, &vp); fp_mod(in, q, &u); fp_exptmod(&u, dmq1, q, &vq); /* C2 = 1/q mod p (iqmp) */ /* u = (vp - vq)C2 mod p. */ fp_sub(&vp, &vq, &u); if (fp_isneg(&u)) fp_add(&u, p, &u); fp_mul(&u, iqmp, &u); fp_mod(&u, p, &u); /* c ^ d mod n = vq + u q */ fp_mul(&u, q, &u); fp_add(&u, &vq, out); fp_zero_multi(&vp, &vq, &u, NULL); return 0; }
char filter(){ fp_t abs = fp_add(fp_add(fp_mul(acc[0], acc[0]), fp_mul(acc[1], acc[1])), fp_mul(acc[2], acc[2])); //////////////////////////////////////////////////////////////////////////////// //idle state filter if (!(fp_cmp(abs, 10486)==1 /*0.32*/ || fp_cmp(abs, 8847)==2 /*0.27*/)) { // if between 0.01 - 0.09 return false; } //////////////////////////////////////////////////////////////////////////////// // def = directional equivalence filter const fp_t def_sensitivity = 2621; //0.08 if (fp_cmp(acc[0], fp_sub(dir_filter_ref[0], def_sensitivity))==2 || fp_cmp(acc[0], fp_add(dir_filter_ref[0], def_sensitivity))== 1 || fp_cmp(acc[1], fp_sub(dir_filter_ref[1], def_sensitivity))==2 || fp_cmp(acc[1], fp_add(dir_filter_ref[1], def_sensitivity))== 1 || fp_cmp(acc[2], fp_sub(dir_filter_ref[2], def_sensitivity))==2 || fp_cmp(acc[2], fp_add(dir_filter_ref[2], def_sensitivity))==1) { dir_filter_ref[0] = acc[0]; dir_filter_ref[1] = acc[1]; dir_filter_ref[2] = acc[2]; return true; } return false; }
void fp2_sqr_basic(fp2_t c, fp2_t a) { fp_t t0, t1, t2; fp_null(t0); fp_null(t1); fp_null(t2); TRY { fp_new(t0); fp_new(t1); fp_new(t2); /* t0 = (a_0 + a_1). */ fp_add(t0, a[0], a[1]); /* t1 = (a_0 - a_1). */ fp_sub(t1, a[0], a[1]); /* t1 = a_0 + u^2 * a_1. */ for (int i = -1; i > fp_prime_get_qnr(); i--) { fp_sub(t1, t1, a[1]); } for (int i = 0; i <= fp_prime_get_qnr(); i++) { fp_add(t1, t1, a[1]); } if (fp_prime_get_qnr() == -1) { /* t2 = 2 * a_0. */ fp_dbl(t2, a[0]); /* c_1 = 2 * a_0 * a_1. */ fp_mul(c[1], t2, a[1]); /* c_0 = a_0^2 + a_1^2 * u^2. */ fp_mul(c[0], t0, t1); } else { /* c_1 = a_0 * a_1. */ fp_mul(c[1], a[0], a[1]); /* c_0 = a_0^2 + a_1^2 * u^2. */ fp_mul(c[0], t0, t1); for (int i = -1; i > fp_prime_get_qnr(); i--) { fp_add(c[0], c[0], c[1]); } for (int i = 0; i <= fp_prime_get_qnr(); i++) { fp_sub(c[0], c[0], c[1]); } /* c_1 = 2 * a_0 * a_1. */ fp_dbl(c[1], c[1]); } /* c = c_0 + c_1 * u. */ } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t0); fp_free(t1); fp_free(t2); } }
void SynthController::updateCutoff() { fixed envValue = envelope_.GetValue(); fixed envContrib = fp_sub(FP_ONE, envValue); envContrib = fp_mul(envContrib, cutoffEnvMod_); envContrib = fp_sub(FP_ONE, envContrib); fixed current = fp_mul(cutoff_, envContrib); hwParameters_.cutoff_ = int(fp2fl(current)*255); }
void fp2_inv(fp2_t c, fp2_t a) { fp_t t0, t1; fp_null(t0); fp_null(t1); TRY { fp_new(t0); fp_new(t1); /* t0 = a_0^2, t1 = a_1^2. */ fp_sqr(t0, a[0]); fp_sqr(t1, a[1]); /* t1 = 1/(a_0^2 + a_1^2). */ #ifndef FP_QNRES if (fp_prime_get_qnr() != -1) { if (fp_prime_get_qnr() == -2) { fp_dbl(t1, t1); fp_add(t0, t0, t1); } else { if (fp_prime_get_qnr() < 0) { fp_mul_dig(t1, t1, -fp_prime_get_qnr()); fp_add(t0, t0, t1); } else { fp_mul_dig(t1, t1, fp_prime_get_qnr()); fp_sub(t0, t0, t1); } } } else { fp_add(t0, t0, t1); } #else fp_add(t0, t0, t1); #endif fp_inv(t1, t0); /* c_0 = a_0/(a_0^2 + a_1^2). */ fp_mul(c[0], a[0], t1); /* c_1 = - a_1/(a_0^2 + a_1^2). */ fp_mul(c[1], a[1], t1); fp_neg(c[1], c[1]); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t0); fp_free(t1); } }
/* c = [a, b] */ void fp_lcm(fp_int *a, fp_int *b, fp_int *c) { fp_int t1, t2; fp_init(&t1); fp_init(&t2); fp_gcd(a, b, &t1); if (fp_cmp_mag(a, b) == FP_GT) { fp_div(a, &t1, &t2, NULL); fp_mul(b, &t2, c); } else { fp_div(b, &t1, &t2, NULL); fp_mul(a, &t2, c); } }
static TENTHSDEGC convertToTenthsOfDegrees(uint16_t reading) { // Convert the reading into thermistor resistance before conversion FIXED_POINT_TYPE temp = THERMISTOR_TemperatureFromADCReading(&thermistor, ÷r, reading); temp = fp_mul(temp, fp_from_int(10)); return (TENTHSDEGC)fp_to_int( temp ); }
/* d = a * b (mod c) */ int fp_mulmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d) { fp_int tmp; fp_zero(&tmp); fp_mul(a, b, &tmp); return fp_mod(&tmp, c, d); }
/* mul */ static int mul(void *a, void *b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(b != NULL); LTC_ARGCHK(c != NULL); fp_mul(a, b, c); return CRYPT_OK; }
fp_t arc_cos(fp_t x) { int i; /* Cap x if out of range. */ if (x < FLOAT_TO_FP(-1.0)) x = FLOAT_TO_FP(-1.0); else if (x > FLOAT_TO_FP(1.0)) x = FLOAT_TO_FP(1.0); /* * Increment through lookup table to find index and then linearly * interpolate for precision. */ /* TODO(crosbug.com/p/25600): Optimize with binary search. */ for (i = 0; i < COSINE_LUT_SIZE-1; i++) { if (x >= cos_lut[i+1]) { const fp_t interp = fp_div(cos_lut[i] - x, cos_lut[i] - cos_lut[i + 1]); return fp_mul(INT_TO_FP(COSINE_LUT_INCR_DEG), INT_TO_FP(i) + interp); } } /* * Shouldn't be possible to get here because inputs are clipped to * [-1, 1] and the cos_lut[] table goes over the same range. If we * are here, throw an assert. */ ASSERT(0); return 0; }
/* * Uncompress twisted Edwards curve point. */ int ed_upk(ed_t r, const ed_t p) { int result = 1; fp_t t; TRY { fp_new(t); fp_copy(r->y, p->y); ed_recover_x(t, p->y, core_get()->ed_d, core_get()->ed_a); if (fp_get_bit(t, 0) != fp_get_bit(p->x, 0)) { fp_neg(t, t); } fp_copy(r->x, t); #if ED_ADD == EXTND fp_mul(r->t, r->x, r->y); #endif fp_set_dig(r->z, 1); r->norm = 1; } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t); } return result; }
fixed SynthController::ProcessSample() { const fixed noise = noiseGenerator_.ProcessSample(); const fixed osc = oscillator_.ProcessSample(); const fixed value=fp_add(noise,osc); const fixed envValue =envelope_.GetScaledValue(); return fp_mul(value, envValue); }
/* Evaluates the following polynomial at x = a: * * coefs[0] x^(n-1) + coefs[1] x^(n-1) + ... + coefs[n-1] * * using the Horner scheme. This changes the order of evaluation to: * * coefs[n-1] + (coefs[n-2] + (... + coefs[n-1] * x) * x) * x * * which greatly reduces the number of required multiplies. */ fp_t fp_poly(fp_t coefs[], size_t n, fp_t a) { size_t i; fp_t out; out = coefs[0]; for(i = 1; i < n; ++i) { out = fp_mul(a, out); out = fp_add(coefs[i], out); } return out; }
unsigned char derive_group2(){ fp_t a, b, c, d; fp_t minDist = 0x7fff; //0x7fff; char minGroup=0; fp_t *ref; char i; for (i = 0; i < 14; i++){ ref = quantizerMap2[i]; a = fp_sub(ref[0], acc[0]); b = fp_sub(ref[1], acc[1]); c = fp_sub(ref[2], acc[2]); d = fp_add(fp_add(fp_mul(a,a), fp_mul(b,b)), fp_mul(c,c)); if (fp_cmp(d, minDist) == 2){ minDist = d; minGroup = i; } } /* UARTSendArray("group=", 6); */ /* UARTSendInt(minGroup); */ return minGroup; }
int ed_affine_is_valid(const fp_t x, const fp_t y) { fp_t tmpFP0; fp_t tmpFP1; fp_t tmpFP2; fp_null(tmpFP0); fp_null(tmpFP1); fp_null(tmpFP2); int r = 0; TRY { fp_new(tmpFP0); fp_new(tmpFP1); fp_new(tmpFP2); // a * X^2 + Y^2 - 1 - d * X^2 * Y^2 =?= 0 fp_sqr(tmpFP0, x); fp_mul(tmpFP0, core_get()->ed_a, tmpFP0); fp_sqr(tmpFP1, y); fp_add(tmpFP1, tmpFP0, tmpFP1); fp_sub_dig(tmpFP1, tmpFP1, 1); fp_sqr(tmpFP0, x); fp_mul(tmpFP0, core_get()->ed_d, tmpFP0); fp_sqr(tmpFP2, y); fp_mul(tmpFP2, tmpFP0, tmpFP2); fp_sub(tmpFP0, tmpFP1, tmpFP2); r = fp_is_zero(tmpFP0); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(tmpFP0); fp_free(tmpFP1); fp_free(tmpFP2); } return r; }
void fp2_mul_frb(fp2_t c, fp2_t a, int i, int j) { ctx_t *ctx = core_get(); if (i == 2) { fp_mul(c[0], a[0], ctx->fp2_p2[j - 1]); fp_mul(c[1], a[1], ctx->fp2_p2[j - 1]); } else { #if ALLOC == AUTO if (i == 1) { fp2_mul(c, a, ctx->fp2_p[j - 1]); } else { fp2_mul(c, a, ctx->fp2_p3[j - 1]); } #else fp2_t t; fp2_null(t); TRY { fp2_new(t); if (i == 1) { fp_copy(t[0], ctx->fp2_p[j - 1][0]); fp_copy(t[1], ctx->fp2_p[j - 1][1]); } else { fp_copy(t[0], ctx->fp2_p3[j - 1][0]); fp_copy(t[1], ctx->fp2_p3[j - 1][1]); } fp2_mul(c, a, t); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp2_free(t); } #endif } }
void set_filter(int channel, filterType_t type, fixed param1,fixed param2,int mix,bool bassyMapping) { filter_t* flt=&filter[channel]; if(flt->type!=type) //reset only on filter type change (maybe no reset would make interresting bugs) { flt->height[0]=0; //idle state flt->height[1]=0; //idle state flt->speed[0]=0; //paused (to avoid having it goind crazy) flt->speed[1]=0; //paused (to avoid having it goind crazy) flt->hipdelay[0]=0 ; flt->hipdelay[1]=0 ; flt->type=type; } flt->dirt=fp_mul(i2fp(100),i2fp(1)-param1)+fp_mul(i2fp(5000),param1) ; flt->mix =fp_mul(i2fp(mix),fp_inv_255) ; if (param1 != flt->parm1) { flt->parm1=param1; //adjust parm to get the most of the parameters, as the fx are more useful with near-limit parameters. if (bassyMapping) { static const fixed fpFreqDivider = fl2fp(1/22050.0f); static const fixed fpZeroSix = fl2fp(0.6f); static const fixed fpThreeOne = fl2fp(3.1f); fixed power = fp_add(fpZeroSix,fp_mul(param1,fpThreeOne)); fixed frequency = fl2fp(pow(10.0f,fp2fl(power))) ; frequency=fp_mul(frequency,fpFreqDivider); flt->freq=frequency; } else { flt->freq=fp_mul(param1,param1); //0 - .5 - 1 => 0 - .25 - 1 } } if (param2 != flt->parm2) { flt->parm2=param2; flt->reso=i2fp(1)-param2 ; flt->reso=fp_sub(fl2fp(1.f),fp_mul(flt->reso,fp_mul(flt->reso,flt->reso))); //0 - .5 - 1 => 0 - .93 - 1 } }
int ed_is_valid(const ed_t p) { ed_t t; #if ED_ADD == EXTND fp_t x_times_y; #endif int r = 0; ed_null(t); #if ED_ADD == EXTND fp_null(x_times_y); #endif if (fp_is_zero(p->z)) { r = 0; } else { TRY { #if ED_ADD == EXTND fp_new(x_times_y); #endif ed_new(t); ed_norm(t, p); // check t coordinate #if ED_ADD == PROJC r = ed_affine_is_valid(t->x, t->y); #elif ED_ADD == EXTND fp_mul(x_times_y, t->x, t->y); if (fp_cmp(x_times_y, t->t) != CMP_EQ) { r = 0; } else { r = ed_affine_is_valid(t->x, t->y); } #endif // if (r == 0) { // util_printf("\n\n(X, Y, T, Z) = \n"); // ed_print(p); // } } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { #if ED_ADD == EXTND fp_free(x_times_y); #endif ed_free(t); } } return r; }
void fp_mul_dig(fp_t c, const fp_t a, dig_t b) { dv_t t; dv_null(t); TRY { dv_new(t); fp_prime_conv_dig(t, b); fp_mul(c, a, t); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { dv_free(t); } }
int main() { if (fp_add (1, 1) != 2) fail ("fp_add 1+1"); if (fp_sub (3, 2) != 1) fail ("fp_sub 3-2"); if (fp_mul (2, 3) != 6) fail ("fp_mul 2*3"); if (fp_div (3, 2) != 1.5) fail ("fp_div 3/2"); if (fp_neg (1) != -1) fail ("fp_neg 1"); if (dp_add (1, 1) != 2) fail ("dp_add 1+1"); if (dp_sub (3, 2) != 1) fail ("dp_sub 3-2"); if (dp_mul (2, 3) != 6) fail ("dp_mul 2*3"); if (dp_div (3, 2) != 1.5) fail ("dp_div 3/2"); if (dp_neg (1) != -1) fail ("dp_neg 1"); if (fp_to_dp (1.5) != 1.5) fail ("fp_to_dp 1.5"); if (dp_to_fp (1.5) != 1.5) fail ("dp_to_fp 1.5"); if (floatsisf (1) != 1) fail ("floatsisf 1"); if (floatsidf (1) != 1) fail ("floatsidf 1"); if (fixsfsi (1.42) != 1) fail ("fixsfsi 1.42"); if (fixunssfsi (1.42) != 1) fail ("fixunssfsi 1.42"); if (fixdfsi (1.42) != 1) fail ("fixdfsi 1.42"); if (fixunsdfsi (1.42) != 1) fail ("fixunsdfsi 1.42"); if (eqsf2 (1, 1) == 0) fail ("eqsf2 1==1"); if (eqsf2 (1, 2) != 0) fail ("eqsf2 1==2"); if (nesf2 (1, 2) == 0) fail ("nesf2 1!=1"); if (nesf2 (1, 1) != 0) fail ("nesf2 1!=1"); if (gtsf2 (2, 1) == 0) fail ("gtsf2 2>1"); if (gtsf2 (1, 1) != 0) fail ("gtsf2 1>1"); if (gtsf2 (0, 1) != 0) fail ("gtsf2 0>1"); if (gesf2 (2, 1) == 0) fail ("gesf2 2>=1"); if (gesf2 (1, 1) == 0) fail ("gesf2 1>=1"); if (gesf2 (0, 1) != 0) fail ("gesf2 0>=1"); if (ltsf2 (1, 2) == 0) fail ("ltsf2 1<2"); if (ltsf2 (1, 1) != 0) fail ("ltsf2 1<1"); if (ltsf2 (1, 0) != 0) fail ("ltsf2 1<0"); if (lesf2 (1, 2) == 0) fail ("lesf2 1<=2"); if (lesf2 (1, 1) == 0) fail ("lesf2 1<=1"); if (lesf2 (1, 0) != 0) fail ("lesf2 1<=0"); if (fail_count != 0) abort (); exit (0); }
int ed_is_infty(const ed_t p) { assert(!fp_is_zero(p->z)); int ret = 0; fp_t norm_y; fp_null(norm_y); fp_new(norm_y); fp_inv(norm_y, p->z); fp_mul(norm_y, p->y, norm_y); if (fp_cmp_dig(norm_y, 1) == CMP_EQ && fp_is_zero(p->x)) { ret = 1; } fp_free(norm_y); return ret; }