int main(){ int T; long long a,b,c; for(scanf("%d",&T);T--;){ scanf("%lld%lld%lld",&a,&b,&c); if(!a){ if(!b)puts(c?"0":"3"); else printf("1 %.12f\n",-c*1.0/b); }else{ if(a<0)a=-a,b=-b,c=-c; long double d=(long double)b*b-(long double)4*a*c; if(/*d==0*/fabsl(d)<1e-9)printf("1 %.12f\n",-b/2.0/a); else if(d<0)puts("0"); else printf("2 %.12Lf %.12Lf\n",(-b-sqrtl(d))/2/a,(-b+sqrtl(d))/2/a); } } return 0; }
depth_t frac_generalized_celtic(depth_t depth, long double wim, long double wre, long double c_im, long double c_re, long double wim2, long double wre2 ) { depth_t wz; for (wz = 1; wz <= depth; ++wz) { wim = 2.0 * wre * wim + c_im; wre = fabsl(wre2 - wim2) + c_re; wim2 = wim * wim; wre2 = wre * wre; if (wim2 + wre2 > 4.0F) return wz; } return 0; }
main() { int ret, si, ni, fi; int status = 0; for (si = 0; si < nitems(scale); si++) { for (ni = 0; ni < nitems(num); ni++) { for (fi = 0; fi < nitems(funcs); fi++) { char cmd[100]; FILE *fp; long double v, d1, d2, diff, prec; v = num[ni]; if (v == 0.0 && funcs[fi].f == logl) continue; snprintf(cmd, sizeof(cmd), "bc -l -e scale=%d -e '%s(%.19Lf)' -equit", scale[si], funcs[fi].name, v); fp = popen(cmd, "r"); ret = fscanf(fp, "%Lf", &d1); pclose(fp); d2 = funcs[fi].f(v); diff = fabsl(d1 - d2); prec = powl(10.0L, (long double)-scale[si]); if (prec < LDBL_EPSILON) prec = LDBL_EPSILON; prec *= 2; /* XXX cheating ? */ if (funcs[fi].f == logl) prec *= 4; else if (funcs[fi].f == expl) prec *= 8; if (diff > prec) { printf("%s %d %Le %Le %Le %Le %Le\n", funcs[fi].name, scale[si], v, d1, d2, diff, prec); status = 1; } } } } return status; }
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))); }
ATF_TC_BODY(sqrtl_powl, tc) { #ifndef __vax__ const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 }; const long double eps = 5.0*DBL_EPSILON; /* XXX powl == pow for now */ volatile long double y, z; size_t i; for (i = 0; i < __arraycount(x); i++) { y = sqrtl(x[i]); z = powl(x[i], 1.0 / 2.0); if (fabsl(y - z) > eps) atf_tc_fail_nonfatal("sqrtl(%0.03Lf) != " "powl(%0.03Lf, 1/2)\n", x[i], x[i]); } #endif }
long double asinhl(long double x) { long double t, w; volatile long double dummy; w = fabsl(x); if (isnanl(x)) return (x + x); /* x is NaN */ if (w < tiny) { #ifndef lint dummy = x + big; /* inexact if x != 0 */ #endif return (x); /* tiny x */ } else if (w < big) { t = one / w; return (copysignl(log1pl(w + w / (t + sqrtl(one + t * t))), x)); } else return (copysignl(logl(w) + ln2, x)); }
LONG_DOUBLE eval_expr_func(eval_context *ctx, ast_node *tree) { expr_func_data *func_data = (expr_func_data*)tree->data; if (strcmp(func_data->name, "sin") == 0) return sinl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "cos") == 0) return cosl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "tan") == 0) return tanl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "acos") == 0) return acosl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "asin") == 0) return asinl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "atan") == 0) return atanl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "cosh") == 0) return coshl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "sinh") == 0) return sinhl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "tanh") == 0) return tanhl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "log") == 0) return logl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "log10") == 0) return log10l(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "ceil") == 0) return ceill(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "fabs") == 0) return fabsl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "floor") == 0) return floorl(eval_expr(ctx, func_data->rhs)); else if (strcmp(func_data->name, "sqrt") == 0) return sqrtl(eval_expr(ctx, func_data->rhs)); else return eval_emit_error(ctx, "Unknown function %s.", func_data->name); }
void TGLFunWidget::drawPredicate(void) { Float x0 = (maxX + minX)*0.5, y0 = (maxY + minY)*0.5, z0 = (maxZ + minZ)*0.5; glPointSize(4); glBegin(GL_POINTS); for (unsigned i = 0; i < mesh->getX().size(); i++) if (fabsl((*results)[funIndex].getResults(i) > predicate.toFloat())) { if ((*results)[funIndex].getResults(i) > 0) glColor3b(1,0,0); else glColor3b(0,0,1); glVertex3f(cX(i) - x0, (mesh->getY().size()) ? cY(i) - y0 : 0, (mesh->getZ().size()) ? cZ(i) - z0 : 0); } glEnd(); }
long double bessi1_spd(long double x) { long double ax,ans; long double y; if ((ax=fabsl(x)) < 3.75) { y=x/3.75,y=y*y; ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3)))))); } else { y=3.75/ax; ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans)))); ans *= (expl(ax)/sqrtl(ax)); } return x < 0.0 ? -ans : ans; }
long double complex ctanl(long double complex z) { long double complex w; long double d; d = cosl(2.0L * creall(z)) + coshl(2.0L * cimagl(z)); if (fabsl(d) < 0.25L) d = _ctansl(z); if (d == 0.0L) { /* mtherr ("ctan", OVERFLOW); */ w = MAXNUM + MAXNUM * I; return w; } w = sinl(2.0L * creall(z)) / d + (sinhl(2.0L * cimagl(z)) / d) * I; return w; }
bool intersect(vec_t & r, const vec_t & u1, const vec_t & u2, const vec_t & v1, const vec_t & v2) { const long double m11 = u1.x - u2.x, m12 = u1.y - u2.y; const long double m21 = v2.x - v1.x, m22 = v2.y - v1.y; const long double det = m11*m22 - m12*m21; if( fabsl(det) < eps ) return false; const long double r11 = m22, r12 = -m12; const long double r21 = -m21, r22 = m11; const long double a = u1.x - v1.x, b = u1.y - v1.y; const long double t = (a*r11 + b*r21)/det, s = (a*r12 + b*r22)/det; r = u1 + (u2 - u1)*t; return true; }
int main (void) { ffi_cif cif; ffi_type *args[MAX_ARGS]; void *values[MAX_ARGS]; float f; long double ld; args[0] = &ffi_type_float; values[0] = &f; /* Initialize the cif */ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_longdouble, args) == FFI_OK); f = 3.14159; #if 1 /* This is ifdef'd out for now. long double support under SunOS/gcc is pretty much non-existent. You'll get the odd bus error in library routines like printf(). */ printf ("%Lf\n", ldblit(f)); #endif ld = 666; ffi_call(&cif, FFI_FN(ldblit), &ld, values); #if 1 /* This is ifdef'd out for now. long double support under SunOS/gcc is pretty much non-existent. You'll get the odd bus error in library routines like printf(). */ printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON); #endif /* These are not always the same!! Check for a reasonable delta */ if (fabsl(ld - ldblit(f)) < LDBL_EPSILON) puts("long double return value tests ok!"); else CHECK(0); exit(0); }
long double __asinhl(long double x) { long double t,w; int64_t hx,ix; GET_LDOUBLE_MSW64(hx,x); ix = hx&0x7fffffffffffffffLL; if(ix>=0x7ff0000000000000LL) return x+x; /* x is inf or NaN */ if(ix< 0x3e20000000000000LL) { /* |x|<2**-29 */ if(huge+x>one) return x; /* return x inexact except 0 */ } if(ix>0x41b0000000000000LL) { /* |x| > 2**28 */ w = __ieee754_logl(fabs(x))+ln2; } else if (ix>0x4000000000000000LL) { /* 2**28 > |x| > 2.0 */ t = fabs(x); w = __ieee754_logl(2.0*t+one/(__ieee754_sqrtl(x*x+one)+t)); } else { /* 2.0 > |x| > 2**-29 */ t = x*x; w =__log1pl(fabsl(x)+t/(one+__ieee754_sqrtl(one+t))); } if(hx>0) return w; else return -w; }
long double SigDig(long double x, size_t n) { long double shift, result; if ((n == 0u) || (n > LDBL_DIG)) result = x; else { --n; #if defined(__DJGPP__) | defined(_MSC_VER) shift = pow(10.0L,(double)n - floor(log10(fabs(x)))); #else shift = powl(10.0L,(double)n - floorl(log10l(fabsl(x)))); #endif result = ToNearest(x * shift) / shift; } return result; }
/* * @brief */ int32_t FindPlane(vec3_t normal, dvec_t dist) { int32_t i; SnapPlane(normal, &dist); const uint16_t hash = ((uint32_t) fabsl(dist)) & (PLANE_HASHES - 1); // search the border bins as well for (i = -1; i <= 1; i++) { const uint16_t h = (hash + i) & (PLANE_HASHES - 1); const map_plane_t *p = plane_hash[h]; while (p) { if (PlaneEqual(p, normal, dist)) { return p - map_planes; } p = p->hash_chain; } } return CreateNewFloatPlane(normal, dist); }
long double atanhl(long double x) { long double t; uint16_t hx, ix; ENTERI(); GET_LDBL_EXPSIGN(hx, x); ix = hx & 0x7fff; if (ix >= 0x3fff) /* |x| >= 1, or NaN or misnormal */ RETURNI(fabsl(x) == 1 ? x / zero : (x - x) / (x - x)); if (ix < BIAS + EXP_TINY && (huge + x) > zero) RETURNI(x); /* x is tiny */ SET_LDBL_EXPSIGN(x, ix); if (ix < 0x3ffe) { /* |x| < 0.5, or misnormal */ t = x+x; t = 0.5*log1pl(t+t*x/(one-x)); } else t = 0.5*log1pl((x+x)/(one-x)); RETURNI((hx & 0x8000) == 0 ? t : -t); }
void updateTimeout(Timeout *timeout, const long double sampleRTT) { //char LOG[300]; if (pthread_rwlock_wrlock(&(timeout->rwlock)) > 0) ERREXIT("Cannot acquire timeout write-lock for updating value."); timeout->extRTT = RUDP_EXTRTT_A * timeout->extRTT + RUDP_EXTRTT_B * sampleRTT; timeout->devRTT = RUDP_DEVRTT_A * timeout->devRTT + RUDP_DEVRTT_B * fabsl(timeout->extRTT - sampleRTT); timeout->value = RUDP_TIMEO_A * timeout->extRTT + RUDP_TIMEO_B * timeout->devRTT; /* sprintf(LOG, "%LF\t%LF\t%LF\n", timeout->extRTT, timeout->devRTT, timeout->value); errno = 0; if (write(LOGFILE, LOG, strlen(LOG)) == -1) ERREXIT("Cannot write timeout log file: %s.", strerror(errno)); */ if (pthread_rwlock_unlock(&(timeout->rwlock)) > 0) ERREXIT("Cannot release timeout read-write lock for updating value."); }
void Tangente (Token ** Pila) { Token *Operando = EntornoEjecucion_BuscaSimbolo (*Pila); if (Buzon.GetHuboError ()) return; if (NoEsReal (Operando)) { BorrarTokenSiEsVariable (Operando); return; } long double ValorDominio = Operando->GetDatoReal (); BorrarTokenSiEsVariable (Operando); ValorDominio = Estado.AngulosEnGrados ? ValorDominio * M_PI / 180.0L : ValorDominio; long double ValorSeno = sinl (ValorDominio); long double ValorCoseno = cosl (ValorDominio); long double ValorRetorno; if (fabsl (ValorSeno) == 1.0L) { Buzon.Error (LLAMADO_DE_FUNCION_NO_VALIDO); return; } else if (ValorCoseno == 1.0L) ValorRetorno = 0.0L; else ValorRetorno = tanl (ValorDominio); if (Buzon.GetHuboError ()) return; Token *TokenRetorno = ConsigueToken (ValorRetorno); if (Buzon.GetHuboError ()) return; delete Desapila (Pila); Apila (Pila, TokenRetorno); if (FueraDeRango (TokenRetorno)) return; return; }
void newton (long double p0, long double b, long double error, long double p, long double (*f) (long double, long double), char *name) { long double p1, fb, fc, c, test; int n = 0; printf (" Starting newton %s with min accuracy of %Lf\n", name, error); printf (" p0 p1 test \n"); do { p1 = p0 - f (p0, 0) / f (p0, 1); if (isnan (p1)) goto fail; test = fabsl (p0 - p1); printf (" %12.6Lf %12.6Lf %12.6Lf \n", p0, p1, test); p0 = p1; // fail gracefully n++; if (n > 20) { printf (" *** This method is failing, use another technique \n"); break; } } while (test > error); fail: printf (" Best Guess: %0.17Lf \n", p1); printf (" Error Estimate: %0.17Lf \n", test); printf (" Stopping newton %s\n\n", name); }
void ImageTile::SetWindows(long double variance, bool convolve) { bool methodA = false; bool methodB = false; bool methodC = true; // Unwindow everything for(unsigned channel = 0;channel<_channelCount;++channel) { for(unsigned scan = 0;scan<_scanCount;++scan) _isWindowed[channel][scan] = false; } if(methodA) { // Window everything higher than trigger * sigma for(unsigned channel = 0;channel<_channelCount;++channel) { for(unsigned scan = 0;scan<_scanCount;++scan) { if(fabsl(GetValueAt(channel, scan) - EvaluateBaselineFunction(scan, channel)) > _trigger * variance) { Window(scan, channel); } } } } if(methodB) { for(unsigned channel = 0;channel<_channelCount;++channel) { for(unsigned scan = 0;scan<_scanCount;++scan) { bool triggered = TriggeredRaise(channel, scan, channel-1, scan-1, variance) || TriggeredRaise(channel, scan, channel-1, scan+1, variance) || TriggeredRaise(channel, scan, channel+1, scan-1, variance) || TriggeredRaise(channel, scan, channel+1, scan+1, variance); if(triggered) Window(scan, channel); } } } if(convolve) ConvolveWindows(); if(methodC) { LineThreshold(true, 0.0, variance, convolve); } }
static long double expx2l (long double x) { long double u, u1, m, f; x = fabsl (x); /* Represent x as an exact multiple of M plus a residual. M is a power of 2 chosen so that exp(m * m) does not overflow or underflow and so that |x - m| is small. */ m = MINV * floorl(M * x + 0.5L); f = x - m; /* x^2 = m^2 + 2mf + f^2 */ u = m * m; u1 = 2 * m * f + f * f; if ((u + u1) > MAXLOGL) return (INFINITYL); /* u is exact, u1 is small. */ u = expl(u) * expl(u1); return (u); }
void Abs (Token ** Pila) { Token *Operando = EntornoEjecucion_BuscaSimbolo (*Pila); if (Buzon.GetHuboError ()) return; if (NoEsReal (Operando)) { BorrarTokenSiEsVariable (Operando); return; } long double ValorRetorno = fabsl (Operando->GetDatoReal ()); BorrarTokenSiEsVariable (Operando); if (Buzon.GetHuboError ()) return; Token *TokenRetorno = ConsigueToken (ValorRetorno); delete Desapila (Pila); Apila (Pila, TokenRetorno); return; }
long double coshl(long double x) { long double t, w; w = fabsl(x); if (!finitel(w)) return (w + w); /* x is INF or NaN */ if (w < thr1) { t = w < tinyl ? w : expm1l(w); w = one + t; if (w != one) w = one + (t * t) / (w + w); return (w); } else if (w < thr2) { t = expl(w); return (half * (t + one / t)); } else if (w <= lnovftL) return (half * expl(w)); else { return (scalbnl(expl((w - MEP1 * ln2hi) - MEP1 * ln2lo), ME)); } }
long double __logbl (long double x) { int32_t es, lx, ix; GET_LDOUBLE_WORDS (es, ix, lx, x); es &= 0x7fff; /* exponent */ if ((es | ix | lx) == 0) return -1.0 / fabsl (x); if (es == 0x7fff) return x * x; if (es == 0) /* IEEE 754 logb */ { /* POSIX specifies that denormal number is treated as though it were normalized. */ if (ix == 0) es = -(__builtin_clz (lx) + 32); else es = -__builtin_clz (ix); } return (long double) (es - 16383); }
void get_acceleration_by_earthl_test(void) { long double utc_in_mjd = 59865.00000000L; long double coord[3], acceleration[3]; coord[0] = -43203.60633L; coord[1] = 932.853125L; coord[2] = 105.030427L; get_acceleration_by_earthl(utc_in_mjd, coord, acceleration); assert(fabsl(fabsl(acceleration[0]) - 0.00021340560717251052L) < 1e-18); assert(fabsl(fabsl(acceleration[1]) - 4.6078667089531894e-006L) < 1e-18); assert(fabsl(fabsl(acceleration[2]) - 5.1880435966992614e-007L) < 1e-18); return; }
void get_acceleration_by_moonl_test(void) { long double utc_in_mjd = 59865.0L; long double coord[3], acceleration[3]; coord[0] = -43203.60633L; coord[1] = 932.853125L; coord[2] = 105.030427L; get_acceleration_by_moonl(utc_in_mjd, coord, acceleration); assert(fabsl(fabsl(acceleration[0]) - 5.7471499870040367575e-11L) < 1e-18); assert(fabsl(fabsl(acceleration[1]) - 4.0468814090081801167e-09L) < 1e-18); assert(fabsl(fabsl(acceleration[2]) - 1.8596276722038470893e-09L) < 1e-18); return; }
void get_acceleration_by_sunl_test(void) { long double utc_in_mjd = 59865.0L; long double coord[3], acceleration[3]; coord[0] = -43203.606331156676L; coord[1] = 932.8531254505084L; coord[2] = 105.03042685970608L; get_acceleration_by_sunl(utc_in_mjd, coord, acceleration); assert(fabsl(fabsl(acceleration[0]) - 2.8480208700617356e-009L) < 1e-18); assert(fabsl(fabsl(acceleration[1]) - 1.5087331078186935e-009L) < 1e-18); assert(fabsl(fabsl(acceleration[2]) - 6.4204449389352687e-010L) < 1e-18); return; }
/* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */ long double asinhl(long double x) { long double z; if (!isfinite (x)) return x; z = fabsl (x); /* Avoid setting FPU underflow exception flag in x * x. */ #if 0 if ( z < 0x1p-32) return x; #endif /* Use log1p to avoid cancellation with small x. Put x * x in denom, so overflow is harmless. asinh(x) = log1p (x + sqrt (x * x + 1.0) - 1.0) = log1p (x + x * x / (sqrt (x * x + 1.0) + 1.0)) */ z = __fast_log1pl (z + z * z / (__fast_sqrtl (z * z + 1.0L) + 1.0L)); return ( x > 0.0 ? z : -z); }
long double __ieee754_exp10l (long double arg) { union ibm_extended_long_double u; long double arg_high, arg_low; long double exp_high, exp_low; if (!__finitel (arg)) return __ieee754_expl (arg); if (arg < LDBL_MIN_10_EXP - LDBL_DIG - 10) return LDBL_MIN * LDBL_MIN; else if (arg > LDBL_MAX_10_EXP + 1) return LDBL_MAX * LDBL_MAX; else if (fabsl (arg) < 0x1p-109L) return 1.0L; u.ld = arg; arg_high = u.d[0].d; arg_low = u.d[1].d; exp_high = arg_high * log10_high; exp_low = arg_high * log10_low + arg_low * M_LN10l; return __ieee754_expl (exp_high) * __ieee754_expl (exp_low); }
long double coshl(long double x) { long double w, t; w = fabsl(x); if (!finitel(w)) return (w + w); /* x is INF or NaN */ if (w < thr1) { if (w < tinyl) return (one + w); /* inexact+directed rounding */ t = expm1l(w); w = one + t; w = one + (t * t) / (w + w); return (w); } if (w < thr2) { t = expl(w); return (half * (t + one / t)); } if (w <= lnovft) return (half * expl(w)); return (scalbnl(expl((w - lnovft) - lnovlo), 16383)); }