scalar SF(scalar q,scalar r) { scalar qr; qr=q*r; if (qr == 0.0) { return 4./3. * M_PI * gsl_pow_3(r); } else { return 4./3. * M_PI * gsl_pow_3(r) * 3.0*(sin(q*r)-qr*cos(q*r))/gsl_pow_3(q*r); } }
scalar sasfit_ff_pearl_necklace(scalar q, sasfit_param * param) { scalar qR,ql,qA,Psi,L,Mr,mr,ms,beta,Sr,Sp,Sm,sinqA_qA,sinql2_ql2,A; SASFIT_ASSERT_PTR(param); // assert pointer param is valid SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((R < 0.0), param, "R(%lg) < 0",R); // modify condition to your needs SASFIT_CHECK_COND1((L < 0.0), param, "L(%lg) < 0",L); // modify condition to your needs SASFIT_CHECK_COND1((NU < 0.0), param, "nu(%lg) < 0",NU); // modify condition to your needs SASFIT_CHECK_COND1((B < 0.0), param, "b(%lg) < 0",B); // modify condition to your needs SASFIT_CHECK_COND1((NP < 0.0), param, "Np(%lg) < 0",NP); // modify condition to your needs // insert your code here A=l+2.*R; qR = q*R; ql = q*l; qA = q*A; mr=l/B; // number of monomers in rod-like segment ms=4.0*M_PI*gsl_pow_3(R)/(3.*NU); Mr=NP-1.0; if (qR==0.0) { Psi = 1; } else { Psi=3.*(sin(qR)-qR*cos(qR))/gsl_pow_3(qR); } if (ql == 0.0) { L=1.0; sinql2_ql2= 1.0; } else { L=gsl_sf_Si(ql)/(ql); sinql2_ql2 = sin(ql/2.0)*2/ql; } if (qA == 0.0) { sinqA_qA=1.; } else { sinqA_qA=sin(qA)/(qA); } if (q==0) { beta = 1.0; } else if (A==2*R) { if (R==0) { beta = 1; } else { beta = sin(q*R)/(q*R); } } else { beta=(gsl_sf_Si(q*(A-R))-gsl_sf_Si(qR))/(ql); } Sp=2*pow(ms,2)*pow(Psi,2)*((NP/(1-sinqA_qA))-(NP/2)-((1-pow(fabs(sinqA_qA),NP))/pow(1-sinqA_qA,2))*sinqA_qA); Sr=pow(mr,2)*(Mr*(2*L-pow(sinql2_ql2,2))+(2*Mr*pow(beta,2)/(1-sinqA_qA))- 2*pow(beta,2)*(1-pow(fabs(sinqA_qA),Mr))/pow(1-sinqA_qA,2)); Sm=mr*beta*ms*Psi*4*(((NP-1)/(1-sinqA_qA))-((1-pow(fabs(sinqA_qA),NP-1))/pow(1-sinqA_qA,2))*sinqA_qA); return (Sp+Sr+Sm)/pow(Mr*mr+NP*ms,2); }
scalar sasfit_ff_sphere_with_3_shells_v(scalar q, sasfit_param * param, int dist) { SASFIT_ASSERT_PTR(param); // assert pointer param is valid // insert your code here return 4./3. * M_PI * gsl_pow_3(R_CORE+T_SH1+T_SH2+T_SH3); }
int main(){ apop_opts.db_engine='s'; //SQLite only. apop_query("create table atab (a numeric)"); for (int i=0; i< 1e5; i++) apop_query("insert into atab values(ran())"); apop_query("create table powa as " "select a, pow(a, 2) as sq, pow(a, 0.5) as sqrt " "from atab"); //compare the std dev of a uniform as reported by the //database routine, the matrix routine, and math. double db_pop_stddev = apop_query_to_float("select stddev_pop(a) from powa"); apop_data *d = apop_query_to_data("select * from powa"); apop_data *cov = apop_data_covariance(d); double matrix_pop_stddev = sqrt(apop_data_get(cov)*(d->matrix->size1/(d->matrix->size1-1.))); assert(fabs(db_pop_stddev - matrix_pop_stddev) < 1e-4); double actual_stddev = sqrt(2*gsl_pow_3(.5)/3); assert(fabs(db_pop_stddev - actual_stddev) < 1e-3); float sq_mean = apop_query_to_float("select avg(sq) from powa"); float actual_sq_mean = 1./3; assert(fabs(sq_mean - actual_sq_mean) < 1e-3); float sqrt_mean = apop_query_to_float("select avg(sqrt) from powa"); float actual_sqrt_mean = 2./3; assert(fabs(sqrt_mean - actual_sqrt_mean) < 1e-3); }
scalar sasfit_ff_debye_anderson_brumberger(scalar q, sasfit_param * param) { SASFIT_ASSERT_PTR(param); // assert pointer param is valid SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((XI < 0.0), param, "xi(%lg) < 0",XI); // modify condition to your needs // insert your code here return gsl_pow_2(ETA*gsl_pow_3(XI*2)*M_PI)/gsl_pow_2(gsl_pow_2(q*XI)+1.0); }
void stats(std:: valarray<float> map, float &mean, float &sigma, float &kurt, float &skew) { float sum = map.sum(); int n = map.size(); mean = map.sum()/float(n); std:: valarray <float> maps(n); valarray<float> maps2(n),maps3(n),maps4(n); for(int i=0; i<n; i++) { maps2[i] = gsl_pow_2(map[i] - mean); maps3[i] = gsl_pow_3(map[i] - mean); maps4[i] = gsl_pow_4(map[i] - mean); } sum = maps2.sum(); sigma = sqrt(sum/(float(n)-1.)); sum = maps3.sum(); double mu3 = sum/(float(n)-1.); sum = maps4.sum(); double mu4 = sum/(float(n)-1.); kurt = mu4/gsl_pow_4(sigma) -3; skew = mu3/gsl_pow_3(sigma); }
double alpha1_doubleprime(double phi, void * mypars) { pars * my_pars = (pars *) mypars; my_pars->n = (int) round(phi); double v = (gsl_pow_2(my_pars->n) + gsl_pow_2(my_pars->h) ); double h = my_pars->h; double n = my_pars->n; double e = my_pars->e; double K = my_pars->K; return 2*e*h*h*K*(3*n*n-h*h)/gsl_pow_3(v); }
Real GreensFunction3DSym::p_r(Real r, Real t) const { const Real D( getD() ); const Real Dt( D * t ); const Real Dt4( 4.0 * Dt ); const Real Dt4Pi( Dt4 * M_PI ); const Real term1( 1.0 / sqrt( gsl_pow_3( Dt4Pi ) ) ); const Real term2( exp( - r * r / Dt4 ) ); const Real jacobian( 4.0 * r * r * M_PI ); return jacobian * term1 * term2; }
scalar sasfit_ff_ff_chain_parabolic_psi_mm(scalar q, sasfit_param * param) { scalar nn; SASFIT_ASSERT_PTR(param); // assert pointer param is valid SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((R_CORE < 0.0), param, "R_core(%lg) < 0",R_CORE); // modify condition to your needs SASFIT_CHECK_COND1((SNAGG < 0.0), param, "nagg(%lg) < 0",SNAGG); // modify condition to your needs SASFIT_CHECK_COND1((VBRUSH < 0.0), param, "Vbrush(%lg) < 0",VBRUSH); // modify condition to your needs SASFIT_CHECK_COND1((RG < 0.0), param, "Rg(%lg) < 0",RG); // modify condition to your needs SASFIT_CHECK_COND1((fabs(POL) > 1.0), param, "|pol|(%lg) > 1",POL); // modify condition to your needs // insert your code here RW_SAW = 2.0; RADAVG = 0.0; PEP = 0.0; if ((R_TOT-T_SHELL) > 0) { R_CORE=R_TOT-T_SHELL; T_SH = T_SHELL; } else { R_CORE = 0.0; T_SH = R_TOT; } if (R_TOT == 0.0) return 0.0; ALPHA_SH = 2.0/(3*M_PI); nn = 4*M_PI*gsl_pow_2(R_TOT)/SIGMA; I = nn*N*gsl_pow_3(A)/(4*M_PI); nn = SNAGG*4*M_PI*gsl_pow_2(R_TOT); I = VBRUSH * nn /(4*M_PI); C=ALPHA_SH/(P*gsl_pow_2(A*N)); // sasfit_out("q:%lf\n",q); LAMBDA = find_LAMBDA(param); // sasfit_out("LAMBDA: %f zmax: %f\n",LAMBDA,sqrt(LAMBDA/C)); PSI = sasfit_param_override_get_psi(PSIDEG*M_PI/180.); return FFmicelle_mm(q,param); return (1.0+POL)/2.0*(FFmicelle_pp(q,param)+FFmicelle_pm(q,param)) + (1.0-POL)/2.0*(FFmicelle_mm(q,param)+FFmicelle_mp(q,param)); }
void fit_params(void) { if (radius_tab[0] != 0.0) alpha = rlog10(density_tab[1] / density_tab[0]) / rlog10(radius_tab[1] / radius_tab[0]); else alpha = 0.0; beta = rlog10(density_tab[ntab-2] / density_tab[ntab-1]) / rlog10(radius_tab[ntab-2] / radius_tab[ntab-1]); if (beta > -3.0) error("%s: total mass diverges (beta = %f)\n", getprog(), beta); mtot = mass_tab[ntab-1] - (4 * M_PI / (3 + beta)) * gsl_pow_3(radius_tab[ntab-1]) * density_tab[ntab-1]; eprintf("[%s: alpha = %f beta = %f mtot = %f]\n", getprog(), alpha, beta, mtot); }
void setprof(int model, double alpha, double rcut) { int j; double r, x; rdtab[0] = mdtab[0] = vctab[0] = 0.0; for (j = 1; j < NTAB; j++) { r = rcut * pow(((double) j) / (NTAB - 1), 2.0); rdtab[j] = r; x = alpha * r; switch (model) { case -3: mdtab[j] = gsl_pow_4(r / rcut); break; case -2: mdtab[j] = gsl_pow_3(r / rcut); break; case -1: mdtab[j] = gsl_pow_2(r / rcut); break; case 0: mdtab[j] = 1 - exp(-x) - x * exp(-x); break; case 1: mdtab[j] = (2 - 2 * exp(-x) - (2*x + x*x) * exp(-x)) / 2; break; case 2: mdtab[j] = (6 - 6 * exp(-x) - (6*x + 3*x*x + x*x*x) * exp(-x)) / 6; break; default: error("%s: bad choice for model\n", getprog()); } vctab[j] = sqrt(gsp_mass(spheroid, r) / r); } if (model > -1) eprintf("[%s: rcut = %8.4f/alpha M(rcut) = %8.6f*mdisk]\n", getprog(), rdtab[NTAB-1] * alpha, mdtab[NTAB-1]); if ((mdtab[0] == mdtab[1]) || (mdtab[NTAB-2] == mdtab[NTAB-1])) error("%s: disk mass table is degenerate\n", getprog()); rm_spline = gsl_interp_alloc(gsl_interp_akima, NTAB); gsl_interp_init(rm_spline, mdtab, rdtab, NTAB); vr_spline = gsl_interp_alloc(gsl_interp_akima, NTAB); gsl_interp_init(vr_spline, rdtab, vctab, NTAB); }
/* Continued fraction which occurs in evaluation * of Q(a,x) or Gamma(a,x). * * 1 (1-a)/x 1/x (2-a)/x 2/x (3-a)/x * F(a,x) = ---- ------- ----- -------- ----- -------- ... * 1 + 1 + 1 + 1 + 1 + 1 + * * Hans E. Plesser, 2002-01-22 (hans dot plesser at itf dot nlh dot no). * * Split out from gamma_inc_Q_CF() by GJ [Tue Apr 1 13:16:41 MST 2003]. * See gamma_inc_Q_CF() below. * */ static int gamma_inc_F_CF(const double a, const double x, gsl_sf_result * result) { const int nmax = 5000; const double small = gsl_pow_3 (GSL_DBL_EPSILON); double hn = 1.0; /* convergent */ double Cn = 1.0 / small; double Dn = 1.0; int n; /* n == 1 has a_1, b_1, b_0 independent of a,x, so that has been done by hand */ for ( n = 2 ; n < nmax ; n++ ) { double an; double delta; if(GSL_IS_ODD(n)) an = 0.5*(n-1)/x; else an = (0.5*n-a)/x; Dn = 1.0 + an * Dn; if ( fabs(Dn) < small ) Dn = small; Cn = 1.0 + an/Cn; if ( fabs(Cn) < small ) Cn = small; Dn = 1.0 / Dn; delta = Cn * Dn; hn *= delta; if(fabs(delta-1.0) < GSL_DBL_EPSILON) break; } result->val = hn; result->err = 2.0*GSL_DBL_EPSILON * fabs(hn); result->err += GSL_DBL_EPSILON * (2.0 + 0.5*n) * fabs(result->val); if(n == nmax) GSL_ERROR ("error in CF for F(a,x)", GSL_EMAXITER); else return GSL_SUCCESS; }
static void _nc_transfer_func_bbks_prepare (NcTransferFunc *tf, NcHICosmo *cosmo) { NcTransferFuncBBKS *tf_bbks = NC_TRANSFER_FUNC_BBKS (tf); NcTransferFuncBBKSPrivate * const self = tf_bbks->priv; const gdouble T_0 = nc_hicosmo_T_gamma0 (cosmo); const gdouble c1 = 3.89; const gdouble c2 = gsl_pow_2 (16.1); const gdouble c3 = gsl_pow_3 (5.46); const gdouble c4 = gsl_pow_4 (6.71); const gdouble c5 = gsl_pow_2 (T_0 / 2.7); /* CMB: (T_0/2.7)^2 = (2.725/2.7)^2 */ const gdouble h = nc_hicosmo_h (cosmo); const gdouble h2 = h * h; const gdouble Ob = nc_hicosmo_Omega_b0 (cosmo); const gdouble Om = nc_hicosmo_Omega_m0 (cosmo); const gdouble wm = Om * h2; self->c1 = c1; self->c2 = c2; self->c3 = c3; self->c4 = c4; self->h = h; switch (self->type) { case NC_TRANSFER_FUNC_BBKS_TYPE_NOBARYONS: self->c5_wm = c5 / wm; break; case NC_TRANSFER_FUNC_BBKS_TYPE_BARYONS: self->c5_wm = (c5 / wm) / exp (- Ob - sqrt (2.0 * h) * Ob / Om); break; case NC_TRANSFER_FUNC_BBKS_TYPE_CCL: self->c5_wm = (1.0 / wm) / exp (- Ob - sqrt (2.0 * h) * Ob / Om); /* Check why they modify it like this, is it an typo? */ break; default: g_assert_not_reached (); break; } if (c5 == 0.0) g_warning ("_nc_transfer_func_bbks_prepare: no radiation universe, BBKS is not defined transfer function will be exaclty = 1."); }
double d2Nglasma0(double pT, double qT, double phipq, double yp, double yq, double rts) { static struct glasma_params params; params.pT = pT; params.qT = qT; params.yp = yp; params.yq = yq; params.rts = rts; params.phipq = phipq; phiIntKernel.function = &phiKernel; (params.Kernel).function = &doubleKernel; phiIntKernel.params = ¶ms; gsl_integration_qng(&phiIntKernel, -M_PI, M_PI, abserr, relerr,\ &result, &error, &neval); double norm = (Nc*Nc)/gsl_pow_3(Nc*Nc-1.)/(4.*pow(M_PI,10.))/gsl_pow_2(pT* qT)*alpha(pT)*alpha(qT); return norm*result; }
double d2Nglasma1(double pT, double yp, double yq, double rts) { double sinres, cosres; static struct glasma_params params; params.pT = pT; params.yp = yp; params.yq = yq; params.rts = rts; phiIntKernel.function = &phiKernel; (params.Kernel).function = &cosKernel; phiIntKernel.params = ¶ms; gsl_integration_qng(&phiIntKernel, -M_PI, M_PI, abserr, relerr, &cosres, &error, &neval); (params.Kernel).function = &sinKernel; phiIntKernel.params = ¶ms; gsl_integration_qng(&phiIntKernel, -M_PI, M_PI, abserr, relerr, &sinres, &error, &neval); double norm = (Nc*Nc)/gsl_pow_3(Nc*Nc-1.)/(4.*pow(M_PI,10.))/gsl_pow_2(pT*pT)*alpha(pT)*alpha(pT) ; return norm*(cosres*cosres + sinres*sinres); }
void integ_mass(bool update) { double *dmdr_tab = (double *) allocate(ntab * sizeof(double)); gsl_spline *spl_dmdr = gsl_spline_alloc(gsl_interp_cspline, ntab); gsl_interp_accel *acc_dmdr = gsl_interp_accel_alloc(); int i, stat; double alpha, mass_int, del_mass, mass_end = mass_tab[ntab - 1]; for (i = 0; i < ntab; i++) dmdr_tab[i] = 4 * M_PI * gsl_pow_2(radius_tab[i]) * density_tab[i]; gsl_spline_init(spl_dmdr, radius_tab, dmdr_tab, ntab); if (radius_tab[0] > 0.0) { alpha = rlog10(density_tab[1] / density_tab[0]) / rlog10(radius_tab[1] / radius_tab[0]); mass_int = (4 * M_PI / (alpha + 3)) * gsl_pow_3(radius_tab[0]) * density_tab[0]; } else mass_int = 0.0; if (update) mass_tab[0] = mass_int; for (i = 1; i < ntab; i++) { stat = gsl_spline_eval_integ_e(spl_dmdr, radius_tab[i-1], radius_tab[i], acc_dmdr, &del_mass); if (stat != 0) error("%s: spline error: %s\n", getprog(), gsl_strerror(stat)); mass_int = mass_int + del_mass; if (update) mass_tab[i] = mass_int; } gsl_interp_accel_free(acc_dmdr); gsl_spline_free(spl_dmdr); free(dmdr_tab); eprintf("[%s: mass[] = %e:%e]\n", getprog(), mass_tab[0], mass_tab[ntab - 1]); if (mass_int < 0.99 * mass_end || mass_int > 1.01 * mass_end) eprintf("[%s: WARNING: final mass = %e integ mass = %e]\n", getprog(), mass_end, mass_int); }
scalar sasfit_ff_beaucage_exppowlaw_2(scalar q, sasfit_param * param) { SASFIT_ASSERT_PTR(param); // assert pointer param is valid SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((G < 0.0), param, "G(%lg) < 0",G); // modify condition to your needs SASFIT_CHECK_COND1((B < 0.0), param, "B(%lg) < 0",B); // modify condition to your needs SASFIT_CHECK_COND1((R_I < 0.0), param, "R_i(%lg) < 0",R_I); // modify condition to your needs SASFIT_CHECK_COND1((R_Ip1 < 0.0), param, "R_i+1(%lg) < 0",R_Ip1); // modify condition to your needs SASFIT_CHECK_COND1((K < 0.0), param, "k(%lg) < 0",K); // modify condition to your needs SASFIT_CHECK_COND1((P < 0.0), param, "P(%lg) < 0",P); // modify condition to your needs // insert your code here scalar x, xs, tmp; x = q*R_I; xs = q*R_Ip1; tmp = gsl_pow_3( gsl_sf_erf(x *K /sqrt(6.)) ) / q; return G*exp(-x*x/3.0) + B*exp(-xs*xs/3.)*pow(tmp,P); }
int main (void) { double y, y_expected; int e, e_expected; gsl_ieee_env_setup (); /* Test for expm1 */ y = gsl_expm1 (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.0)"); y = gsl_expm1 (1e-10); y_expected = 1.000000000050000000002e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(1e-10)"); y = gsl_expm1 (-1e-10); y_expected = -9.999999999500000000017e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-1e-10)"); y = gsl_expm1 (0.1); y_expected = 0.1051709180756476248117078264902; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.1)"); y = gsl_expm1 (-0.1); y_expected = -0.09516258196404042683575094055356; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-0.1)"); y = gsl_expm1 (10.0); y_expected = 22025.465794806716516957900645284; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(10.0)"); y = gsl_expm1 (-10.0); y_expected = -0.99995460007023751514846440848444; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-10.0)"); /* Test for log1p */ y = gsl_log1p (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.0)"); y = gsl_log1p (1e-10); y_expected = 9.9999999995000000000333333333308e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(1e-10)"); y = gsl_log1p (0.1); y_expected = 0.095310179804324860043952123280765; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.1)"); y = gsl_log1p (10.0); y_expected = 2.3978952727983705440619435779651; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(10.0)"); /* Test for gsl_hypot */ y = gsl_hypot (0.0, 0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(0.0, 0.0)"); y = gsl_hypot (1e-10, 1e-10); y_expected = 1.414213562373095048801688e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, 1e-10)"); y = gsl_hypot (1e-38, 1e-38); y_expected = 1.414213562373095048801688e-38; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-38, 1e-38)"); y = gsl_hypot (1e-10, -1.0); y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, -1)"); y = gsl_hypot (-1.0, 1e-10); y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(-1, 1e-10)"); y = gsl_hypot (1e307, 1e301); y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e301)"); y = gsl_hypot (1e301, 1e307); y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e301, 1e307)"); y = gsl_hypot (1e307, 1e307); y_expected = 1.414213562373095048801688e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e307)"); /* Test +-Inf, finite */ y = gsl_hypot (GSL_POSINF, 1.2); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_POSINF, 1.2)"); y = gsl_hypot (GSL_NEGINF, 1.2); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NEGINF, 1.2)"); y = gsl_hypot (1.2, GSL_POSINF); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1.2, GSL_POSINF)"); y = gsl_hypot (1.2, GSL_NEGINF); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1.2, GSL_NEGINF)"); /* Test NaN, finite */ y = gsl_hypot (GSL_NAN, 1.2); y_expected = GSL_NAN; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, 1.2)"); y = gsl_hypot (1.2, GSL_NAN); y_expected = GSL_NAN; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1.2, GSL_NAN)"); /* Test NaN, NaN */ y = gsl_hypot (GSL_NAN, GSL_NAN); y_expected = GSL_NAN; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, GSL_NAN)"); /* Test +Inf, NaN */ y = gsl_hypot (GSL_POSINF, GSL_NAN); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_POSINF, GSL_NAN)"); /* Test -Inf, NaN */ y = gsl_hypot (GSL_NEGINF, GSL_NAN); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NEGINF, GSL_NAN)"); /* Test NaN, +Inf */ y = gsl_hypot (GSL_NAN, GSL_POSINF); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, GSL_POSINF)"); /* Test NaN, -Inf */ y = gsl_hypot (GSL_NAN, GSL_NEGINF); y_expected = GSL_POSINF; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, GSL_NEGINF)"); /* Test for gsl_hypot3 */ y = gsl_hypot3 (0.0, 0.0, 0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(0.0, 0.0, 0.0)"); y = gsl_hypot3 (1e-10, 1e-10, 1e-10); y_expected = 1.732050807568877293527446e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-10, 1e-10, 1e-10)"); y = gsl_hypot3 (1e-38, 1e-38, 1e-38); y_expected = 1.732050807568877293527446e-38; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-38, 1e-38, 1e-38)"); y = gsl_hypot3 (1e-10, 1e-10, -1.0); y_expected = 1.000000000000000000099; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-10, 1e-10, -1)"); y = gsl_hypot3 (1e-10, -1.0, 1e-10); y_expected = 1.000000000000000000099; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-10, -1, 1e-10)"); y = gsl_hypot3 (-1.0, 1e-10, 1e-10); y_expected = 1.000000000000000000099; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(-1, 1e-10, 1e-10)"); y = gsl_hypot3 (1e307, 1e301, 1e301); y_expected = 1.0000000000009999999999995e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e307, 1e301, 1e301)"); y = gsl_hypot3 (1e307, 1e307, 1e307); y_expected = 1.732050807568877293527446e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e307, 1e307, 1e307)"); y = gsl_hypot3 (1e307, 1e-307, 1e-307); y_expected = 1.0e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e307, 1e-307, 1e-307)"); /* Test for acosh */ y = gsl_acosh (1.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.0)"); y = gsl_acosh (1.1); y_expected = 4.435682543851151891329110663525e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.1)"); y = gsl_acosh (10.0); y_expected = 2.9932228461263808979126677137742e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(10.0)"); y = gsl_acosh (1e10); y_expected = 2.3718998110500402149594646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1e10)"); /* Test for asinh */ y = gsl_asinh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.0)"); y = gsl_asinh (1e-10); y_expected = 9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (-1e-10); y_expected = -9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (0.1); y_expected = 9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.1)"); y = gsl_asinh (-0.1); y_expected = -9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-0.1)"); y = gsl_asinh (1.0); y_expected = 8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1.0)"); y = gsl_asinh (-1.0); y_expected = -8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1.0)"); y = gsl_asinh (10.0); y_expected = 2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(10)"); y = gsl_asinh (-10.0); y_expected = -2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-10)"); y = gsl_asinh (1e10); y_expected = 2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e10)"); y = gsl_asinh (-1e10); y_expected = -2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1e10)"); /* Test for atanh */ y = gsl_atanh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.0)"); y = gsl_atanh (1e-20); y_expected = 1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(1e-20)"); y = gsl_atanh (-1e-20); y_expected = -1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-1e-20)"); y = gsl_atanh (0.1); y_expected = 1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.1)"); y = gsl_atanh (-0.1); y_expected = -1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-0.1)"); y = gsl_atanh (0.9); y_expected = 1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); y = gsl_atanh (-0.9); y_expected = -1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); /* Test for pow_int */ y = gsl_pow_2 (-3.14); y_expected = pow (-3.14, 2.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_2(-3.14)"); y = gsl_pow_3 (-3.14); y_expected = pow (-3.14, 3.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_3(-3.14)"); y = gsl_pow_4 (-3.14); y_expected = pow (-3.14, 4.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_4(-3.14)"); y = gsl_pow_5 (-3.14); y_expected = pow (-3.14, 5.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_5(-3.14)"); y = gsl_pow_6 (-3.14); y_expected = pow (-3.14, 6.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_6(-3.14)"); y = gsl_pow_7 (-3.14); y_expected = pow (-3.14, 7.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_7(-3.14)"); y = gsl_pow_8 (-3.14); y_expected = pow (-3.14, 8.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_8(-3.14)"); y = gsl_pow_9 (-3.14); y_expected = pow (-3.14, 9.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_9(-3.14)"); { int n; for (n = -9; n < 10; n++) { y = gsl_pow_int (-3.14, n); y_expected = pow (-3.14, n); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_int(-3.14,%d)", n); } } { unsigned int n; for (n = 0; n < 10; n++) { y = gsl_pow_uint (-3.14, n); y_expected = pow (-3.14, n); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_uint(-3.14,%d)", n); } } /* Test case for n at INT_MAX, INT_MIN */ { double u = 1.0000001; int n = INT_MAX; y = gsl_pow_int (u, n); y_expected = pow (u, n); gsl_test_rel (y, y_expected, 1e-6, "gsl_pow_int(%.7f,%d)", u, n); n = INT_MIN; y = gsl_pow_int (u, n); y_expected = pow (u, n); gsl_test_rel (y, y_expected, 1e-6, "gsl_pow_int(%.7f,%d)", u, n); } /* Test for ldexp */ y = gsl_ldexp (M_PI, -2); y_expected = M_PI_4; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(pi,-2)"); y = gsl_ldexp (1.0, 2); y_expected = 4.000000; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(1.0,2)"); y = gsl_ldexp (0.0, 2); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(0.0,2)"); y = gsl_ldexp (9.999999999999998890e-01, 1024); y_expected = GSL_DBL_MAX; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp DBL_MAX"); y = gsl_ldexp (1e308, -2000); y_expected = 8.7098098162172166755761e-295; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(1e308,-2000)"); y = gsl_ldexp (GSL_DBL_MIN, 2000); y_expected = 2.554675596204441378334779940e294; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(DBL_MIN,2000)"); /* Test subnormals */ { int i = 0; volatile double x = GSL_DBL_MIN; y_expected = 2.554675596204441378334779940e294; x /= 2; while (x > 0) { i++ ; y = gsl_ldexp (x, 2000 + i); gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(DBL_MIN/2**%d,%d)",i,2000+i); x /= 2; } } /* Test for frexp */ y = gsl_frexp (0.0, &e); y_expected = 0; e_expected = 0; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(0) exponent"); y = gsl_frexp (M_PI, &e); y_expected = M_PI_4; e_expected = 2; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(pi) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(pi) exponent"); y = gsl_frexp (2.0, &e); y_expected = 0.5; e_expected = 2; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(2.0) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(2.0) exponent"); y = gsl_frexp (1.0 / 4.0, &e); y_expected = 0.5; e_expected = -1; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0.25) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(0.25) exponent"); y = gsl_frexp (1.0 / 4.0 - 4.0 * GSL_DBL_EPSILON, &e); y_expected = 0.999999999999996447; e_expected = -2; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0.25-eps) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(0.25-eps) exponent"); y = gsl_frexp (GSL_DBL_MAX, &e); y_expected = 9.999999999999998890e-01; e_expected = 1024; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(DBL_MAX) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(DBL_MAX) exponent"); y = gsl_frexp (-GSL_DBL_MAX, &e); y_expected = -9.999999999999998890e-01; e_expected = 1024; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(-DBL_MAX) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(-DBL_MAX) exponent"); y = gsl_frexp (GSL_DBL_MIN, &e); y_expected = 0.5; e_expected = -1021; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(DBL_MIN) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(DBL_MIN) exponent"); y = gsl_frexp (-GSL_DBL_MIN, &e); y_expected = -0.5; e_expected = -1021; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(-DBL_MIN) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(-DBL_MIN) exponent"); /* Test subnormals */ { int i = 0; volatile double x = GSL_DBL_MIN; y_expected = 0.5; e_expected = -1021; x /= 2; while (x > 0) { e_expected--; i++ ; y = gsl_frexp (x, &e); gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(DBL_MIN/2**%d) fraction",i); gsl_test_int (e, e_expected, "gsl_frexp(DBL_MIN/2**%d) exponent", i); x /= 2; } } /* Test for approximate floating point comparison */ { double x, y; int i; x = M_PI; y = 22.0 / 7.0; /* test the basic function */ for (i = 0; i < 10; i++) { double tol = pow (10, -i); int res = gsl_fcmp (x, y, tol); gsl_test_int (res, -(i >= 4), "gsl_fcmp(%.5f,%.5f,%g)", x, y, tol); } for (i = 0; i < 10; i++) { double tol = pow (10, -i); int res = gsl_fcmp (y, x, tol); gsl_test_int (res, (i >= 4), "gsl_fcmp(%.5f,%.5f,%g)", y, x, tol); } } #if HAVE_IEEE_COMPARISONS /* Test for isinf, isnan, finite */ { double zero, one, inf, nan; int s; zero = 0.0; one = 1.0; inf = exp (1.0e10); nan = inf / inf; s = gsl_isinf (zero); gsl_test_int (s, 0, "gsl_isinf(0)"); s = gsl_isinf (one); gsl_test_int (s, 0, "gsl_isinf(1)"); s = gsl_isinf (inf); gsl_test_int (s, 1, "gsl_isinf(inf)"); s = gsl_isinf (-inf); gsl_test_int (s, -1, "gsl_isinf(-inf)"); s = gsl_isinf (nan); gsl_test_int (s, 0, "gsl_isinf(nan)"); s = gsl_isnan (zero); gsl_test_int (s, 0, "gsl_isnan(0)"); s = gsl_isnan (one); gsl_test_int (s, 0, "gsl_isnan(1)"); s = gsl_isnan (inf); gsl_test_int (s, 0, "gsl_isnan(inf)"); s = gsl_isnan (-inf); gsl_test_int (s, 0, "gsl_isnan(-inf)"); s = gsl_isnan (nan); gsl_test_int (s, 1, "gsl_isnan(nan)"); s = gsl_finite (zero); gsl_test_int (s, 1, "gsl_finite(0)"); s = gsl_finite (one); gsl_test_int (s, 1, "gsl_finite(1)"); s = gsl_finite (inf); gsl_test_int (s, 0, "gsl_finite(inf)"); s = gsl_finite (-inf); gsl_test_int (s, 0, "gsl_finite(-inf)"); s = gsl_finite (nan); gsl_test_int (s, 0, "gsl_finite(nan)"); } #endif { double x = gsl_fdiv (2.0, 3.0); gsl_test_rel (x, 2.0 / 3.0, 4 * GSL_DBL_EPSILON, "gsl_fdiv(2,3)"); } /* Test constants in gsl_math.h */ { double x = log(M_E); gsl_test_rel (x, 1.0, 4 * GSL_DBL_EPSILON, "ln(M_E)"); } { double x=pow(2.0,M_LOG2E); gsl_test_rel (x, exp(1.0), 4 * GSL_DBL_EPSILON, "2^M_LOG2E"); } { double x=pow(10.0,M_LOG10E); gsl_test_rel (x, exp(1.0), 4 * GSL_DBL_EPSILON, "10^M_LOG10E"); } { double x=pow(M_SQRT2, 2.0); gsl_test_rel (x, 2.0, 4 * GSL_DBL_EPSILON, "M_SQRT2^2"); } { double x=pow(M_SQRT1_2, 2.0); gsl_test_rel (x, 1.0/2.0, 4 * GSL_DBL_EPSILON, "M_SQRT1_2"); } { double x=pow(M_SQRT3, 2.0); gsl_test_rel (x, 3.0, 4 * GSL_DBL_EPSILON, "M_SQRT3^2"); } { double x = M_PI; gsl_test_rel (x, 3.1415926535897932384626433832795, 4 * GSL_DBL_EPSILON, "M_PI"); } { double x = 2 * M_PI_2; gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "2*M_PI_2"); } { double x = 4 * M_PI_4; gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "4*M_PI_4"); } { double x = pow(M_SQRTPI, 2.0); gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "M_SQRTPI^2"); } { double x = pow(M_2_SQRTPI, 2.0); gsl_test_rel (x, 4/M_PI, 4 * GSL_DBL_EPSILON, "M_SQRTPI^2"); } { double x = M_1_PI; gsl_test_rel (x, 1/M_PI, 4 * GSL_DBL_EPSILON, "M_1_SQRTPI"); } { double x = M_2_PI; gsl_test_rel (x, 2.0/M_PI, 4 * GSL_DBL_EPSILON, "M_2_PI"); } { double x = exp(M_LN10); gsl_test_rel (x, 10, 4 * GSL_DBL_EPSILON, "exp(M_LN10)"); } { double x = exp(M_LN2); gsl_test_rel (x, 2, 4 * GSL_DBL_EPSILON, "exp(M_LN2)"); } { double x = exp(M_LNPI); gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "exp(M_LNPI)"); } { double x = M_EULER; gsl_test_rel (x, 0.5772156649015328606065120900824, 4 * GSL_DBL_EPSILON, "M_EULER"); } exit (gsl_test_summary ()); }
int main (void) { double y, y_expected; gsl_ieee_env_setup (); /* Test for expm1 */ y = gsl_expm1 (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.0)"); y = gsl_expm1 (1e-10); y_expected = 1.000000000050000000002e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(1e-10)"); y = gsl_expm1 (-1e-10); y_expected = -9.999999999500000000017e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-1e-10)"); y = gsl_expm1 (0.1); y_expected = 0.1051709180756476248117078264902; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.1)"); y = gsl_expm1 (-0.1); y_expected = -0.09516258196404042683575094055356; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-0.1)"); y = gsl_expm1 (10.0); y_expected = 22025.465794806716516957900645284; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(10.0)"); y = gsl_expm1 (-10.0); y_expected = -0.99995460007023751514846440848444; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-10.0)"); /* Test for log1p */ y = gsl_log1p (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.0)"); y = gsl_log1p (1e-10); y_expected = 9.9999999995000000000333333333308e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(1e-10)"); y = gsl_log1p (0.1); y_expected = 0.095310179804324860043952123280765; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.1)"); y = gsl_log1p (10.0); y_expected = 2.3978952727983705440619435779651; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(10.0)"); /* Test for gsl_hypot */ y = gsl_hypot (0.0, 0.0) ; y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(0.0, 0.0)"); y = gsl_hypot (1e-10, 1e-10) ; y_expected = 1.414213562373095048801688e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, 1e-10)"); y = gsl_hypot (1e-38, 1e-38) ; y_expected = 1.414213562373095048801688e-38; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-38, 1e-38)"); y = gsl_hypot (1e-10, -1.0) ; y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, -1)"); y = gsl_hypot (-1.0, 1e-10) ; y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(-1, 1e-10)"); y = gsl_hypot (1e307, 1e301) ; y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e301)"); y = gsl_hypot (1e301, 1e307) ; y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e301, 1e307)"); y = gsl_hypot (1e307, 1e307) ; y_expected = 1.414213562373095048801688e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e307)"); /* Test for acosh */ y = gsl_acosh (1.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.0)"); y = gsl_acosh (1.1); y_expected = 4.435682543851151891329110663525e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.1)"); y = gsl_acosh (10.0); y_expected = 2.9932228461263808979126677137742e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(10.0)"); y = gsl_acosh (1e10); y_expected = 2.3718998110500402149594646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1e10)"); /* Test for asinh */ y = gsl_asinh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.0)"); y = gsl_asinh (1e-10); y_expected = 9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (-1e-10); y_expected = -9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (0.1); y_expected = 9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.1)"); y = gsl_asinh (-0.1); y_expected = -9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-0.1)"); y = gsl_asinh (1.0); y_expected = 8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1.0)"); y = gsl_asinh (-1.0); y_expected = -8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1.0)"); y = gsl_asinh (10.0); y_expected = 2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(10)"); y = gsl_asinh (-10.0); y_expected = -2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-10)"); y = gsl_asinh (1e10); y_expected = 2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e10)"); y = gsl_asinh (-1e10); y_expected = -2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1e10)"); /* Test for atanh */ y = gsl_atanh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.0)"); y = gsl_atanh (1e-20); y_expected = 1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(1e-20)"); y = gsl_atanh (-1e-20); y_expected = -1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-1e-20)"); y = gsl_atanh (0.1); y_expected = 1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.1)"); y = gsl_atanh (-0.1); y_expected = -1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-0.1)"); y = gsl_atanh (0.9); y_expected = 1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); y = gsl_atanh (-0.9); y_expected = -1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); /* Test for pow_int */ y = gsl_pow_2 (-3.14); y_expected = pow(-3.14, 2.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_2(-3.14)"); y = gsl_pow_3 (-3.14); y_expected = pow(-3.14, 3.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_3(-3.14)"); y = gsl_pow_4 (-3.14); y_expected = pow(-3.14, 4.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_4(-3.14)"); y = gsl_pow_5 (-3.14); y_expected = pow(-3.14, 5.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_5(-3.14)"); y = gsl_pow_6 (-3.14); y_expected = pow(-3.14, 6.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_6(-3.14)"); y = gsl_pow_7 (-3.14); y_expected = pow(-3.14, 7.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_7(-3.14)"); y = gsl_pow_8 (-3.14); y_expected = pow(-3.14, 8.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_8(-3.14)"); y = gsl_pow_9 (-3.14); y_expected = pow(-3.14, 9.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_9(-3.14)"); { int n; for (n = -9; n < 10; n++) { y = gsl_pow_int (-3.14, n); y_expected = pow(-3.14, n); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_n(-3.14,%d)", n); } } /* Test for isinf, isnan, finite*/ { double zero, one, inf, nan; int s; zero = 0.0; one = 1.0; inf = exp(1.0e10); nan = inf / inf; s = gsl_isinf(zero); gsl_test_int (s, 0, "gsl_isinf(0)"); s = gsl_isinf(one); gsl_test_int (s, 0, "gsl_isinf(1)"); s = gsl_isinf(inf); gsl_test_int (s, 1, "gsl_isinf(inf)"); s = gsl_isinf(-inf); gsl_test_int (s, -1, "gsl_isinf(-inf)"); s = gsl_isinf(nan); gsl_test_int (s, 0, "gsl_isinf(nan)"); s = gsl_isnan(zero); gsl_test_int (s, 0, "gsl_isnan(0)"); s = gsl_isnan(one); gsl_test_int (s, 0, "gsl_isnan(1)"); s = gsl_isnan(inf); gsl_test_int (s, 0, "gsl_isnan(inf)"); s = gsl_isnan(nan); gsl_test_int (s, 1, "gsl_isnan(nan)"); s = gsl_finite(zero); gsl_test_int (s, 1, "gsl_finite(0)"); s = gsl_finite(one); gsl_test_int (s, 1, "gsl_finite(1)"); s = gsl_finite(inf); gsl_test_int (s, 0, "gsl_finite(inf)"); s = gsl_finite(nan); gsl_test_int (s, 0, "gsl_finite(nan)"); } { double x = gsl_fdiv (2.0, 3.0); gsl_test_rel (x, 2.0/3.0, 4*GSL_DBL_EPSILON, "gsl_fdiv(2,3)"); } exit (gsl_test_summary ()); }
inline double pow_3(const double x) { return gsl_pow_3(x); }
scalar sasfit_sd_lognorm_fp(scalar q, sasfit_param * param) { scalar R, DeltaR, L; scalar c, N, LNf; SASFIT_ASSERT_PTR(param); // assert pointer param is valid SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((FP < 0.0), param, "fp(%lg) < 0",FP); // modify condition to your needs SASFIT_CHECK_COND1((SIGMA < 0.0), param, "sigma(%lg) < 0",SIGMA); // modify condition to your needs SASFIT_CHECK_COND1((MU < 0.0), param, "mu(%lg) < 0",MU); // modify condition to your needs SASFIT_CHECK_COND1((LENGTH2 < 0.0), param, "length2(%lg) < 0",LENGTH2); // modify condition to your needs SASFIT_CHECK_COND1((LENGTH3 < 0.0), param, "length3(%lg) < 0",LENGTH3); // modify condition to your needs SASFIT_CHECK_COND1((SHAPE < 0.0), param, "shape(%lg) < 0",SHAPE); // modify condition to your needs // insert your code here if (q == 0.0) return 0.0; c = 1.0/sqrt(M_PI*2.0)/SIGMA/pow(MU,1.0-P) / exp(0.5*pow(SIGMA*(1.0-P),2.0)); switch ((int) SHAPE) { case 1: N = FP*1e-21*3./(4.*M_PI * X(3,param)); break; case 2: L = LENGTH2; N = FP*1e-21 / (M_PI*X(2,param)*L); break; case 3: R = LENGTH2; N = FP*1e-21 / (M_PI*X(1,param)*gsl_pow_2(R)); break; case 4: DeltaR = LENGTH2; N = FP*1e-21/(4.*M_PI* ( X(3,param)/3. +X(2,param)*DeltaR +X(1,param)*gsl_pow_2(DeltaR) +X(0,param)*gsl_pow_3(DeltaR)/3. ) ); break; case 5: R = LENGTH2; N = FP*1e-21/(4.*M_PI* ( gsl_pow_3(R)*X(0,param)/3. + gsl_pow_2(R)*X(1,param) + R *X(2,param) + X(3,param)/3. ) ); break; case 6: DeltaR = LENGTH2; N = FP*1e-21/(4.*M_PI*X(3,param)/3.); break; case 7: R = LENGTH2; N = FP*1e-21/(4.*M_PI*gsl_pow_3(R)*X(0,param)/3.); break; case 8: DeltaR = LENGTH2; N = FP*1e-21 / (4.*M_PI* ( X(2,param)*DeltaR +X(1,param)*gsl_pow_2(DeltaR) +X(0,param)*gsl_pow_3(DeltaR)/3. ) ); break; case 9: R = LENGTH2; N = FP*1e-21 / (4.*M_PI* ( gsl_pow_2(R)*X(1,param) + R *X(2,param) + X(3,param)/3. ) ); break; case 10: DeltaR = LENGTH2; L = LENGTH3; N = FP*1e-21/(M_PI* L*( X(2,param) + X(1,param)*2. *DeltaR + X(0,param)*gsl_pow_2(DeltaR) ) ); break; case 11: R = LENGTH2; L = LENGTH3; N = FP*1e-21/(M_PI* L*( gsl_pow_2(R) *X(0,param) + R * 2.*X(1,param) + X(2,param) ) ); break; case 12: R = LENGTH2; DeltaR = LENGTH3; N = FP*1e-21/(M_PI* ( gsl_pow_2(R) + 2*R*DeltaR + gsl_pow_2(DeltaR) ) * X(1,param) ); break; case 13: DeltaR = LENGTH2; L = LENGTH3; N = FP*1e-21/(M_PI* X(2,param) * L); break; case 14: R = LENGTH2; L = LENGTH3; N = FP*1e-21/(M_PI* gsl_pow_2(R) * X(2,param) * L); break; case 15: R = LENGTH2; DeltaR = LENGTH3; N = FP*1e-21/(M_PI* gsl_pow_2(R) * X(1,param) ); break; case 16: DeltaR = LENGTH2; L = LENGTH3; N = FP*1e-21/(M_PI* L* ( gsl_pow_2(DeltaR)*X(0,param) +2*DeltaR *X(1,param) ) ); break; case 17: R = LENGTH2; L = LENGTH3; N = FP*1e-21/(M_PI* L* ( X(2,param) +2*R*X(1,param) ) ); break; case 18: R = LENGTH2; DeltaR = LENGTH3; N = FP*1e-21/(M_PI* X(1,param)* ( gsl_pow_2(DeltaR) +2*DeltaR*R ) ); break; default: N=FP; } LNf = N*c* pow(q,-P) * exp(-0.5*gsl_pow_2(log(q/MU)/SIGMA)); return LNf; return 0.0; }
int main (void) { double y, y_expected; int e, e_expected; gsl_ieee_env_setup (); /* Test for expm1 */ y = gsl_expm1 (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.0)"); y = gsl_expm1 (1e-10); y_expected = 1.000000000050000000002e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(1e-10)"); y = gsl_expm1 (-1e-10); y_expected = -9.999999999500000000017e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-1e-10)"); y = gsl_expm1 (0.1); y_expected = 0.1051709180756476248117078264902; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.1)"); y = gsl_expm1 (-0.1); y_expected = -0.09516258196404042683575094055356; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-0.1)"); y = gsl_expm1 (10.0); y_expected = 22025.465794806716516957900645284; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(10.0)"); y = gsl_expm1 (-10.0); y_expected = -0.99995460007023751514846440848444; gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-10.0)"); /* Test for log1p */ y = gsl_log1p (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.0)"); y = gsl_log1p (1e-10); y_expected = 9.9999999995000000000333333333308e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(1e-10)"); y = gsl_log1p (0.1); y_expected = 0.095310179804324860043952123280765; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.1)"); y = gsl_log1p (10.0); y_expected = 2.3978952727983705440619435779651; gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(10.0)"); /* Test for gsl_hypot */ y = gsl_hypot (0.0, 0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(0.0, 0.0)"); y = gsl_hypot (1e-10, 1e-10); y_expected = 1.414213562373095048801688e-10; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, 1e-10)"); y = gsl_hypot (1e-38, 1e-38); y_expected = 1.414213562373095048801688e-38; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-38, 1e-38)"); y = gsl_hypot (1e-10, -1.0); y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, -1)"); y = gsl_hypot (-1.0, 1e-10); y_expected = 1.000000000000000000005; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(-1, 1e-10)"); y = gsl_hypot (1e307, 1e301); y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e301)"); y = gsl_hypot (1e301, 1e307); y_expected = 1.000000000000499999999999e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e301, 1e307)"); y = gsl_hypot (1e307, 1e307); y_expected = 1.414213562373095048801688e307; gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e307)"); /* Test for acosh */ y = gsl_acosh (1.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.0)"); y = gsl_acosh (1.1); y_expected = 4.435682543851151891329110663525e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.1)"); y = gsl_acosh (10.0); y_expected = 2.9932228461263808979126677137742e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(10.0)"); y = gsl_acosh (1e10); y_expected = 2.3718998110500402149594646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1e10)"); /* Test for asinh */ y = gsl_asinh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.0)"); y = gsl_asinh (1e-10); y_expected = 9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (-1e-10); y_expected = -9.9999999999999999999833333333346e-11; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)"); y = gsl_asinh (0.1); y_expected = 9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.1)"); y = gsl_asinh (-0.1); y_expected = -9.983407889920756332730312470477e-2; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-0.1)"); y = gsl_asinh (1.0); y_expected = 8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1.0)"); y = gsl_asinh (-1.0); y_expected = -8.8137358701954302523260932497979e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1.0)"); y = gsl_asinh (10.0); y_expected = 2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(10)"); y = gsl_asinh (-10.0); y_expected = -2.9982229502979697388465955375965e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-10)"); y = gsl_asinh (1e10); y_expected = 2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e10)"); y = gsl_asinh (-1e10); y_expected = -2.3718998110500402149599646668302e1; gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1e10)"); /* Test for atanh */ y = gsl_atanh (0.0); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.0)"); y = gsl_atanh (1e-20); y_expected = 1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(1e-20)"); y = gsl_atanh (-1e-20); y_expected = -1e-20; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-1e-20)"); y = gsl_atanh (0.1); y_expected = 1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.1)"); y = gsl_atanh (-0.1); y_expected = -1.0033534773107558063572655206004e-1; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-0.1)"); y = gsl_atanh (0.9); y_expected = 1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); y = gsl_atanh (-0.9); y_expected = -1.4722194895832202300045137159439e0; gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)"); /* Test for pow_int */ y = gsl_pow_2 (-3.14); y_expected = pow (-3.14, 2.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_2(-3.14)"); y = gsl_pow_3 (-3.14); y_expected = pow (-3.14, 3.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_3(-3.14)"); y = gsl_pow_4 (-3.14); y_expected = pow (-3.14, 4.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_4(-3.14)"); y = gsl_pow_5 (-3.14); y_expected = pow (-3.14, 5.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_5(-3.14)"); y = gsl_pow_6 (-3.14); y_expected = pow (-3.14, 6.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_6(-3.14)"); y = gsl_pow_7 (-3.14); y_expected = pow (-3.14, 7.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_7(-3.14)"); y = gsl_pow_8 (-3.14); y_expected = pow (-3.14, 8.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_8(-3.14)"); y = gsl_pow_9 (-3.14); y_expected = pow (-3.14, 9.0); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_9(-3.14)"); { int n; for (n = -9; n < 10; n++) { y = gsl_pow_int (-3.14, n); y_expected = pow (-3.14, n); gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_n(-3.14,%d)", n); } } /* Test for ldexp */ y = gsl_ldexp (M_PI, -2); y_expected = M_PI_4; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(pi,-2)"); y = gsl_ldexp (1.0, 2); y_expected = 4.000000; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(1.0,2)"); y = gsl_ldexp (0.0, 2); y_expected = 0.0; gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(0.0,2)"); /* Test for frexp */ y = gsl_frexp (M_PI, &e); y_expected = M_PI_4; e_expected = 2; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(pi) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(pi) exponent"); y = gsl_frexp (2.0, &e); y_expected = 0.5; e_expected = 2; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(2.0) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(2.0) exponent"); y = gsl_frexp (1.0 / 4.0, &e); y_expected = 0.5; e_expected = -1; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0.25) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(0.25) exponent"); y = gsl_frexp (1.0 / 4.0 - 4.0 * GSL_DBL_EPSILON, &e); y_expected = 0.999999999999996447; e_expected = -2; gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0.25-eps) fraction"); gsl_test_int (e, e_expected, "gsl_frexp(0.25-eps) exponent"); /* Test for approximate floating point comparison */ { double x, y; int i; x = M_PI; y = 22.0 / 7.0; /* test the basic function */ for (i = 0; i < 10; i++) { double tol = pow (10, -i); int res = gsl_fcmp (x, y, tol); gsl_test_int (res, -(i >= 4), "gsl_fcmp(%.5f,%.5f,%g)", x, y, tol); } for (i = 0; i < 10; i++) { double tol = pow (10, -i); int res = gsl_fcmp (y, x, tol); gsl_test_int (res, (i >= 4), "gsl_fcmp(%.5f,%.5f,%g)", y, x, tol); } } #if HAVE_IEEE_COMPARISONS /* Test for isinf, isnan, finite */ { double zero, one, inf, nan; int s; zero = 0.0; one = 1.0; inf = exp (1.0e10); nan = inf / inf; s = gsl_isinf (zero); gsl_test_int (s, 0, "gsl_isinf(0)"); s = gsl_isinf (one); gsl_test_int (s, 0, "gsl_isinf(1)"); s = gsl_isinf (inf); gsl_test_int (s, 1, "gsl_isinf(inf)"); s = gsl_isinf (-inf); gsl_test_int (s, -1, "gsl_isinf(-inf)"); s = gsl_isinf (nan); gsl_test_int (s, 0, "gsl_isinf(nan)"); s = gsl_isnan (zero); gsl_test_int (s, 0, "gsl_isnan(0)"); s = gsl_isnan (one); gsl_test_int (s, 0, "gsl_isnan(1)"); s = gsl_isnan (inf); gsl_test_int (s, 0, "gsl_isnan(inf)"); s = gsl_isnan (nan); gsl_test_int (s, 1, "gsl_isnan(nan)"); s = gsl_finite (zero); gsl_test_int (s, 1, "gsl_finite(0)"); s = gsl_finite (one); gsl_test_int (s, 1, "gsl_finite(1)"); s = gsl_finite (inf); gsl_test_int (s, 0, "gsl_finite(inf)"); s = gsl_finite (nan); gsl_test_int (s, 0, "gsl_finite(nan)"); } #endif { double x = gsl_fdiv (2.0, 3.0); gsl_test_rel (x, 2.0 / 3.0, 4 * GSL_DBL_EPSILON, "gsl_fdiv(2,3)"); } exit (gsl_test_summary ()); }