TEST(math, ilogb) { ASSERT_EQ(FP_ILOGB0, ilogb(0.0)); ASSERT_EQ(FP_ILOGBNAN, ilogb(nan(""))); ASSERT_EQ(INT_MAX, ilogb(HUGE_VAL)); ASSERT_EQ(0, ilogb(1.0)); ASSERT_EQ(3, ilogb(10.0)); }
void test_ilogb() { static_assert((std::is_same<decltype(ilogb((double)0)), int>::value), ""); static_assert((std::is_same<decltype(ilogbf(0)), int>::value), ""); static_assert((std::is_same<decltype(ilogbl(0)), int>::value), ""); assert(ilogb(1) == 0); }
int main(void) { char buf[128], *end; double d; float f; long double ld; int e, i; printf("1..3\n"); assert(ilogb(0) == FP_ILOGB0); assert(ilogb(NAN) == FP_ILOGBNAN); assert(ilogb(INFINITY) == INT_MAX); for (e = DBL_MIN_EXP - DBL_MANT_DIG; e < DBL_MAX_EXP; e++) { snprintf(buf, sizeof(buf), "0x1.p%d", e); d = strtod(buf, &end); assert(*end == '\0'); i = ilogb(d); assert(i == e); } printf("ok 1 - ilogb\n"); assert(ilogbf(0) == FP_ILOGB0); assert(ilogbf(NAN) == FP_ILOGBNAN); assert(ilogbf(INFINITY) == INT_MAX); for (e = FLT_MIN_EXP - FLT_MANT_DIG; e < FLT_MAX_EXP; e++) { snprintf(buf, sizeof(buf), "0x1.p%d", e); f = strtof(buf, &end); assert(*end == '\0'); i = ilogbf(f); assert(i == e); } printf("ok 2 - ilogbf\n"); assert(ilogbl(0) == FP_ILOGB0); assert(ilogbl(NAN) == FP_ILOGBNAN); assert(ilogbl(INFINITY) == INT_MAX); for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e < LDBL_MAX_EXP; e++) { snprintf(buf, sizeof(buf), "0x1.p%d", e); ld = strtold(buf, &end); assert(*end == '\0'); i = ilogbl(ld); assert(i == e); } printf("ok 3 - ilogbl\n"); return (0); }
/*++ Function: ilogb See MSDN. --*/ PALIMPORT int __cdecl PAL_ilogb(double x) { int ret; PERF_ENTRY(ilogb); ENTRY("ilogb (x=%f)\n", x); #if !HAVE_COMPATIBLE_ILOGB0 if (x == 0.0) { ret = -2147483648; } else #endif // !HAVE_COMPATIBLE_ILOGB0 #if !HAVE_COMPATIBLE_ILOGBNAN if (isnan(x)) { ret = 2147483647; } else #endif // !HAVE_COMPATIBLE_ILOGBNAN { ret = ilogb(x); } LOGEXIT("ilogb returns int %d\n", ret); PERF_EXIT(ilogb); return ret; }
bool Texture2D::createStorage(Size2i size, unsigned int channels, bool compressed, int levels) { if (created) { return false; } // levels = -1 means max mipmap level according to texture dimensions const int maxLevels = ilogb(size.max()) + 1; if (levels == 0) levels = 1; if (levels < 0 || levels > maxLevels) levels = maxLevels; this->channels = std::min(std::max(1u, channels), 4u); this->size = size; this->levels = levels; if (glTexStorage2D) { // try to allocate immutable storage (ogl 4.3) glTexStorage2D(target, levels, glInternalFormat(compressed), size.width(), size.height()); } else { // ensure texture completeness despite mutable storage for (int i=0; i<levels; ++i) { glTexImage2D(target, i, glInternalFormat(compressed), size.width(), size.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, nullptr); size = Size2i(std::max(1, size.width()>>1), std::max(1, size.height()>>1)); } glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); } return created = true; }
int main() { double x = 1.0; double y = 1.0; int i = 1; acosh(x); asinh(x); atanh(x); cbrt(x); expm1(x); erf(x); erfc(x); isnan(x); j0(x); j1(x); jn(i,x); ilogb(x); logb(x); log1p(x); rint(x); y0(x); y1(x); yn(i,x); # ifdef _THREAD_SAFE gamma_r(x,&i); lgamma_r(x,&i); # else gamma(x); lgamma(x); # endif hypot(x,y); nextafter(x,y); remainder(x,y); scalb(x,y); return 0; }
/* * Convert a floating point number in native format to TMS32032 * floating point single precision (32 bit) format. Note that the * TMS floating point value is returned as an unsigned integer. */ static unsigned int float2tms32(float x) { unsigned int zero = 0x80000000; /* Zero value is special case */ int nfracbits = 23; /* Not including hidden bit / sign bit */ int signbit = 1 << nfracbits; int fracmask = ~((~0)<<nfracbits); int iexp; int sign; int ifrac; unsigned int rtn; if (x == 0){ rtn = zero; }else{ iexp = ilogb(x); /* Binary exponent if 1 <= |fraction| < 2 */ ifrac = (int)scalbn(x, nfracbits-iexp); /* Frac part as integer */ if (x<0 && (ifrac & signbit)){ /* Force top bit of negative fraction to be 0 */ ifrac <<= 1; iexp--; } sign = x<0 ? signbit : 0; rtn = (iexp << (nfracbits+1)) | sign | (ifrac & fracmask); } return rtn; }
T ulp_imp(const T& val, const mpl::false_&, const Policy& pol) { BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); BOOST_MATH_STD_USING int expon; static const char* function = "ulp<%1%>(%1%)"; int fpclass = (boost::math::fpclassify)(val); if(fpclass == (int)FP_NAN) { return policies::raise_domain_error<T>( function, "Argument must be finite, but got %1%", val, pol); } else if((fpclass == (int)FP_INFINITE) || (fabs(val) >= tools::max_value<T>())) { return (val < 0 ? -1 : 1) * policies::raise_overflow_error<T>(function, 0, pol); } else if(fpclass == FP_ZERO) return detail::get_smallest_value<T>(); // // This code is almost the same as that for float_next, except for negative integers, // where we preserve the relation ulp(x) == ulp(-x) as does Java: // expon = 1 + ilogb(fabs(val)); T diff = scalbn(T(1), expon - std::numeric_limits<T>::digits); if(diff == 0) diff = detail::get_smallest_value<T>(); return diff; }
int ilogbl(long double x) { #if defined(__arm__) || defined(_ARM_) return ilogb(x); #else #error Not supported on your platform yet #endif }
void Math_ilogb(void *fp) { F_Math_ilogb *f; f = fp; *f->ret = ilogb(f->x); }
inline T normalize_value(const T& val, const mpl::true_&) { BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); boost::intmax_t shift = std::numeric_limits<T>::digits - ilogb(val) - 1; T result = scalbn(val, shift); result = round(result); return scalbn(result, -shift); }
int main () { double param; int result; param = 10.0; result = ilogb (param); printf ("ilogb(%f) = %d\n", param, result); return 0; }
void test_fp_exp( void ) { #if __STDC_VERSION__ >= 199901L printf( "Testing C99 exponential/logarithm functions...\n" ); /* Small test values taken from SPECFUN tests */ VERIFY( CompDbl( expm1( 0.0 ), 0.0 ) ); VERIFY( CompDbl( expm1( 1.0 ), E-1.0 ) ); VERIFY( CompDbl( expm1( 1.0E-3 ), 1.00050016670834166E-3 ) ); VERIFY( CompDbl( expm1( 1.0E-9 ), 1.00000000050000000e-9 ) ); VERIFY( CompDbl( expm1( -1.0E-3 ), -9.9950016662500833194E-4 ) ); VERIFY( CompDbl( expm1( -1.0E-9 ), -9.9999999950000000016e-10 ) ); VERIFY( CompDbl( log1p( 0.02 ), 0.019803 ) ); VERIFY( CompDbl( log1p( 0.03 ), 0.029559 ) ); VERIFY( CompDbl( log1p( 0.10 ), 0.095310 ) ); /* logb/ilogb tests */ VERIFY( logb( 0.0 ) == INFINITY ); VERIFY( CompDbl( logb( 1024.0 ), 10.0 ) ); VERIFY( CompDbl( logb( 1025.0 ), 10.0 ) ); VERIFY( CompDbl( logb( 1.0/1024.0 ), -10.0 ) ); VERIFY( CompDbl( logb( -1025.0 ), 10.0 ) ); VERIFY( ilogb( 0.0 ) == FP_ILOGB0 ); VERIFY( ilogb( NAN ) == FP_ILOGBNAN ); VERIFY( ilogb( 1024.0 ) == 10 ); VERIFY( ilogb( 1025.0 ) == 10 ); VERIFY( ilogb( 1.0/1024.0 ) == -10 ); VERIFY( ilogb( -1025.0 ) == 10 ); #endif }
ATF_TC_BODY(ilogb, tc) { ATF_CHECK(ilogbf(0) == FP_ILOGB0); ATF_CHECK_RAISED_INVALID; ATF_CHECK(ilogb(0) == FP_ILOGB0); ATF_CHECK_RAISED_INVALID; #ifdef __HAVE_LONG_DOUBLE ATF_CHECK(ilogbl(0) == FP_ILOGB0); ATF_CHECK_RAISED_INVALID; #endif ATF_CHECK(ilogbf(-0) == FP_ILOGB0); ATF_CHECK_RAISED_INVALID; ATF_CHECK(ilogb(-0) == FP_ILOGB0); ATF_CHECK_RAISED_INVALID; #ifdef __HAVE_LONG_DOUBLE ATF_CHECK(ilogbl(-0) == FP_ILOGB0); ATF_CHECK_RAISED_INVALID; #endif ATF_CHECK(ilogbf(INFINITY) == INT_MAX); ATF_CHECK_RAISED_INVALID; ATF_CHECK(ilogb(INFINITY) == INT_MAX); ATF_CHECK_RAISED_INVALID; #ifdef __HAVE_LONG_DOUBLE ATF_CHECK(ilogbl(INFINITY) == INT_MAX); ATF_CHECK_RAISED_INVALID; #endif ATF_CHECK(ilogbf(-INFINITY) == INT_MAX); ATF_CHECK_RAISED_INVALID; ATF_CHECK(ilogb(-INFINITY) == INT_MAX); ATF_CHECK_RAISED_INVALID; #ifdef __HAVE_LONG_DOUBLE ATF_CHECK(ilogbl(-INFINITY) == INT_MAX); ATF_CHECK_RAISED_INVALID; #endif ATF_CHECK(ilogbf(1024) == 10); ATF_CHECK_RAISED_NOTHING; ATF_CHECK(ilogb(1024) == 10); ATF_CHECK_RAISED_NOTHING; #ifdef __HAVE_LONG_DOUBLE ATF_CHECK(ilogbl(1024) == 10); ATF_CHECK_RAISED_NOTHING; #endif #ifndef __vax__ ATF_CHECK(ilogbf(NAN) == FP_ILOGBNAN); ATF_CHECK_RAISED_INVALID; ATF_CHECK(ilogb(NAN) == FP_ILOGBNAN); ATF_CHECK_RAISED_INVALID; #ifdef __HAVE_LONG_DOUBLE ATF_CHECK(ilogbl(NAN) == FP_ILOGBNAN); ATF_CHECK_RAISED_INVALID; #endif #endif }
/* * Output in "human-readable" format. Uses 3 digits max and puts * unit suffixes at the end. Makes output compact and easy to read, * especially on huge disks. * */ unit_t unit_adjust(double *val) { double abval; unit_t unit; unsigned int unit_sz; abval = fabs(*val); unit_sz = abval ? ilogb(abval) / 10 : 0; if (unit_sz >= UNIT_MAX) { unit = NONE; } else { unit = unitp[unit_sz]; *val /= (double)valp[unit_sz]; } return (unit); }
int ilogbl (long double x) { return ilogb(x); }
int ilogbf (float x) { return (int) ilogb( (double)x ); }
double significand(double x) { return scalb(x,(double) -ilogb(x)); }
int ilogbf(float x) { return ilogb(x); }
int ilogbl(long double a1) { return ilogb(a1); }
static void F(compile_test) (void) { TYPE a, b, c = 1.0; complex TYPE d; int i; int saved_count; long int j; long long int k; a = cos (cos (x)); b = acos (acos (a)); a = sin (sin (x)); b = asin (asin (a)); a = tan (tan (x)); b = atan (atan (a)); c = atan2 (atan2 (a, c), atan2 (b, x)); a = cosh (cosh (x)); b = acosh (acosh (a)); a = sinh (sinh (x)); b = asinh (asinh (a)); a = tanh (tanh (x)); b = atanh (atanh (a)); a = exp (exp (x)); b = log (log (a)); a = log10 (log10 (x)); b = ldexp (ldexp (a, 1), 5); a = frexp (frexp (x, &i), &i); b = expm1 (expm1 (a)); a = log1p (log1p (x)); b = logb (logb (a)); a = exp2 (exp2 (x)); b = log2 (log2 (a)); a = pow (pow (x, a), pow (c, b)); b = sqrt (sqrt (a)); a = hypot (hypot (x, b), hypot (c, a)); b = cbrt (cbrt (a)); a = ceil (ceil (x)); b = fabs (fabs (a)); a = floor (floor (x)); b = fmod (fmod (a, b), fmod (c, x)); a = nearbyint (nearbyint (x)); b = round (round (a)); a = trunc (trunc (x)); b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i); j = lrint (x) + lround (a); k = llrint (b) + llround (c); a = erf (erf (x)); b = erfc (erfc (a)); a = tgamma (tgamma (x)); b = lgamma (lgamma (a)); a = rint (rint (x)); b = nextafter (nextafter (a, b), nextafter (c, x)); a = nextdown (nextdown (a)); b = nexttoward (nexttoward (x, a), c); a = nextup (nextup (a)); b = remainder (remainder (a, b), remainder (c, x)); a = scalb (scalb (x, a), (TYPE) (6)); k = scalbn (a, 7) + scalbln (c, 10l); i = ilogb (x); j = llogb (x); a = fdim (fdim (x, a), fdim (c, b)); b = fmax (fmax (a, x), fmax (c, b)); a = fmin (fmin (x, a), fmin (c, b)); b = fma (sin (a), sin (x), sin (c)); a = totalorder (totalorder (x, b), totalorder (c, x)); b = totalordermag (totalordermag (x, a), totalordermag (c, x)); #ifdef TEST_INT a = atan2 (i, b); b = remquo (i, a, &i); c = fma (i, b, i); a = pow (i, c); #endif x = a + b + c + i + j + k; saved_count = count; if (ccount != 0) ccount = -10000; d = cos (cos (z)); z = acos (acos (d)); d = sin (sin (z)); z = asin (asin (d)); d = tan (tan (z)); z = atan (atan (d)); d = cosh (cosh (z)); z = acosh (acosh (d)); d = sinh (sinh (z)); z = asinh (asinh (d)); d = tanh (tanh (z)); z = atanh (atanh (d)); d = exp (exp (z)); z = log (log (d)); d = sqrt (sqrt (z)); z = conj (conj (d)); d = fabs (conj (a)); z = pow (pow (a, d), pow (b, z)); d = cproj (cproj (z)); z += fabs (cproj (a)); a = carg (carg (z)); b = creal (creal (d)); c = cimag (cimag (z)); x += a + b + c + i + j + k; z += d; if (saved_count != count) count = -10000; if (0) { a = cos (y); a = acos (y); a = sin (y); a = asin (y); a = tan (y); a = atan (y); a = atan2 (y, y); a = cosh (y); a = acosh (y); a = sinh (y); a = asinh (y); a = tanh (y); a = atanh (y); a = exp (y); a = log (y); a = log10 (y); a = ldexp (y, 5); a = frexp (y, &i); a = expm1 (y); a = log1p (y); a = logb (y); a = exp2 (y); a = log2 (y); a = pow (y, y); a = sqrt (y); a = hypot (y, y); a = cbrt (y); a = ceil (y); a = fabs (y); a = floor (y); a = fmod (y, y); a = nearbyint (y); a = round (y); a = trunc (y); a = remquo (y, y, &i); j = lrint (y) + lround (y); k = llrint (y) + llround (y); a = erf (y); a = erfc (y); a = tgamma (y); a = lgamma (y); a = rint (y); a = nextafter (y, y); a = nexttoward (y, y); a = remainder (y, y); a = scalb (y, (const TYPE) (6)); k = scalbn (y, 7) + scalbln (y, 10l); i = ilogb (y); j = llogb (y); a = fdim (y, y); a = fmax (y, y); a = fmin (y, y); a = fma (y, y, y); a = totalorder (y, y); a = totalordermag (y, y); #ifdef TEST_INT a = atan2 (i, y); a = remquo (i, y, &i); a = fma (i, y, i); a = pow (i, y); #endif d = cos ((const complex TYPE) z); d = acos ((const complex TYPE) z); d = sin ((const complex TYPE) z); d = asin ((const complex TYPE) z); d = tan ((const complex TYPE) z); d = atan ((const complex TYPE) z); d = cosh ((const complex TYPE) z); d = acosh ((const complex TYPE) z); d = sinh ((const complex TYPE) z); d = asinh ((const complex TYPE) z); d = tanh ((const complex TYPE) z); d = atanh ((const complex TYPE) z); d = exp ((const complex TYPE) z); d = log ((const complex TYPE) z); d = sqrt ((const complex TYPE) z); d = pow ((const complex TYPE) z, (const complex TYPE) z); d = fabs ((const complex TYPE) z); d = carg ((const complex TYPE) z); d = creal ((const complex TYPE) z); d = cimag ((const complex TYPE) z); d = conj ((const complex TYPE) z); d = cproj ((const complex TYPE) z); } }
double significand(double x) { return __ieee754_scalb(x,(double) -ilogb(x)); }
sl_def(do_test, void) { #define x values[p].d #define xf values[p].f #define y values[p+1].d #define yf values[p+1].f #define n values[p+2].i #define nl values[p+2].l #define call1(F) \ values[p].desc = #F; \ values[p].d = F(x); \ ++p; \ values[p].desc = #F "f"; \ values[p].f = F ## f (xf); \ ++p #define call1i(F) \ values[p].desc = #F; \ values[p].i = F(x); \ ++p #define call2(F) \ values[p].desc = #F; \ values[p].d = F(x, y); \ p += 2; \ values[p].desc = #F "f"; \ values[p].f = F ## f (xf, yf); \ p += 2 #define call2i(F) \ values[p].desc = #F; \ values[p].i = F(x, y); \ p += 2; \ values[p].desc = #F "f"; \ values[p].i = F(xf, yf); \ p += 2 /* classify */ call1i(fpclassify); call1i(signbit); call1i(isfinite); call1i(isnormal); call1i(isnan); call1i(isinf); /* trig */ call1(acos); call1(asin); call1(atan); call2(atan2); call1(cos); call1(sin); call1(tan); /* hyperbolic */ call1(acosh); call1(asinh); call1(atanh); call1(cosh); call1(sinh); call1(tanh); /* exp/log */ call1(exp); call1(exp2); call1(expm1); values[p].desc = "frexp"; values[p].d = frexp(x, &values[p+1].i); p += 2; values[p].desc = "frexpf"; values[p].f = frexpf(xf, &values[p+1].i); p += 2; values[p].desc = "ilogb"; values[p].i = ilogb(x); p++; values[p].desc = "ilogbf"; values[p].i = ilogbf(xf); p++; values[p].desc = "ldexp"; values[p].d = ldexp(x, n); p+=3; values[p].desc = "ldexpf"; values[p].f = ldexpf(xf, n); p+=3; call1(log); call1(log10); call1(log1p); call1(log2); call1(logb); values[p].desc = "modf"; values[p].d = modf(x, &y); p += 2; values[p].desc = "modff"; values[p].f = modff(xf, &yf); p += 2; values[p].desc = "scalbn"; values[p].d = scalbn(x, n); p+=3; values[p].desc = "scalbnf"; values[p].f = scalbnf(xf, n); p+=3; values[p].desc = "scalbln"; values[p].d = scalbln(x, nl); p+=3; values[p].desc = "scalblnf"; values[p].f = scalblnf(xf, nl); p+=3; /* power/abs */ call1(cbrt); call1(fabs); call2(hypot); call2(pow); call1(sqrt); /* error/gamma */ call1(erf); call1(erfc); call1(lgamma); call1(tgamma); call1(ceil); call1(floor); call1(nearbyint); call1(rint); call1(lrint); values[p].desc = "lrint"; values[p].l = lrint(x); p++; values[p].desc = "lrintf"; values[p].l = lrintf(xf); p++; values[p].desc = "llrint"; values[p].ll = llrint(x); p++; values[p].desc = "llrintf"; values[p].ll = llrintf(xf); p++; call1(round); values[p].desc = "lround"; values[p].l = lround(x); p++; values[p].desc = "lroundf"; values[p].l = lroundf(xf); p++; values[p].desc = "llround"; values[p].ll = llround(x); p++; values[p].desc = "llroundf"; values[p].ll = llroundf(xf); p++; call1(trunc); /* rem/mod */ call2(fmod); call2(remainder); values[p].desc = "remquo"; values[p].d = remquo(x, y, &values[p+1].i); p+=2; values[p].desc = "remquof"; values[p].f = remquof(xf, yf, &values[p+1].i); p+=2; call2(copysign); /* nan */ values[p].desc = "nan"; values[p].d = nan(""); ++p; values[p].desc = "nanf"; values[p].f = nanf(""); ++p; call2(nextafter); /* min/max/dim */ call2(fdim); call2(fmax); call2(fmin); values[p].desc = "fma"; values[p].d = fma(x, y, values[p+2].d); p+=3; values[p].desc = "fmaf"; values[p].d = fmaf(xf, yf, values[p+2].f); p+=3; /* comp */ call2i(isgreater); call2i(isgreaterequal); call2i(isless); call2i(islessequal); call2i(islessgreater); call2i(isunordered); #undef x #undef xf #undef y #undef n }
sl_enddef // XIGNORE: mts*:D // SLT_RUN: -f TEST.d1 // SLT_RUN: -f TEST.d2 int main(int argc, char **argv) { int j; double x = .42; int n = 42; assert(fibre_tag(0) == 2 && fibre_rank(0) == 0); assert(fibre_tag(1) == 0 && fibre_rank(1) == 0); x = *(double*)fibre_data(0); n = *(long*)fibre_data(1); for(j = 0; j < MAX_TESTS; ++j) { values[j].desc = 0; values[j].f = values[j].d = x; values[j].i = values[j].l = values[j].ll = n; } sl_create(,,,,,,, do_test); sl_sync(); double_t xd = x; float_t xf = x; output_string("dot forty two, d: ", 1); output_float(xd, 1, 4); output_char('\n', 1); output_string("dot forty two, f: ", 1); output_float(xf, 1, 4); output_char('\n', 1); output_string("HUGE_VAL: ", 1); output_float(HUGE_VAL, 1, 4); output_char('\n', 1); output_string("HUGE_VALF: ", 1); output_float(HUGE_VALF, 1, 4); output_char('\n', 1); output_string("INFINITY: ", 1); output_float(INFINITY, 1, 4); output_char('\n', 1); output_string("NAN: ", 1); output_float(NAN, 1, 4); output_char('\n', 1); output_string("FP_ILOGB0 // ilogb(0): ", 1); output_int(FP_ILOGB0 == ilogb(0), 1); output_char('\n', 1); output_string("FP_ILOGBNAN // ilogb(NAN): ", 1); output_int(FP_ILOGBNAN == ilogb(NAN), 1); output_char('\n', 1); output_string("M_2: ", 1); output_float(M_E, 1, 4); output_char('\n', 1); output_string("M_LOG2E: ", 1); output_float(M_LOG2E, 1, 4); output_char('\n', 1); output_string("M_LOG10E: ", 1); output_float(M_LOG10E, 1, 4); output_char('\n', 1); output_string("M_LN2: ", 1); output_float(M_LN2, 1, 4); output_char('\n', 1); output_string("M_LN10: ", 1); output_float(M_LN10, 1, 4); output_char('\n', 1); output_string("M_PI: ", 1); output_float(M_PI, 1, 4); output_char('\n', 1); output_string("M_PI_2: ", 1); output_float(M_PI_2, 1, 4); output_char('\n', 1); output_string("M_PI_4: ", 1); output_float(M_PI_4, 1, 4); output_char('\n', 1); output_string("M_1_PI: ", 1); output_float(M_1_PI, 1, 4); output_char('\n', 1); output_string("M_2_PI: ", 1); output_float(M_2_PI, 1, 4); output_char('\n', 1); output_string("M_2_SQRTPI: ", 1); output_float(M_2_SQRTPI, 1, 4); output_char('\n', 1); output_string("M_SQRT2: ", 1); output_float(M_SQRT2, 1, 4); output_char('\n', 1); output_string("M_SQRT1_2: ", 1); output_float(M_SQRT1_2, 1, 4); output_char('\n', 1); for (j = 0; j < p; ++j) { const char *d = values[j].desc ? values[j].desc : "."; output_string(d, 1); output_char(' ', 1); output_float(values[j].d, 1, 4); output_char(' ', 1); output_float(values[j].f, 1, 4); output_char(' ', 1); output_int(values[j].i, 1); output_char(' ', 1); output_int(values[j].l, 1); output_char(' ', 1); output_int(values[j].ll, 1); output_char('\n', 1); } return 0; }
__device__ void double_precision_math_functions() { int iX; double fX, fY; acos(1.0); acosh(1.0); asin(0.0); asinh(0.0); atan(0.0); atan2(0.0, 1.0); atanh(0.0); cbrt(0.0); ceil(0.0); copysign(1.0, -2.0); cos(0.0); cosh(0.0); cospi(0.0); cyl_bessel_i0(0.0); cyl_bessel_i1(0.0); erf(0.0); erfc(0.0); erfcinv(2.0); erfcx(0.0); erfinv(1.0); exp(0.0); exp10(0.0); exp2(0.0); expm1(0.0); fabs(1.0); fdim(1.0, 0.0); floor(0.0); fma(1.0, 2.0, 3.0); fmax(0.0, 0.0); fmin(0.0, 0.0); fmod(0.0, 1.0); frexp(0.0, &iX); hypot(1.0, 0.0); ilogb(1.0); isfinite(0.0); isinf(0.0); isnan(0.0); j0(0.0); j1(0.0); jn(-1.0, 1.0); ldexp(0.0, 0); lgamma(1.0); llrint(0.0); llround(0.0); log(1.0); log10(1.0); log1p(-1.0); log2(1.0); logb(1.0); lrint(0.0); lround(0.0); modf(0.0, &fX); nan("1"); nearbyint(0.0); nextafter(0.0, 0.0); fX = 1.0; norm(1, &fX); norm3d(1.0, 0.0, 0.0); norm4d(1.0, 0.0, 0.0, 0.0); normcdf(0.0); normcdfinv(1.0); pow(1.0, 0.0); rcbrt(1.0); remainder(2.0, 1.0); remquo(1.0, 2.0, &iX); rhypot(0.0, 1.0); rint(1.0); fX = 1.0; rnorm(1, &fX); rnorm3d(0.0, 0.0, 1.0); rnorm4d(0.0, 0.0, 0.0, 1.0); round(0.0); rsqrt(1.0); scalbln(0.0, 1); scalbn(0.0, 1); signbit(1.0); sin(0.0); sincos(0.0, &fX, &fY); sincospi(0.0, &fX, &fY); sinh(0.0); sinpi(0.0); sqrt(0.0); tan(0.0); tanh(0.0); tgamma(2.0); trunc(0.0); y0(1.0); y1(1.0); yn(1, 1.0); }
int ilogbl( double x ) { return ilogb((double) x); }
void math (double d, int *ex, double *dp) { acos (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 8 } */ acosh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 10 } */ asin (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 12 } */ asinh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 14 } */ atan (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 16 } */ atanh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 18 } */ atan2 (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 20 } */ cbrt (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 22 } */ ceil (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 24 } */ copysign (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 26 } */ cos (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 28 } */ cosh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 30 } */ erf (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 32 } */ erfc (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 34 } */ exp (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 36 } */ exp2 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 38 } */ expm1 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 40 } */ fabs (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 42 } */ fdim (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 44 } */ floor (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 46 } */ fma (d, d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 48 } */ fmax (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 50 } */ fmin (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 52 } */ fmod (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 54 } */ frexp (d, ex); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 56 } */ hypot (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 58 } */ /* We don't generate the warning for ilogb. */ ilogb (d); ldexp (d, *ex); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 62 } */ lgamma (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 64 } */ llrint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 66 } */ llround (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 68 } */ log (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 70 } */ log10 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 72 } */ log1p (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 74 } */ log2 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 76 } */ logb (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 78 } */ lrint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 80 } */ lround (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 82 } */ modf (d, dp); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 84 } */ nan (""); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 86 } */ nearbyint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 88 } */ nextafter (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 90 } */ nexttoward (d, 20.0L); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 92 } */ pow (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 94 } */ remainder (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 96 } */ remquo (d, d, ex); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 98 } */ rint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 100 } */ round (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 102 } */ scalbln (d, 100L); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 104 } */ scalbn (d, 100); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 106 } */ sin (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 108 } */ sinh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 110 } */ sincos (d, dp, dp); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 112 } */ sqrt (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 114 } */ tan (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 116 } */ tanh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 118 } */ tgamma (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 120 } */ trunc (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 122 } */ }
int main( void ) { const int bits_per_float = 24; const int mantissa_size = 52; const int bias = 1023; int currentp = -1; //-1 is 2/pi, -2 would be 1/pi int nextp = currentp - 1; int offset = 0; uint64_t mantissa = 0; int i, bit; union { uint64_t u; double d; }value, exponent, startExp, expstep; long double v = 0; long double test = 2.0L/3.14159265358979323846264338327950288L; startExp.u = mantissa_size + currentp - bits_per_float; expstep.u = bias - bits_per_float; startExp.u += bias; startExp.u <<= mantissa_size; expstep.u <<= mantissa_size; // startExp.u &= 0x7ff0000000000000ULL; startExp.u = 5; // stick a simple constant in there for gdb testing -- jsm expstep.u &= 0x7ff0000000000000ULL; /* put a breakpoint here */ while( currentp + bias > 0 ) { //set up exponent value.u = 0; for( i = 0; i < bits_per_float; i++ ) { bit = get_bit( offset++ ); if( bit < 0 ) goto exit; value.u = value.u << 1; value.u |= bit; nextp--; } value.u |= startExp.u; value.d -= startExp.d; v += value.d; printf( "0x1.%13.13llxp%d, //%17.21g (%17.21g, %17.21g, %17.21g) %17.21g\n", value.u & 0x000FFFFFFFFFFFFFULL, ilogb(value.d), value.d, (double) test, (double) v, (double) (test - v), expstep.d ); startExp.d *= expstep.d; } exit: return 0; }
EXPORT_C double fma(double x, double y, double z) { #ifndef __SYMBIAN32__ static const double split = 0x1p27 + 1.0; #else static const double split = 134217729; #endif //__SYMBIAN32__ double xs, ys, zs; double c, cc, hx, hy, p, q, tx, ty; double r, rr, s; int oround; int ex, ey, ez; int spread; if (z == 0.0) return (x * y); if (x == 0.0 || y == 0.0) return (x * y + z); /* Results of frexp() are undefined for these cases. */ if (!isfinite(x) || !isfinite(y) || !isfinite(z)) return (x * y + z); xs = frexp(x, &ex); ys = frexp(y, &ey); zs = frexp(z, &ez); oround = fegetround(); spread = ex + ey - ez; /* * If x * y and z are many orders of magnitude apart, the scaling * will overflow, so we handle these cases specially. Rounding * modes other than FE_TONEAREST are painful. */ if (spread > DBL_MANT_DIG * 2) { fenv_t env; feraiseexcept(FE_INEXACT); switch(oround) { case FE_TONEAREST: return (x * y); case FE_TOWARDZERO: if (x > 0.0 ^ y < 0.0 ^ z < 0.0) return (x * y); feholdexcept(&env); r = x * y; if (!fetestexcept(FE_INEXACT)) r = nextafter(r, 0); feupdateenv(&env); return (r); case FE_DOWNWARD: if (z > 0.0) return (x * y); feholdexcept(&env); r = x * y; if (!fetestexcept(FE_INEXACT)) r = nextafter(r, -INFINITY); feupdateenv(&env); return (r); default: /* FE_UPWARD */ if (z < 0.0) return (x * y); feholdexcept(&env); r = x * y; if (!fetestexcept(FE_INEXACT)) r = nextafter(r, INFINITY); feupdateenv(&env); return (r); } } if (spread < -DBL_MANT_DIG) { feraiseexcept(FE_INEXACT); if (!isnormal(z)) feraiseexcept(FE_UNDERFLOW); switch (oround) { case FE_TONEAREST: return (z); case FE_TOWARDZERO: if (x > 0.0 ^ y < 0.0 ^ z < 0.0) return (z); else return (nextafter(z, 0)); case FE_DOWNWARD: if (x > 0.0 ^ y < 0.0) return (z); else return (nextafter(z, -INFINITY)); default: /* FE_UPWARD */ if (x > 0.0 ^ y < 0.0) return (nextafter(z, INFINITY)); else return (z); } } /* * Use Dekker's algorithm to perform the multiplication and * subsequent addition in twice the machine precision. * Arrange so that x * y = c + cc, and x * y + z = r + rr. */ fesetround(FE_TONEAREST); p = xs * split; hx = xs - p; hx += p; tx = xs - hx; p = ys * split; hy = ys - p; hy += p; ty = ys - hy; p = hx * hy; q = hx * ty + tx * hy; c = p + q; cc = p - c + q + tx * ty; zs = ldexp(zs, -spread); r = c + zs; s = r - c; rr = (c - (r - s)) + (zs - s) + cc; spread = ex + ey; if (spread + ilogb(r) > -1023) { fesetround(oround); r = r + rr; } else { /* * The result is subnormal, so we round before scaling to * avoid double rounding. */ #ifndef __SYMBIAN32__ p = ldexp(copysign(0x1p-1022, r), -spread); #else p = ldexp(copysign(0, r), -spread); #endif //__SYMBIAN32__ c = r + p; s = c - r; cc = (r - (c - s)) + (p - s) + rr; fesetround(oround); r = (c + cc) - p; } return (ldexp(r, spread)); }
void domath (void) { #ifndef NO_DOUBLE double f1; double f2; int i1; f1 = acos (0.0); fprintf( stdout, "acos : %f\n", f1); f1 = acosh (0.0); fprintf( stdout, "acosh : %f\n", f1); f1 = asin (1.0); fprintf( stdout, "asin : %f\n", f1); f1 = asinh (1.0); fprintf( stdout, "asinh : %f\n", f1); f1 = atan (M_PI_4); fprintf( stdout, "atan : %f\n", f1); f1 = atan2 (2.3, 2.3); fprintf( stdout, "atan2 : %f\n", f1); f1 = atanh (1.0); fprintf( stdout, "atanh : %f\n", f1); f1 = cbrt (27.0); fprintf( stdout, "cbrt : %f\n", f1); f1 = ceil (3.5); fprintf( stdout, "ceil : %f\n", f1); f1 = copysign (3.5, -2.5); fprintf( stdout, "copysign : %f\n", f1); f1 = cos (M_PI_2); fprintf( stdout, "cos : %f\n", f1); f1 = cosh (M_PI_2); fprintf( stdout, "cosh : %f\n", f1); f1 = erf (42.0); fprintf( stdout, "erf : %f\n", f1); f1 = erfc (42.0); fprintf( stdout, "erfc : %f\n", f1); f1 = exp (0.42); fprintf( stdout, "exp : %f\n", f1); f1 = exp2 (0.42); fprintf( stdout, "exp2 : %f\n", f1); f1 = expm1 (0.00042); fprintf( stdout, "expm1 : %f\n", f1); f1 = fabs (-1.123); fprintf( stdout, "fabs : %f\n", f1); f1 = fdim (1.123, 2.123); fprintf( stdout, "fdim : %f\n", f1); f1 = floor (0.5); fprintf( stdout, "floor : %f\n", f1); f1 = floor (-0.5); fprintf( stdout, "floor : %f\n", f1); f1 = fma (2.1, 2.2, 3.01); fprintf( stdout, "fma : %f\n", f1); f1 = fmax (-0.42, 0.42); fprintf( stdout, "fmax : %f\n", f1); f1 = fmin (-0.42, 0.42); fprintf( stdout, "fmin : %f\n", f1); f1 = fmod (42.0, 3.0); fprintf( stdout, "fmod : %f\n", f1); /* no type-specific variant */ i1 = fpclassify(1.0); fprintf( stdout, "fpclassify : %d\n", i1); f1 = frexp (42.0, &i1); fprintf( stdout, "frexp : %f\n", f1); f1 = hypot (42.0, 42.0); fprintf( stdout, "hypot : %f\n", f1); i1 = ilogb (42.0); fprintf( stdout, "ilogb : %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 = j0 (1.2); fprintf( stdout, "j0 : %f\n", f1); f1 = j1 (1.2); fprintf( stdout, "j1 : %f\n", f1); f1 = jn (2,1.2); fprintf( stdout, "jn : %f\n", f1); f1 = ldexp (1.2,3); fprintf( stdout, "ldexp : %f\n", f1); f1 = lgamma (42.0); fprintf( stdout, "lgamma : %f\n", f1); f1 = llrint (-0.5); fprintf( stdout, "llrint : %f\n", f1); f1 = llrint (0.5); fprintf( stdout, "llrint : %f\n", f1); f1 = llround (-0.5); fprintf( stdout, "lround : %f\n", f1); f1 = llround (0.5); fprintf( stdout, "lround : %f\n", f1); f1 = log (42.0); fprintf( stdout, "log : %f\n", f1); f1 = log10 (42.0); fprintf( stdout, "log10 : %f\n", f1); f1 = log1p (42.0); fprintf( stdout, "log1p : %f\n", f1); f1 = log2 (42.0); fprintf( stdout, "log2 : %f\n", f1); f1 = logb (42.0); fprintf( stdout, "logb : %f\n", f1); f1 = lrint (-0.5); fprintf( stdout, "lrint : %f\n", f1); f1 = lrint (0.5); fprintf( stdout, "lrint : %f\n", f1); f1 = lround (-0.5); fprintf( stdout, "lround : %f\n", f1); f1 = lround (0.5); fprintf( stdout, "lround : %f\n", f1); f1 = modf (42.0,&f2); fprintf( stdout, "lmodf : %f\n", f1); f1 = nan (""); fprintf( stdout, "nan : %f\n", f1); f1 = nearbyint (1.5); fprintf( stdout, "nearbyint : %f\n", f1); f1 = nextafter (1.5,2.0); fprintf( stdout, "nextafter : %f\n", f1); f1 = pow (3.01, 2.0); fprintf( stdout, "pow : %f\n", f1); f1 = remainder (3.01,2.0); fprintf( stdout, "remainder : %f\n", f1); f1 = remquo (29.0,3.0,&i1); fprintf( stdout, "remquo : %f\n", f1); f1 = rint (0.5); fprintf( stdout, "rint : %f\n", f1); f1 = rint (-0.5); fprintf( stdout, "rint : %f\n", f1); f1 = round (0.5); fprintf( stdout, "round : %f\n", f1); f1 = round (-0.5); fprintf( stdout, "round : %f\n", f1); f1 = scalbln (1.2,3); fprintf( stdout, "scalbln : %f\n", f1); f1 = scalbn (1.2,3); fprintf( stdout, "scalbn : %f\n", f1); /* no type-specific variant */ i1 = signbit(1.0); fprintf( stdout, "signbit : %i\n", i1); f1 = sin (M_PI_4); fprintf( stdout, "sin : %f\n", f1); f1 = sinh (M_PI_4); fprintf( stdout, "sinh : %f\n", f1); f1 = sqrt (9.0); fprintf( stdout, "sqrt : %f\n", f1); f1 = tan (M_PI_4); fprintf( stdout, "tan : %f\n", f1); f1 = tanh (M_PI_4); fprintf( stdout, "tanh : %f\n", f1); f1 = tgamma (2.1); fprintf( stdout, "tgamma : %f\n", f1); f1 = trunc (3.5); fprintf( stdout, "trunc : %f\n", f1); f1 = y0 (1.2); fprintf( stdout, "y0 : %f\n", f1); f1 = y1 (1.2); fprintf( stdout, "y1 : %f\n", f1); f1 = yn (3,1.2); fprintf( stdout, "yn : %f\n", f1); #endif }