long double TSolver::gcalc(const char f,const long double a,const long double b,const long double step) //calculates function { #define ain(x) (a-step<=x && a+step>=x) #define bin(x) (b-step<=x && b+step>=x) #define angin(x) (torad(a)-step<x && torad(a)+step>x) switch (f) {case '+' : return a+b; case '-' : return a-b; case '*' : return a*b; case '/' : if (bin(0)) {Err=E_DEV_ZERO;return 0;};return a/b; case '!' : if (floorl(a)!=a) {Err=E_ARG;return 0;}return factor(a); case '_' : return -a; case cpi : return M_PI; case cx : return X; case fexp : return exp(a); case fln : if (a<0) {Err=E_ARG;return 0;}return logl(a); case flog : if (a<0) {Err=E_ARG;return 0;}return log10l(a); case flogn : if (a<0) {Err=E_ARG;return 0;}return log(a)/log(b); case '^': case f_op_pow: case fpow : if (a<0 && b<1 && b>0 && (!fmodl(b,2))) {Err=E_ARG;return 0;}return powl(a,b); case fsqr : return a*a; case f_op_root: case froot : if (a<0 && (!fmodl(b,2))){Err=E_ARG;return 0;} return (a>0 || (!fmodl(b,2)))?powl(a,1/b):-powl(-a,1/b); case fsqrt : if (a<0) {Err=E_ARG;return 0;}return sqrtl(a); case f_abs : return fabsl(a); case fsin : return sinl(a); case fcos : return cosl(a); case ftan : if (angin(M_PI_2) || angin(M_PI_2+M_PI)) {Err=E_ARG;return 0;} return tanl(a); case fctan : if (angin(0) || angin(M_PI)) {Err=E_ARG;return 0;} return 1/tanl(a); case fsin+ARC : if (fabsl(a)>1) {Err=E_ARG;return 0;} return asinl(a); case fcos+ARC : if (fabsl(a)>1) {Err=E_ARG;return 0;} return acosl(a); case ftan+ARC : return atanl(a); case fctan+ARC: return atanl(1/a); case fsin+HYP : return sinhl(a); case fcos+HYP : return coshl(a); case ftan+HYP : return tanhl(a); case fctan+HYP : return 1/tanhl(a); #ifndef _OLD_ case fsin+HYP+ARC : return asinhl(a); case fcos+HYP+ARC : return acoshl(a); case ftan+HYP+ARC : if (fabsl(a)>=1) {Err=E_ARG;return 0;} return atanhl(a); case fctan+HYP+ARC : if (angin(0)) {Err=E_ARG;return 0;} return atanhl(1/a); #endif default: return 0; } }
static Result XXX_PushOpr(Stack *sopr, Stack *sval, int opr) { Result res = R_SUCCE; long double tmp; long double *ans; while (!SEmpty(sopr) && XXX_ShouldPop(*STopInt(sopr), opr)) { switch (SPopInt(sopr)) { case OPR_TRM: return R_ITRNL; case BIN_ADD: XXXPO_EVOB(*ans += tmp); case BIN_SUB: XXXPO_EVOB(*ans -= tmp); case BIN_MUL: XXXPO_EVOB(*ans *= tmp); case BIN_DIV: XXXPO_EVOB(*ans /= tmp); case BIN_MOD: XXXPO_EVOB(*ans = fmodl(*ans, tmp)); case BIN_PWR: XXXPO_EVOB(*ans = powl(*ans, tmp)); case UNA_PLS: XXXPO_EVOU(); case UNA_MNS: XXXPO_EVOU(*ans = -*ans); default: return R_ITRNL; } if ((res = RMathType(*ans))) return ERR(res); } if (SPushInt(sopr, opr)) return R_ITRNL; return R_SUCCE; }
int main() { long double z,i,m,l,count,p,c,k; c=1; while(1) { scanf("%Lf %Lf %Lf %Lf",&z,&i,&m,&l); if(z==0&&i==0&&l==0&&m==0) break; count=0; while(1) { p=(z*l)+i; p=fmodl(p,m); if(count==0) k=p; else if(p==k) break; count++; l=p; } printf("Case %0.Lf: %0.Lf\n",c,count); c++; } return 0; }
long double asinl(long double x) { long double y, y_sin, y_cos; y = 0; while (1) { y_sin = sinl(y); y_cos = cosl(y); if (y > M_PI_2 || y < -M_PI_2) { y = fmodl(y, M_PI); } if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x) { break; } y = y - (y_sin - x) / y_cos; } return y; }
int main(void) { #pragma STDC FENV_ACCESS ON long double y; float d; int e, i, err = 0; struct ll_l *p; for (i = 0; i < sizeof t/sizeof *t; i++) { p = t + i; if (p->r < 0) continue; fesetround(p->r); feclearexcept(FE_ALL_EXCEPT); y = fmodl(p->x, p->x2); e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW); if (!checkexcept(e, p->e, p->r)) { printf("%s:%d: bad fp exception: %s fmodl(%La,%La)=%La, want %s", p->file, p->line, rstr(p->r), p->x, p->x2, p->y, estr(p->e)); printf(" got %s\n", estr(e)); err++; } d = ulperrl(y, p->y, p->dy); if (!checkcr(y, p->y, p->r)) { printf("%s:%d: %s fmodl(%La,%La) want %La got %La ulperr %.3f = %a + %a\n", p->file, p->line, rstr(p->r), p->x, p->x2, p->y, y, d, d-p->dy, p->dy); err++; } } return !!err; }
targ_ldouble _modulo(targ_ldouble x, targ_ldouble y) { #if __DMC__ short sw; __asm { fld tbyte ptr y fld tbyte ptr x // ST = x, ST1 = y FM1: // We don't use fprem1 because for some inexplicable // reason we get -5 when we do _modulo(15, 10) fprem // ST = ST % ST1 fstsw word ptr sw fwait mov AH,byte ptr sw+1 // get msb of status word in AH sahf // transfer to flags jp FM1 // continue till ST < ST1 fstp ST(1) // leave remainder on stack } #elif __FreeBSD__ || __OpenBSD__ || __DragonFly__ return fmod(x, y); #else return fmodl(x, y); #endif }
ull* productFib(ull prod) { ull *out = malloc(3 * sizeof(ull*)); ull isfib = 1; long double golden = 1.6180339887498948482; long double srfive = 2.2360679774997896964; long double p = (long double)prod; long double n, m, r, t; n = roundl(sqrtl(p / golden)); m = p / n; r = fmodl(p, n); if (r > 0) { isfib = 0; t = floorl(logl(n * srfive) / logl(golden)) + 1; n = roundl(powl(golden, t) / srfive); m = roundl(powl(golden, t + 1) / srfive); } out[0] = (ull)n; out[1] = (ull)m; out[2] = isfib; return out; }
void test_fmod() { static_assert((std::is_same<decltype(fmod((double)0, (double)0)), double>::value), ""); static_assert((std::is_same<decltype(fmodf(0,0)), float>::value), ""); static_assert((std::is_same<decltype(fmodl(0,0)), long double>::value), ""); assert(fmod(1.5,1) == .5); }
long double modfl(long double x, long double * iptr) { long double ret = fmodl(x, 1.0); *iptr = x - ret; return ret; }
DWORDLONG Target::Rand(DWORDLONG limit) { #if defined(IOMTR_OSFAMILY_UNIX) && defined(WORKAROUND_MOD_BUG) return ((DWORDLONG)fmodl(spec.random = A * spec.random + B, limit)); #else #ifdef _DEBUG assert(limit > 0); #endif return (spec.random = A * spec.random + B) % limit; #endif }
long double sinl(long double x) { long double x_squared; long double sin_x; size_t i; /* Move x to [-pi, pi) */ x = fmodl(x, 2 * M_PI); if (x >= M_PI) { x -= 2 * M_PI; } if (x < -M_PI) { x += 2 * M_PI; } /* Move x to [-pi/2, pi/2) */ if (x >= M_PI_2) { x = M_PI - x; } if (x < -M_PI_2) { x = -M_PI - x; } x_squared = x * x; sin_x = 0.0; /* Perform Taylor series approximation for sin(x) with ten terms */ for (i = 0; i < 10; i++) { if (i % 2 == 0) { sin_x += x * _ldbl_inv_fact[i]; } else { sin_x -= x * _ldbl_inv_fact[i]; } x *= x_squared; } return sin_x; }
static int _map(long double in_value, long double in_min, long double in_max, long double out_min, long double out_max, long double out_step, double *out_value) { long double result; result = (in_value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; errno = 0; result -= fmodl((result - out_min), out_step); if (errno > 0) return -errno; *out_value = result; return 0; }
int main () { long double i, result = 0; long double d = 1; long double n = 2; long double c; for (i=2; i<=MAX; i++){ long double x = d; //long double c = (i%3==0) ? (2*i)/3 : 1; //long double c = (i%3==0) ? (2*i)/3 : 1; c = fmodl(i, 3.0); if (c == 0.0 ) c = 2*(i/3) ; else c = 1.0; d = n; n = c * d + x; } result = addDigits(n); printf("Solution is %0.0Lf\n", result ); exit (0); }
inline real_concept fmod(real_concept a, real_concept b) { return fmodl(a.value(), b.value()); }
// // Ugly workaround for macro fmodl: // inline long double call_fmodl(long double a, long double b) { return fmodl(a, b); }
inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b) { return fmodl(a.value(), b.value()); }
long double test1l(long double x, long double y) { return fmodl(x, y); }
long double fmod360(long double d) { d = fmodl(d, 360); if (d < 0) d += 360; return d; }
static int testl(long double long_double_x, int int_x, long long_x) { int r = 0; r += __finitel(long_double_x); r += __fpclassifyl(long_double_x); r += __isinfl(long_double_x); r += __isnanl(long_double_x); r += __signbitl(long_double_x); r += acoshl(long_double_x); r += acosl(long_double_x); r += asinhl(long_double_x); r += asinl(long_double_x); r += atan2l(long_double_x, long_double_x); r += atanhl(long_double_x); r += atanl(long_double_x); r += cbrtl(long_double_x); r += ceill(long_double_x); r += copysignl(long_double_x, long_double_x); r += coshl(long_double_x); r += cosl(long_double_x); r += erfcl(long_double_x); r += erfl(long_double_x); r += exp2l(long_double_x); r += expl(long_double_x); r += expm1l(long_double_x); r += fabsl(long_double_x); r += fdiml(long_double_x, long_double_x); r += floorl(long_double_x); r += fmal(long_double_x, long_double_x, long_double_x); r += fmaxl(long_double_x, long_double_x); r += fminl(long_double_x, long_double_x); r += fmodl(long_double_x, long_double_x); r += frexpl(long_double_x, &int_x); r += hypotl(long_double_x, long_double_x); r += ilogbl(long_double_x); r += ldexpl(long_double_x, int_x); r += lgammal(long_double_x); r += llrintl(long_double_x); r += llroundl(long_double_x); r += log10l(long_double_x); r += log1pl(long_double_x); r += log2l(long_double_x); r += logbl(long_double_x); r += logl(long_double_x); r += lrintl(long_double_x); r += lroundl(long_double_x); r += modfl(long_double_x, &long_double_x); r += nearbyintl(long_double_x); r += nextafterl(long_double_x, long_double_x); r += nexttowardl(long_double_x, long_double_x); r += powl(long_double_x, long_double_x); r += remainderl(long_double_x, long_double_x); r += remquol(long_double_x, long_double_x, &int_x); r += rintl(long_double_x); r += roundl(long_double_x); r += scalblnl(long_double_x, long_x); r += scalbnl(long_double_x, int_x); r += sinhl(long_double_x); r += sinl(long_double_x); r += sqrtl(long_double_x); r += tanhl(long_double_x); r += tanl(long_double_x); r += tgammal(long_double_x); r += truncl(long_double_x); return r; }
int main() { while(1) { scanf("%ld",&n); if(n==0) break; add=count=0; for(i=0;i<n;i++) { scanf("%ld",&a[i]); add+=a[i]; if(a[i]==0) count++; } if(count==n) { printf("0\n"); continue; } pro=x[n-1]; bool c[1000]={0}; for(i=0;i<n;i++) { if(c[i]==0) { count=0; for(j=i+1;j<n;j++) { if(a[i]==a[j]) { c[j]=1; count++; } } pro=pro/x[count]; } } pro/=n; pro*=add; d=pro; for(i=0;i<n;i++) { b[i]=fmodl(pro,10); pro/=10; pro=floorl(pro); pro+=d; } if(d==0) { for(i=n-1;i>=0;i--) printf("%ld",a[i]); } else { if(pro>d) printf("%0.Lf",pro-d); for(i=n-1;i>=0;i--) printf("%ld",b[i]); } printf("\n"); } return 0; }
TEST(math, fmodl) { ASSERT_FLOAT_EQ(2.0, fmodl(12.0, 10.0)); }
void domathl (void) { #ifndef NO_LONG_DOUBLE long double f1; long double f2; int i1; f1 = acosl(0.0); fprintf( stdout, "acosl : %Lf\n", f1); f1 = acoshl(0.0); fprintf( stdout, "acoshl : %Lf\n", f1); f1 = asinl(1.0); fprintf( stdout, "asinl : %Lf\n", f1); f1 = asinhl(1.0); fprintf( stdout, "asinhl : %Lf\n", f1); f1 = atanl(M_PI_4); fprintf( stdout, "atanl : %Lf\n", f1); f1 = atan2l(2.3, 2.3); fprintf( stdout, "atan2l : %Lf\n", f1); f1 = atanhl(1.0); fprintf( stdout, "atanhl : %Lf\n", f1); f1 = cbrtl(27.0); fprintf( stdout, "cbrtl : %Lf\n", f1); f1 = ceill(3.5); fprintf( stdout, "ceill : %Lf\n", f1); f1 = copysignl(3.5, -2.5); fprintf( stdout, "copysignl : %Lf\n", f1); f1 = cosl(M_PI_2); fprintf( stdout, "cosl : %Lf\n", f1); f1 = coshl(M_PI_2); fprintf( stdout, "coshl : %Lf\n", f1); f1 = erfl(42.0); fprintf( stdout, "erfl : %Lf\n", f1); f1 = erfcl(42.0); fprintf( stdout, "erfcl : %Lf\n", f1); f1 = expl(0.42); fprintf( stdout, "expl : %Lf\n", f1); f1 = exp2l(0.42); fprintf( stdout, "exp2l : %Lf\n", f1); f1 = expm1l(0.00042); fprintf( stdout, "expm1l : %Lf\n", f1); f1 = fabsl(-1.123); fprintf( stdout, "fabsl : %Lf\n", f1); f1 = fdiml(1.123, 2.123); fprintf( stdout, "fdiml : %Lf\n", f1); f1 = floorl(0.5); fprintf( stdout, "floorl : %Lf\n", f1); f1 = floorl(-0.5); fprintf( stdout, "floorl : %Lf\n", f1); f1 = fmal(2.1, 2.2, 3.01); fprintf( stdout, "fmal : %Lf\n", f1); f1 = fmaxl(-0.42, 0.42); fprintf( stdout, "fmaxl : %Lf\n", f1); f1 = fminl(-0.42, 0.42); fprintf( stdout, "fminl : %Lf\n", f1); f1 = fmodl(42.0, 3.0); fprintf( stdout, "fmodl : %Lf\n", f1); /* no type-specific variant */ i1 = fpclassify(1.0); fprintf( stdout, "fpclassify : %d\n", i1); f1 = frexpl(42.0, &i1); fprintf( stdout, "frexpl : %Lf\n", f1); f1 = hypotl(42.0, 42.0); fprintf( stdout, "hypotl : %Lf\n", f1); i1 = ilogbl(42.0); fprintf( stdout, "ilogbl : %d\n", i1); /* no type-specific variant */ i1 = isfinite(3.0); fprintf( stdout, "isfinite : %d\n", i1); /* no type-specific variant */ i1 = isgreater(3.0, 3.1); fprintf( stdout, "isgreater : %d\n", i1); /* no type-specific variant */ i1 = isgreaterequal(3.0, 3.1); fprintf( stdout, "isgreaterequal : %d\n", i1); /* no type-specific variant */ i1 = isinf(3.0); fprintf( stdout, "isinf : %d\n", i1); /* no type-specific variant */ i1 = isless(3.0, 3.1); fprintf( stdout, "isless : %d\n", i1); /* no type-specific variant */ i1 = islessequal(3.0, 3.1); fprintf( stdout, "islessequal : %d\n", i1); /* no type-specific variant */ i1 = islessgreater(3.0, 3.1); fprintf( stdout, "islessgreater : %d\n", i1); /* no type-specific variant */ i1 = isnan(0.0); fprintf( stdout, "isnan : %d\n", i1); /* no type-specific variant */ i1 = isnormal(3.0); fprintf( stdout, "isnormal : %d\n", i1); /* no type-specific variant */ f1 = isunordered(1.0, 2.0); fprintf( stdout, "isunordered : %d\n", i1); f1 = j0l(1.2); fprintf( stdout, "j0l : %Lf\n", f1); f1 = j1l(1.2); fprintf( stdout, "j1l : %Lf\n", f1); f1 = jnl(2,1.2); fprintf( stdout, "jnl : %Lf\n", f1); f1 = ldexpl(1.2,3); fprintf( stdout, "ldexpl : %Lf\n", f1); f1 = lgammal(42.0); fprintf( stdout, "lgammal : %Lf\n", f1); f1 = llrintl(-0.5); fprintf( stdout, "llrintl : %Lf\n", f1); f1 = llrintl(0.5); fprintf( stdout, "llrintl : %Lf\n", f1); f1 = llroundl(-0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = llroundl(0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = logl(42.0); fprintf( stdout, "logl : %Lf\n", f1); f1 = log10l(42.0); fprintf( stdout, "log10l : %Lf\n", f1); f1 = log1pl(42.0); fprintf( stdout, "log1pl : %Lf\n", f1); f1 = log2l(42.0); fprintf( stdout, "log2l : %Lf\n", f1); f1 = logbl(42.0); fprintf( stdout, "logbl : %Lf\n", f1); f1 = lrintl(-0.5); fprintf( stdout, "lrintl : %Lf\n", f1); f1 = lrintl(0.5); fprintf( stdout, "lrintl : %Lf\n", f1); f1 = lroundl(-0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = lroundl(0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = modfl(42.0,&f2); fprintf( stdout, "lmodfl : %Lf\n", f1); f1 = nanl(""); fprintf( stdout, "nanl : %Lf\n", f1); f1 = nearbyintl(1.5); fprintf( stdout, "nearbyintl : %Lf\n", f1); f1 = nextafterl(1.5,2.0); fprintf( stdout, "nextafterl : %Lf\n", f1); f1 = powl(3.01, 2.0); fprintf( stdout, "powl : %Lf\n", f1); f1 = remainderl(3.01,2.0); fprintf( stdout, "remainderl : %Lf\n", f1); f1 = remquol(29.0,3.0,&i1); fprintf( stdout, "remquol : %Lf\n", f1); f1 = rintl(0.5); fprintf( stdout, "rintl : %Lf\n", f1); f1 = rintl(-0.5); fprintf( stdout, "rintl : %Lf\n", f1); f1 = roundl(0.5); fprintf( stdout, "roundl : %Lf\n", f1); f1 = roundl(-0.5); fprintf( stdout, "roundl : %Lf\n", f1); f1 = scalblnl(1.2,3); fprintf( stdout, "scalblnl : %Lf\n", f1); f1 = scalbnl(1.2,3); fprintf( stdout, "scalbnl : %Lf\n", f1); /* no type-specific variant */ i1 = signbit(1.0); fprintf( stdout, "signbit : %i\n", i1); f1 = sinl(M_PI_4); fprintf( stdout, "sinl : %Lf\n", f1); f1 = sinhl(M_PI_4); fprintf( stdout, "sinhl : %Lf\n", f1); f1 = sqrtl(9.0); fprintf( stdout, "sqrtl : %Lf\n", f1); f1 = tanl(M_PI_4); fprintf( stdout, "tanl : %Lf\n", f1); f1 = tanhl(M_PI_4); fprintf( stdout, "tanhl : %Lf\n", f1); f1 = tgammal(2.1); fprintf( stdout, "tgammal : %Lf\n", f1); f1 = truncl(3.5); fprintf( stdout, "truncl : %Lf\n", f1); f1 = y0l(1.2); fprintf( stdout, "y0l : %Lf\n", f1); f1 = y1l(1.2); fprintf( stdout, "y1l : %Lf\n", f1); f1 = ynl(3,1.2); fprintf( stdout, "ynl : %Lf\n", f1); #endif }
TEST(math, fmodl) { ASSERT_DOUBLE_EQ(2.0L, fmodl(12.0L, 10.0L)); }
void NumericosBinarios (Token ** Pila, int Caso) { Token *Operando2 = EntornoEjecucion_BuscaSimbolo (*Pila); if (Buzon.GetHuboError ()) return; Token *Operando1 = EntornoEjecucion_BuscaSimbolo ((*Pila)->GetSig ()); if (Buzon.GetHuboError ()) { BorrarTokenSiEsVariable (Operando2); return; } if (NoEsReal (Operando1)) { BorrarTokenSiEsVariable (Operando1); BorrarTokenSiEsVariable (Operando2); return; } if (NoEsReal (Operando2)) { BorrarTokenSiEsVariable (Operando1); BorrarTokenSiEsVariable (Operando2); return; } long double Op1 = Operando1->GetDatoReal (); BorrarTokenSiEsVariable (Operando1); long double Op2 = Operando2->GetDatoReal (); BorrarTokenSiEsVariable (Operando2); long double ValorRetorno; switch (Caso) { case 1: ValorRetorno = Op1 - Op2; break; case 2: ValorRetorno = Op1 * Op2; break; case 3: if (Op2) ValorRetorno = Op1 / Op2; else Buzon.Error (DIVISION_POR_CERO); break; case 4: if (Op2) ValorRetorno = fmodl (Op1, Op2); else Buzon.Error (DIVISION_POR_CERO); break; case 5: ValorRetorno = powl (Op1, Op2); break; }; if (Buzon.GetHuboError ()) return; Token *TokenRetorno = ConsigueToken (ValorRetorno); if (Buzon.GetHuboError ()) return; if (FueraDeRango (TokenRetorno)) return; delete Desapila (Pila); delete Desapila (Pila); Apila (Pila, TokenRetorno); return; }
double fmod(double x, double y) { return fmodl(x, y); }
extern "C" long double _swift_fmodl(long double lhs, long double rhs) { return fmodl(lhs, rhs); }
npy_longdouble npy_fmodl(npy_longdouble x, npy_longdouble y) { return fmodl(x, y); }