int main () { DECL_LONG_DOUBLE_ROUNDING BEGIN_LONG_DOUBLE_ROUNDING (); /* See IEEE 754, section 6.3: "the sign of the result of the round floating-point number to integral value operation is the sign of the operand. These rules shall apply even when operands or results are zero or infinite." */ /* Zero. */ ASSERT (!signbit (truncl (0.0L))); ASSERT (!!signbit (truncl (minus_zerol)) == !!signbit (minus_zerol)); /* Positive numbers. */ ASSERT (!signbit (truncl (0.3L))); ASSERT (!signbit (truncl (0.7L))); /* Negative numbers. */ ASSERT (!!signbit (truncl (-0.3L)) == !!signbit (minus_zerol)); ASSERT (!!signbit (truncl (-0.7L)) == !!signbit (minus_zerol)); /* [MX] shaded specification in POSIX. */ /* NaN. */ ASSERT (isnanl (truncl (NaNl ()))); /* Infinity. */ ASSERT (truncl (Infinityl ()) == Infinityl ()); ASSERT (truncl (- Infinityl ()) == - Infinityl ()); return 0; }
int main(void) { long double NaN = 0.0l / 0.0l; long double Inf = 1.0l / 0.0l; long double negInf = -1.0l / 0.0l; long double val = __VERIFIER_nondet_long_double(); if (!__isnanl(val) && !__isinfl(val) && !__iszerol(val)) { if (val > 0) { assert(truncl(val) <= val); } else { assert(truncl(val) >= val); } } assert(truncl(0.0l) == 0.0l); assert(truncl(-0.0l) == -0.0l); int isNeg = __signbitl(truncl(-0.0l)); assert(isNeg); assert(truncl(Inf) == Inf); assert(truncl(negInf) == negInf); assert(__isnanl(truncl(NaN))); return 0; }
void test_trunc() { static_assert((std::is_same<decltype(trunc((double)0)), double>::value), ""); static_assert((std::is_same<decltype(truncf(0)), float>::value), ""); static_assert((std::is_same<decltype(truncl(0)), long double>::value), ""); assert(trunc(1) == 1); }
int main(void) { #pragma STDC FENV_ACCESS ON long double y; float d; int e, i, err = 0; struct l_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 = truncl(p->x); e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW); if (!checkexceptall(e, p->e, p->r)) { printf("%s:%d: bad fp exception: %s truncl(%La)=%La, want %s", p->file, p->line, rstr(p->r), p->x, 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 truncl(%La) want %La got %La ulperr %.3f = %a + %a\n", p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy); err++; } } return !!err; }
void mjd_to_utcl(long double mjd, int *nyear, int *nmonth, int *nday, int *nhour, int *nminute, long double *nsecond) { long double A, B, C, D, E, G, F, I; long double days, month, year; long double jd = mjd + 2400001.0L; F = modfl(jd, &I); A = truncl((I - 1867216.25L) / 36524.25L); B = (I > 2299160.0L) ? I + 1 + A - truncl(A / 4.0L) : I; C = B + 1524.0L; D = truncl((C - 122.1L) / 365.25L); E = truncl(365.25L * D); G = truncl((C - E) / 30.6001L); days = C - E + F - truncl(30.6001L * G); month = (G < 13.0L) ? G - 1 : G - 13.0L; year = (month > 2.5L) ? D - 4716.0L : D - 4715.0L; *nyear = (int) year; *nmonth = (int) month; *nday = (int) days; days_to_hmsl(days - (int) days, nhour, nminute, nsecond); return; }
long double mjd_to_gmstl(long double utc_in_mjd, long double delta_ut) { long double ts = utc_in_mjd + delta_ut / SEC_IN_DAY; long double ts_trunc = truncl(ts); long double s = ts - ts_trunc; long double tu = (truncl(ts) - MJD2000) / JULIAN_C; long double s0 = 1.753368559233266L + (628.3319706888409L + (6.770713944903336e-06L - 4.508767234318685e-10L*tu)*tu)*tu; long double freq = 1.002737909350795L + (5.900575455674703e-11L - 5.893984333409384e-15L*tu)*tu; s0 += freq*s*PI2; long double r = s0 / PI2; long double i = truncl(r); long double gmst = s0 - PI2*i; if (gmst < 0) { gmst += PI2; } return gmst; }
TEST(math, truncl) { fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero. ASSERT_FLOAT_EQ(1.0, truncl(1.5)); ASSERT_FLOAT_EQ(-1.0, truncl(-1.5)); ASSERT_FLOAT_EQ(0.0, truncl(0.0)); ASSERT_FLOAT_EQ(-0.0, truncl(-0.0)); ASSERT_TRUE(isnan(truncl(nan("")))); ASSERT_FLOAT_EQ(HUGE_VALL, truncl(HUGE_VALL)); }
TEST(math, truncl) { auto guard = make_scope_guard([]() { fesetenv(FE_DFL_ENV); }); fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero. ASSERT_DOUBLE_EQ(1.0L, truncl(1.5L)); ASSERT_DOUBLE_EQ(-1.0L, truncl(-1.5L)); ASSERT_DOUBLE_EQ(0.0L, truncl(0.0L)); ASSERT_DOUBLE_EQ(-0.0L, truncl(-0.0L)); ASSERT_TRUE(isnan(truncl(nan("")))); ASSERT_DOUBLE_EQ(HUGE_VALL, truncl(HUGE_VALL)); }
long double modfl (long double x, long double *iptr) { if (isfinite (x)) { long double integer_part = truncl (x); *iptr = integer_part; return x - integer_part; } else { if (isinf (x)) { *iptr = x; return 1.0L / x; } else /* isnanl (x) */ { *iptr = x; return x; } } }
void fun_C(int x, int y, int z) { b=truncl(a); printf("%Lf\n", b); }
long double test4l(long double x) { return truncl(x); }
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 }
npy_longdouble npy_truncl(npy_longdouble x) { return truncl(x); }
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; }