long double coshl(long double x) { union ldshape u = {x}; unsigned ex = u.i.se & 0x7fff; uint32_t w; long double t; /* |x| */ u.i.se = ex; x = u.f; w = u.i.m >> 32; /* |x| < log(2) */ if (ex < 0x3fff-1 || (ex == 0x3fff-1 && w < 0xb17217f7)) { if (ex < 0x3fff-32) { FORCE_EVAL(x + 0x1p120f); return 1; } t = expm1l(x); return 1 + t*t/(2*(1+t)); } /* |x| < log(LDBL_MAX) */ if (ex < 0x3fff+13 || (ex == 0x3fff+13 && w < 0xb17217f7)) { t = expl(x); return 0.5*(t + 1/t); } /* |x| > log(LDBL_MAX) or nan */ t = expl(0.5*x); return 0.5*t*t; }
int main() { long double Cx; long double l; // setup dC = CxMax - CxMin; dl = lMax - lMin; step_l = dl/iPixelsNumber; eMin = expl(lMin); // = expl(lMin); // 0.0 < eMin < 1.0 eMax = expl(lMax); // 1.0 de = eMax - eMin; // go along real axis from CxMin to CxMax using nonlinear scale l = lMin; Cx = GiveC(l); printf("c = %.20Lf \n",Cx); while (l<lMax) { // info message Cx = GiveC(l); printf("c = %.20Lf \n",Cx); // next point l += step_l; } printf("nonlinear scale \n" ); return 0; }
long double get_probability_of_success(int t_f, int t_r, int l, int q_min, int q_max) { long double lambda_t=(q_max-q_min) * (long double)t_r/l; // std::cout << "lambda_t: " << lambda_t << "\n"; double r_t = 2 * (long double)t_f/l * (1-expl(-lambda_t)); long double p_t = 1-expl(-r_t); return p_t; }
//////////////////////////////////////////////////////////////////////////////// // static long double Argument_Addition_Series_Ei(long double x) // // // // Description: // // For 6.8 < x < 50.0, the argument addition series is used to calculate // // Ei. // // // // The argument addition series for Ei(x) is: // // Ei(x+dx) = Ei(x) + exp(x) Sum j! [exp(j) expj(-dx) - 1] / x^(j+1), // // where the Sum extends from j = 0 to inf, |x| > |dx| and expj(y) is // // the exponential polynomial expj(y) = Sum y^k / k!, the Sum extending // // from k = 0 to k = j. // // // // Arguments: // // long double x // // The argument of the exponential integral Ei(). // // // // Return Value: // // The value of the exponential integral Ei evaluated at x. // //////////////////////////////////////////////////////////////////////////////// static long double Argument_Addition_Series_Ei(long double x) { static long double ei[] = { 1.915047433355013959531e2L, 4.403798995348382689974e2L, 1.037878290717089587658e3L, 2.492228976241877759138e3L, 6.071406374098611507965e3L, 1.495953266639752885229e4L, 3.719768849068903560439e4L, 9.319251363396537129882e4L, 2.349558524907683035782e5L, 5.955609986708370018502e5L, 1.516637894042516884433e6L, 3.877904330597443502996e6L, 9.950907251046844760026e6L, 2.561565266405658882048e7L, 6.612718635548492136250e7L, 1.711446713003636684975e8L, 4.439663698302712208698e8L, 1.154115391849182948287e9L, 3.005950906525548689841e9L, 7.842940991898186370453e9L, 2.049649711988081236484e10L, 5.364511859231469415605e10L, 1.405991957584069047340e11L, 3.689732094072741970640e11L, 9.694555759683939661662e11L, 2.550043566357786926147e12L, 6.714640184076497558707e12L, 1.769803724411626854310e13L, 4.669055014466159544500e13L, 1.232852079912097685431e14L, 3.257988998672263996790e14L, 8.616388199965786544948e14L, 2.280446200301902595341e15L, 6.039718263611241578359e15L, 1.600664914324504111070e16L, 4.244796092136850759368e16L, 1.126348290166966760275e17L, 2.990444718632336675058e17L, 7.943916035704453771510e17L, 2.111342388647824195000e18L, 5.614329680810343111535e18L, 1.493630213112993142255e19L, 3.975442747903744836007e19L, 1.058563689713169096306e20L }; int k = (int) (x + 0.5); int j = 0; long double xx = (long double) k; long double dx = x - xx; long double xxj = xx; long double edx = expl(dx); long double Sm = 1.0L; long double Sn = (edx - 1.0L) / xxj; long double term = DBL_MAX; long double factorial = 1.0L; long double dxj = 1.0L; while (fabsl(term) > epsilon * fabsl(Sn) ) { j++; factorial *= (long double) j; xxj *= xx; dxj *= (-dx); Sm += (dxj / factorial); term = ( factorial * (edx * Sm - 1.0L) ) / xxj; Sn += term; } return ei[k-7] + Sn * expl(xx); }
//Taken from mathworld and wikipidia long double dB(long double x) { long double ret; if (fabsl(x)>1e-40) { ret=(expl(x)-1.0-x*expl(x))/(expl(x)-1)/(expl(x)-1); } else { ret= -1.0/2.0+x/6.0-powl(x,3.0)/180.0+powl(x,5.0)/5040; } return ret; }
// constructor for the case treatment and control Pvalues::Pvalues(int length, int q_min, int q_max, int t_f, int t_r, int c_f, int c_r) { n=2*q_max; has_control=true; // calculate probility of success for treatment and control // -------------------------------------------------------- long double lambda_t = (q_max-q_min) * (t_r/(long double)length); long double rate_t = (t_f/(long double)length) * (1-expl(-lambda_t)); p_t = 1 - exp(-rate_t*2); long double lambda_c = (q_max-q_min) * (c_r/(long double)length); long double rate_c = (c_f/(long double)length) * (1-expl(-lambda_c)); p_c = 1 - exp(-rate_c*2); // init binomial distribution // -------------------------- boost::math::binomial_distribution<long double> BinomialTreatment(n,p_t); boost::math::binomial_distribution<long double> BinomialControl(n,p_c); // init p-values from -n to n // -------------------------- std::map<int, long double> DiffBinom; for(int d=-n;d<=n;d++) { for(int k=0;k<=(n-abs(d));k++) { if(0<=d) { DiffBinom[d]=DiffBinom[d]+pdf(BinomialTreatment,(k+abs(d)))*pdf(BinomialControl,k); } else { DiffBinom[d]=DiffBinom[d]+pdf(BinomialControl,k+abs(d))*pdf(BinomialTreatment,k); } } } long double pval=0; for(int d=n;d>=-n;d--) { pval=pval+DiffBinom[d]; p_values[d]=pval; p_values_10log[d]=-log10l(pval); } }
long double logl(long double x) { long double y, y_old, ey, epsilon; y = 0.0; y_old = 1.0; epsilon = 1e-6; //fixme while (y > y_old + epsilon || y < y_old - epsilon) { y_old = y; ey = expl(y); y -= (ey - x) / ey; if (y > 700.0) { y = 700.0; } if (y < -700.0) { y = -700.0; } } if (y == 700.0) { return INFINITY; } if (y == -700.0) { return INFINITY; } return y; }
static long double P(long double mu, long double sigma, long double x) { long double tmp = 1 / (sigma * sqrtl(2.0 * M_PIl)); long double up = -powl(x-mu, 2) / (2 * powl(sigma, 2)); tmp *= expl(up); return tmp; }
long double factorial(int num) { assert( num > -1); if (num == 0) return 1; // definition of 0! long double result = 0.0;//log(1); for (int i = 1; i <= num; i++) result = result + logl((long double) i); return expl(result); }
void test_exp() { static_assert((std::is_same<decltype(exp((double)0)), double>::value), ""); static_assert((std::is_same<decltype(expf(0)), float>::value), ""); static_assert((std::is_same<decltype(expl(0)), long double>::value), ""); assert(exp(0) == 1); }
long double log_gamma(double N) { const long double SQRT2PI = sqrtl(atanl(1.0) * 8.0); long double Z = (long double)N; long double Sc; Sc = (logl(Z + A) * (Z + 0.5)) - (Z + A) - logl(Z); long double F = 1.0; long double Ck; long double Sum = SQRT2PI; for(int K = 1; K < A; K++) { Z++; Ck = powl(A - K, K - 0.5); Ck *= expl(A - K); Ck /= F; Sum += (Ck / Z); F *= (-1.0 * K); } return logl(Sum) + Sc; }
int main(int argc, char *argv[]) { char *password = fsp_argv_password(&argc, argv); if (argc != 2) { fprintf(stderr, "%s revision %s\n", argv[0], FS_FRONTEND_VER); fprintf(stderr, "Usage: %s <kbname>\n", argv[0]); return 1; } fsp_syslog_enable(); fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RO); if (!link) { fs_error(LOG_ERR, "couldn't connect to “%s”", argv[1]); return 2; } if (fsp_no_op(link, 0)) { fs_error(LOG_ERR, "NO-OP failed\n"); return 3; } fs_data_size total = {0, 0, 0, 0, 0, 0}; fs_data_size sz; if (fsp_get_data_size(link, 0, &sz)) { fs_error(LOG_ERR, "cannot get size information"); exit(2); } printf("%5s%12s%12s%12s%12s\n", "seg","quads (s)","quads (sr)", "models", "resources"); const int segments = fsp_link_segments(link); for (fs_segment seg = 0; seg < segments; ++seg) { fs_data_size sz; int ret = fsp_get_data_size(link, seg, &sz); if (ret) { printf("%5d -- problem obtaining size information --\n", seg); } else { printf("%5d%12lld%+12lld%12lld%12lld\n", seg, sz.quads_s, sz.quads_sr - sz.quads_s, sz.models_s, sz.resources); total.quads_s += sz.quads_s; total.quads_sr += sz.quads_sr; if (sz.models_s > total.models_s) total.models_s = sz.models_s; total.resources += sz.resources; } } printf("\n"); printf("%5s%12lld%+12lld%12lld%12lld\n", "TOTAL", total.quads_s, (total.quads_sr - total.quads_s), total.models_s, total.resources); printf("\ncollision probability ≅ %.2Lf%%\n", 100.0 * (1.0 - expl(-(total.resources * (total.resources-1.0) / (2.0 * CONST_2to63))))); fsp_close_link(link); }
static TACommandVerdict expl_cmd(TAThread thread,TAInputStream stream) { long double x, res; // Prepare x = readLongDouble(&stream); errno = 0; START_TARGET_OPERATION(thread); // Execute res = expl(x); END_TARGET_OPERATION(thread); // Response writeLongDouble(thread, res); writeInt(thread, errno); sendResponse(thread); return taDefaultVerdict; }
static long double stirf(long double x) { long double y, w, v; w = 1.0L/x; /* For large x, use rational coefficients from the analytical expansion. */ if (x > 1024.0L) w = (((((6.97281375836585777429E-5L * w + 7.84039221720066627474E-4L) * w - 2.29472093621399176955E-4L) * w - 2.68132716049382716049E-3L) * w + 3.47222222222222222222E-3L) * w + 8.33333333333333333333E-2L) * w + 1.0L; else w = 1.0L + w * polevll( w, STIR, 8 ); y = expl(x); if (x > MAXSTIR) { /* Avoid overflow in pow() */ v = powl(x, 0.5L * x - 0.25L); y = v * (v / y); } else { y = powl(x, x - 0.5L) / y; } y = SQTPI * y * w; return (y); }
long double logl(long double x) { long double y, y_old, ey, epsilon; y = 0.0; y_old = 1.0; epsilon = LDBL_EPSILON; while (y > y_old + epsilon || y < y_old - epsilon) { y_old = y; ey = expl(y); y -= (ey - x) / ey; if (y > 700.0) { y = 700.0; } if (y < -700.0) { y = -700.0; } epsilon = (fabs(y) > 1.0) ? fabs(y) * LDBL_EPSILON : LDBL_EPSILON; } if (y == 700.0) { return INFINITY; } if (y == -700.0) { return INFINITY; } return y; }
/* * Bruce Lindbloom, "Spectral Power Distribution of a Blackbody Radiator" * http://www.brucelindbloom.com/Eqn_Blackbody.html */ static double spd_blackbody(unsigned long int wavelength, double TempK) { // convert wavelength from nm to m const long double lambda = (double)wavelength * 1e-9; /* * these 2 constants were computed using following Sage code: * * (from http://physics.nist.gov/cgi-bin/cuu/Value?h) * h = 6.62606957 * 10^-34 # Planck * c= 299792458 # speed of light in vacuum * k = 1.3806488 * 10^-23 # Boltzmann * * c_1 = 2 * pi * h * c^2 * c_2 = h * c / k * * print 'c_1 = ', c_1, ' ~= ', RealField(128)(c_1) * print 'c_2 = ', c_2, ' ~= ', RealField(128)(c_2) */ #define c1 3.7417715246641281639549488324352159753e-16L #define c2 0.014387769599838156481252937624049081933L return (double)(c1 / (powl(lambda, 5) * (expl(c2 / (lambda * TempK)) - 1.0L))); #undef c2 #undef c1 }
long double complex CLANG_PORT_DECL(cpowl) (long double complex X, long double complex Y) { long double complex Res; long double i; long double r = hypotl (__real__ X, __imag__ X); if (r == 0.0L) { __real__ Res = __imag__ Res = 0.0L; } else { long double rho; long double theta; i = cargl (X); theta = i * __real__ Y; if (__imag__ Y == 0.0L) /* This gives slightly more accurate results in these cases. */ rho = powl (r, __real__ Y); else { r = logl (r); /* rearrangement of cexp(X * clog(Y)) */ theta += r * __imag__ Y; rho = expl (r * __real__ Y - i * __imag__ Y); } __real__ Res = rho * cosl (theta); __imag__ Res = rho * sinl (theta); } return Res; }
int main(void) { double i,e,roznica; double edbl = 0; long double eldbl = 0; long double el,roznical; for(i=0; i<19; i++) { edbl=edbl+((i+1)/silnia(i)); } edbl=0.5*edbl; printf("Typ Double: %.20f\n", edbl); e=exp(1); printf("EXP(1): %.20f\n",e); roznica=e-edbl; printf("ROZNICA: %.20g\n",roznica); for(i=0; i<22; i++) { eldbl=eldbl+((i+1)/silnia(i)); } eldbl=0.5*eldbl; printf("Typ LDouble: %.20lf\n", eldbl); el=expl(1); printf("EXPL(1): %.20lf\n",el); roznical=el-eldbl; printf("ROZNICA: %.20lg\n",roznical); }
void Exp (Token ** Pila) { Token *Operando = EntornoEjecucion_BuscaSimbolo (*Pila); if (Buzon.GetHuboError ()) return; if (NoEsReal (Operando)) { BorrarTokenSiEsVariable (Operando); return; } long double ValorDominio = Operando->GetDatoReal (); BorrarTokenSiEsVariable (Operando); long double ValorRetorno = expl (ValorDominio); if (Buzon.GetHuboError ()) return; Token *TokenRetorno = ConsigueToken (ValorRetorno); if (Buzon.GetHuboError ()) return; delete Desapila (Pila); Apila (Pila, TokenRetorno); if (FueraDeRango (TokenRetorno)) return; return; }
int main(int argc, char const *argv[]) { printf("Open file ... %d\n", isReadWriteable("Makefile")); long double xxl = expl(800); printf("e to the power of 1000 is %.2Le\n", xxl); return 0; }
static long double Continued_Fraction_Ei( long double x ) { long double Am1 = 1.0L; long double A0 = 0.0L; long double Bm1 = 0.0L; long double B0 = 1.0L; long double a = expl(x); long double b = -x + 1.0L; long double Ap1 = b * A0 + a * Am1; long double Bp1 = b * B0 + a * Bm1; int j = 1; a = 1.0L; while ( fabsl(Ap1 * B0 - A0 * Bp1) > epsilon * fabsl(A0 * Bp1) ) { if ( fabsl(Bp1) > 1.0L) { Am1 = A0 / Bp1; A0 = Ap1 / Bp1; Bm1 = B0 / Bp1; B0 = 1.0L; } else { Am1 = A0; A0 = Ap1; Bm1 = B0; B0 = Bp1; } a = -j * j; b += 2.0L; Ap1 = b * A0 + a * Am1; Bp1 = b * B0 + a * Bm1; j += 1; } return (-Ap1 / Bp1); }
// constructor for the case without control Pvalues::Pvalues(int length, int q_min, int q_max, int t_f, int t_r) { has_control=false; n=2*q_max; // calculate probility of success for treatment // -------------------------------------------- long double lambda_t = (q_max-q_min)*(t_r/(long double)length); long double rate_t = (t_f/(long double)length)*(1-expl(-lambda_t)); p_t = 1-exp(-rate_t*2); // init binomial distribution // -------------------------- boost::math::binomial_distribution<long double> BinomialTreatment(n,p_t); // init p-values from n to 0 // ------------------------- long double pval=0; for(int k=n;0<=k;k--) { pval=pval+pdf(BinomialTreatment,(k)); p_values[k]=pval; p_values_10log[k]=-log10l(pval); } }
void cm_float_exp(unsigned argc, obj_t args) { obj_t recvr = CAR(args); m_float_new(consts.cl._float, expl(FLOAT(recvr)->val)); }
int main (void) { printf ("%.16Lg\n", expl (1.0L)); printf ("%.16Lg\n", expl (-1.0L)); printf ("%.16Lg\n", expl (2.0L)); printf ("%.16Lg\n", expl (4.0L)); printf ("%.16Lg\n", expl (-2.0L)); printf ("%.16Lg\n", expl (-4.0L)); printf ("%.16Lg\n", expl (0.0625L)); printf ("%.16Lg\n", expl (0.3L)); printf ("%.16Lg\n", expl (0.6L)); }
long double complex cexpl (long double complex Z) { long double complex Res; long double rho = expl (__real__ Z); __real__ Res = rho * cosl(__imag__ Z); __imag__ Res = rho * sinl(__imag__ Z); return Res; }
long double coshl(long double x) { long double t,w; int32_t ex; u_int32_t mx,lx; /* High word of |x|. */ GET_LDOUBLE_WORDS(ex,mx,lx,x); ex &= 0x7fff; /* x is INF or NaN */ if(ex==0x7fff) return x*x; /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */ if(ex < 0x3ffd || (ex == 0x3ffd && mx < 0xb17217f7u)) { t = expm1l(fabsl(x)); w = one+t; if (ex<0x3fbc) return w; /* cosh(tiny) = 1 */ return one+(t*t)/(w+w); } /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ if (ex < 0x4003 || (ex == 0x4003 && mx < 0xb0000000u)) { t = expl(fabsl(x)); return half*t+half/t; } /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */ if (ex < 0x400c || (ex == 0x400c && mx < 0xb1700000u)) return half*expl(fabsl(x)); /* |x| in [log(maxdouble), log(2*maxdouble)) */ if (ex == 0x400c && (mx < 0xb174ddc0u || (mx == 0xb174ddc0u && lx < 0x31aec0ebu))) { w = expl(half*fabsl(x)); t = half*w; return t*w; } /* |x| >= log(2*maxdouble), cosh(x) overflow */ return huge*huge; }
long double sinhl(long double x) { long double a; int x_class = fpclassify (x); if (x_class == FP_NAN) { errno = EDOM; return x; } if (x_class == FP_ZERO) return x; if (x_class == FP_INFINITE || (fabs (x) > (MAXLOGL + LOGE2L))) { errno = ERANGE; #ifdef INFINITIES return (signbit (x) ? -INFINITYL : INFINITYL); #else return (signbit (x) ? -MAXNUML : MAXNUML); #endif } a = fabsl (x); if (a > 1.0L) { if (a >= (MAXLOGL - LOGE2L)) { a = expl(0.5L*a); a = (0.5L * a) * a; if (x < 0.0L) a = -a; return (a); } a = expl(a); a = 0.5L*a - (0.5L/a); if (x < 0.0L) a = -a; return (a); } a *= a; return (x + x * a * (polevll(a,P,3)/polevll(a,Q,4))); }
__complex__ long double cexpl(__complex__ long double z) { __complex__ long double ret; long double r_exponent = expl(__real__ z); __real__ ret = r_exponent * cosl(__imag__ z); __imag__ ret = r_exponent * sinl(__imag__ z); return ret; }
long double complex cexpl(long double complex z) { long double complex w; long double r; r = expl(creall(z)); w = r * cosl(cimagl(z)) + (r * sinl(cimagl(z))) * I; return (w); }
ldcomplex csinhl(ldcomplex z) { long double t, x, y, S, C; int hx, ix, hy, iy, n; ldcomplex ans; x = LD_RE(z); y = LD_IM(z); hx = HI_XWORD(x); ix = hx & 0x7fffffff; hy = HI_XWORD(y); iy = hy & 0x7fffffff; x = fabsl(x); y = fabsl(y); (void) sincosl(y, &S, &C); if (ix >= 0x4004e000) { /* |x| > 60 = prec/2 (14,28,34,60) */ if (ix >= 0x400C62E4) { /* |x| > 11356.52... ~ log(2**16384) */ if (ix >= 0x7fff0000) { /* |x| is inf or NaN */ if (y == zero) { LD_RE(ans) = x; LD_IM(ans) = y; } else if (iy >= 0x7fff0000) { LD_RE(ans) = x; LD_IM(ans) = x - y; } else { LD_RE(ans) = C * x; LD_IM(ans) = S * x; } } else { /* return exp(x)=t*2**n */ t = __k_cexpl(x, &n); LD_RE(ans) = scalbnl(C * t, n - 1); LD_IM(ans) = scalbnl(S * t, n - 1); } } else { t = expl(x) * half; LD_RE(ans) = C * t; LD_IM(ans) = S * t; } } else { if (x == zero) { /* x = 0, return (0,S) */ LD_RE(ans) = zero; LD_IM(ans) = S; } else { LD_RE(ans) = C * sinhl(x); LD_IM(ans) = S * coshl(x); } } if (hx < 0) LD_RE(ans) = -LD_RE(ans); if (hy < 0) LD_IM(ans) = -LD_IM(ans); return (ans); }