CFLOAT M_DECL_FUNC (__csin) (CFLOAT x) { CFLOAT retval; int negate = signbit (__real__ x); int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); __real__ x = M_FABS (__real__ x); if (__glibc_likely (icls >= FP_ZERO)) { /* Imaginary part is finite. */ if (__glibc_likely (rcls >= FP_ZERO)) { /* Real part is finite. */ const int t = (int) ((M_MAX_EXP - 1) * M_MLIT (M_LN2)); FLOAT sinix, cosix; if (__glibc_likely (__real__ x > M_MIN)) { M_SINCOS (__real__ x, &sinix, &cosix); } else { sinix = __real__ x; cosix = 1; } if (negate) sinix = -sinix; if (M_FABS (__imag__ x) > t) { FLOAT exp_t = M_EXP (t); FLOAT ix = M_FABS (__imag__ x); if (signbit (__imag__ x)) cosix = -cosix; ix -= t; sinix *= exp_t / 2; cosix *= exp_t / 2; if (ix > t) { ix -= t; sinix *= exp_t; cosix *= exp_t; } if (ix > t) { /* Overflow (original imaginary part of x > 3t). */ __real__ retval = M_MAX * sinix; __imag__ retval = M_MAX * cosix; } else { FLOAT exp_val = M_EXP (ix); __real__ retval = exp_val * sinix; __imag__ retval = exp_val * cosix; } } else { __real__ retval = M_COSH (__imag__ x) * sinix; __imag__ retval = M_SINH (__imag__ x) * cosix; } math_check_force_underflow_complex (retval); } else { if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = __real__ x - __real__ x; __imag__ retval = __imag__ x; } else { __real__ retval = M_NAN; __imag__ retval = M_NAN; feraiseexcept (FE_INVALID); } } } else if (icls == FP_INFINITE) { /* Imaginary part is infinite. */ if (rcls == FP_ZERO) { /* Real part is 0.0. */ __real__ retval = M_COPYSIGN (0, negate ? -1 : 1); __imag__ retval = __imag__ x; } else if (rcls > FP_ZERO) { /* Real part is finite. */ FLOAT sinix, cosix; if (__glibc_likely (__real__ x > M_MIN)) { M_SINCOS (__real__ x, &sinix, &cosix); } else { sinix = __real__ x; cosix = 1; } __real__ retval = M_COPYSIGN (M_HUGE_VAL, sinix); __imag__ retval = M_COPYSIGN (M_HUGE_VAL, cosix); if (negate) __real__ retval = -__real__ retval; if (signbit (__imag__ x)) __imag__ retval = -__imag__ retval; } else { __real__ retval = __real__ x - __real__ x; __imag__ retval = M_HUGE_VAL; } } else { if (rcls == FP_ZERO) __real__ retval = M_COPYSIGN (0, negate ? -1 : 1); else __real__ retval = M_NAN; __imag__ retval = M_NAN; } return retval; }
__complex__ long double __catanl (__complex__ long double x) { __complex__ long double res; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls <= FP_INFINITE || icls <= FP_INFINITE, 0)) { if (rcls == FP_INFINITE) { __real__ res = __copysignl (M_PI_2l, __real__ x); __imag__ res = __copysignl (0.0, __imag__ x); } else if (icls == FP_INFINITE) { if (rcls >= FP_ZERO) __real__ res = __copysignl (M_PI_2l, __real__ x); else __real__ res = __nanl (""); __imag__ res = __copysignl (0.0, __imag__ x); } else if (icls == FP_ZERO || icls == FP_INFINITE) { __real__ res = __nanl (""); __imag__ res = __copysignl (0.0, __imag__ x); } else { __real__ res = __nanl (""); __imag__ res = __nanl (""); } } else if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0)) { res = x; } else { if (fabsl (__real__ x) >= 16.0L / LDBL_EPSILON || fabsl (__imag__ x) >= 16.0L / LDBL_EPSILON) { __real__ res = __copysignl (M_PI_2l, __real__ x); if (fabsl (__real__ x) <= 1.0L) __imag__ res = 1.0L / __imag__ x; else if (fabsl (__imag__ x) <= 1.0L) __imag__ res = __imag__ x / __real__ x / __real__ x; else { long double h = __ieee754_hypotl (__real__ x / 2.0L, __imag__ x / 2.0L); __imag__ res = __imag__ x / h / h / 4.0L; } } else { long double den, absx, absy; absx = fabsl (__real__ x); absy = fabsl (__imag__ x); if (absx < absy) { long double t = absx; absx = absy; absy = t; } if (absy < LDBL_EPSILON / 2.0L) den = (1.0L - absx) * (1.0L + absx); else if (absx >= 1.0L) den = (1.0L - absx) * (1.0L + absx) - absy * absy; else if (absx >= 0.75L || absy >= 0.5L) den = -__x2y2m1l (absx, absy); else den = (1.0L - absx) * (1.0L + absx) - absy * absy; __real__ res = 0.5L * __ieee754_atan2l (2.0L * __real__ x, den); if (fabsl (__imag__ x) == 1.0L && fabsl (__real__ x) < LDBL_EPSILON * LDBL_EPSILON) __imag__ res = (__copysignl (0.5L, __imag__ x) * (M_LN2l - __ieee754_logl (fabsl (__real__ x)))); else { long double r2 = 0.0L, num, f; if (fabsl (__real__ x) >= LDBL_EPSILON * LDBL_EPSILON) r2 = __real__ x * __real__ x; num = __imag__ x + 1.0L; num = r2 + num * num; den = __imag__ x - 1.0L; den = r2 + den * den; f = num / den; if (f < 0.5L) __imag__ res = 0.25L * __ieee754_logl (f); else { num = 4.0L * __imag__ x; __imag__ res = 0.25L * __log1pl (num / den); } } } if (fabsl (__real__ res) < LDBL_MIN) { volatile long double force_underflow = __real__ res * __real__ res; (void) force_underflow; } if (fabsl (__imag__ res) < LDBL_MIN) { volatile long double force_underflow = __imag__ res * __imag__ res; (void) force_underflow; } } return res; }
__complex__ long double __ctanl (__complex__ long double x) { __complex__ long double res; if (__builtin_expect (!isfinite (__real__ x) || !isfinite (__imag__ x), 0)) { if (__isinf_nsl (__imag__ x)) { __real__ res = __copysignl (0.0, __real__ x); __imag__ res = __copysignl (1.0, __imag__ x); } else if (__real__ x == 0.0) { res = x; } else { __real__ res = __nanl (""); __imag__ res = __nanl (""); if (__isinf_nsl (__real__ x)) feraiseexcept (FE_INVALID); } } else { long double sinrx, cosrx; long double den; const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2); int rcls = fpclassify (__real__ x); /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y)) = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */ if (__builtin_expect (rcls != FP_SUBNORMAL, 1)) { __sincosl (__real__ x, &sinrx, &cosrx); } else { sinrx = __real__ x; cosrx = 1.0; } if (fabsl (__imag__ x) > t) { /* Avoid intermediate overflow when the real part of the result may be subnormal. Ignoring negligible terms, the imaginary part is +/- 1, the real part is sin(x)*cos(x)/sinh(y)^2 = 4*sin(x)*cos(x)/exp(2y). */ long double exp_2t = __ieee754_expl (2 * t); __imag__ res = __copysignl (1.0, __imag__ x); __real__ res = 4 * sinrx * cosrx; __imag__ x = fabsl (__imag__ x); __imag__ x -= t; __real__ res /= exp_2t; if (__imag__ x > t) { /* Underflow (original imaginary part of x has absolute value > 2t). */ __real__ res /= exp_2t; } else __real__ res /= __ieee754_expl (2 * __imag__ x); } else { long double sinhix, coshix; if (fabsl (__imag__ x) > LDBL_MIN) { sinhix = __ieee754_sinhl (__imag__ x); coshix = __ieee754_coshl (__imag__ x); } else { sinhix = __imag__ x; coshix = 1.0L; } if (fabsl (sinhix) > fabsl (cosrx) * LDBL_EPSILON) den = cosrx * cosrx + sinhix * sinhix; else den = cosrx * cosrx; __real__ res = sinrx * cosrx / den; __imag__ res = sinhix * coshix / den; } } return res; }
void conjugate_gradient_sparse(cs *A, double *b, double* x, int n, double itol) { int i,j; int iter; double rho,rho1,alpha,beta,omega; double r[n]; double z[n]; double q[n], temp_q[n]; double p[n], temp_p[n]; double res[n]; double precond[n]; //Preconditioner memset(precond, 0, n*sizeof(double)); memset(r, 0, n*sizeof(double)); memset(z, 0, n*sizeof(double)); memset(q, 0, n*sizeof(double)); memset(temp_q, 0, n*sizeof(double)); memset(p, 0, n*sizeof(double)); memset(temp_p, 0, n*sizeof(double)); /* Preconditioner */ double max; int pp; for(j = 0; j < n; ++j){ for(pp = A->p[j], max = fabs(A->x[pp]); pp < A->p[j+1]; pp++) if(fabs(A->x[pp]) > max) //vriskei to diagonio stoixeio max = fabs(A->x[pp]); precond[j] = 1/max; } cblas_dcopy (n, x, 1, res, 1); //r=b-Ax cblas_dcopy (n, b, 1, r, 1); memset(p, 0, n*sizeof(double)); cs_gaxpy (A, x, p); for(i=0;i<n;i++){ r[i]=r[i]-p[i]; } double r_norm = cblas_dnrm2 (n, r, 1); double b_norm = cblas_dnrm2 (n, b, 1); if(!b_norm) b_norm = 1; iter = 0; while( r_norm/b_norm > itol && iter < n ) { iter++; cblas_dcopy (n, r, 1, z, 1); //gia na min allaksei o r for(i=0;i<n;i++){ z[i]=precond[i]*z[i]; } rho = cblas_ddot (n, z, 1, r, 1); if (fpclassify(fabs(rho)) == FP_ZERO){ printf("RHO aborting CG due to EPS...\n"); exit(42); } if (iter == 1){ cblas_dcopy (n, z, 1, p, 1); } else{ beta = rho/rho1; //p = z + beta*p; cblas_dscal (n, beta, p, 1); //rescale cblas_daxpy (n, 1, z, 1, p, 1); //p = 1*z + p } rho1 = rho; //q = Ap memset(q, 0, n*sizeof(double)); cs_gaxpy (A, p, q); omega = cblas_ddot (n, p, 1, q, 1); if (fpclassify(fabs(omega)) == FP_ZERO){ printf("OMEGA aborting CG due to EPS...\n"); exit(42); } alpha = rho/omega; //x = x + aplha*p; cblas_dcopy (n, p, 1, temp_p, 1); cblas_dscal (n, alpha, temp_p, 1);//rescale by alpha cblas_daxpy (n, 1, temp_p, 1, res, 1);// sum x = 1*x + temp_p //r = r - aplha*q; cblas_dcopy (n, q, 1, temp_q, 1); cblas_dscal (n, -alpha, temp_q, 1);//rescale by alpha cblas_daxpy (n, 1, temp_q, 1, r, 1);// sum r = 1*r - temp_p //next step r_norm = cblas_dnrm2 (n, r, 1); } cblas_dcopy (n, res, 1, x, 1); }
inline int fpclassify BOOST_NO_MACRO_EXPAND(float t) { return BOOST_FPCLASSIFY_PREFIX fpclassify(t); }
__complex__ long double __clog10l (__complex__ long double x) { __complex__ long double result; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0)) { /* Real and imaginary part are 0.0. */ __imag__ result = signbit (__real__ x) ? M_PIl : 0.0; __imag__ result = __copysignl (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabsl (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ long double absx = fabsl (__real__ x), absy = fabsl (__imag__ x); int scale = 0; if (absx < absy) { long double t = absx; absx = absy; absy = t; } if (absx > LDBL_MAX / 2.0L) { scale = -1; absx = __scalbnl (absx, scale); absy = (absy >= LDBL_MIN * 2.0L ? __scalbnl (absy, scale) : 0.0L); } else if (absx < LDBL_MIN && absy < LDBL_MIN) { scale = LDBL_MANT_DIG; absx = __scalbnl (absx, scale); absy = __scalbnl (absy, scale); } if (absx == 1.0L && scale == 0) { long double absy2 = absy * absy; if (absy2 <= LDBL_MIN * 2.0L * M_LN10l) __real__ result = (absy2 / 2.0L - absy2 * absy2 / 4.0L) * M_LOG10El; else __real__ result = __log1pl (absy2) * (M_LOG10El / 2.0L); } else if (absx > 1.0L && absx < 2.0L && absy < 1.0L && scale == 0) { long double d2m1 = (absx - 1.0L) * (absx + 1.0L); if (absy >= LDBL_EPSILON) d2m1 += absy * absy; __real__ result = __log1pl (d2m1) * (M_LOG10El / 2.0L); } else if (absx < 1.0L && absx >= 0.75L && absy < LDBL_EPSILON / 2.0L && scale == 0) { long double d2m1 = (absx - 1.0L) * (absx + 1.0L); __real__ result = __log1pl (d2m1) * (M_LOG10El / 2.0L); } else if (absx < 1.0L && (absx >= 0.75L || absy >= 0.5L) && scale == 0) { long double d2m1 = __x2y2m1l (absx, absy); __real__ result = __log1pl (d2m1) * (M_LOG10El / 2.0L); } else { long double d = __ieee754_hypotl (absx, absy); __real__ result = __ieee754_log10l (d) - scale * M_LOG10_2l; } __imag__ result = M_LOG10El * __ieee754_atan2l (__imag__ x, __real__ x); } else { __imag__ result = __nanl (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VALL; else __real__ result = __nanl (""); } return result; }
__complex__ float __csinhf (__complex__ float x) { __complex__ float retval; int negate = signbit (__real__ x); int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); __real__ x = fabsf (__real__ x); if (__builtin_expect (rcls >= FP_ZERO, 1)) { /* Real part is finite. */ if (__builtin_expect (icls >= FP_ZERO, 1)) { /* Imaginary part is finite. */ const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2); float sinix, cosix; if (__builtin_expect (icls != FP_SUBNORMAL, 1)) { __sincosf (__imag__ x, &sinix, &cosix); } else { sinix = __imag__ x; cosix = 1.0f; } if (fabsf (__real__ x) > t) { float exp_t = __ieee754_expf (t); float rx = fabsf (__real__ x); if (signbit (__real__ x)) cosix = -cosix; rx -= t; sinix *= exp_t / 2.0f; cosix *= exp_t / 2.0f; if (rx > t) { rx -= t; sinix *= exp_t; cosix *= exp_t; } if (rx > t) { /* Overflow (original real part of x > 3t). */ __real__ retval = FLT_MAX * cosix; __imag__ retval = FLT_MAX * sinix; } else { float exp_val = __ieee754_expf (rx); __real__ retval = exp_val * cosix; __imag__ retval = exp_val * sinix; } } else { __real__ retval = __ieee754_sinhf (__real__ x) * cosix; __imag__ retval = __ieee754_coshf (__real__ x) * sinix; } if (negate) __real__ retval = -__real__ retval; if (fabsf (__real__ retval) < FLT_MIN) { volatile float force_underflow = __real__ retval * __real__ retval; (void) force_underflow; } if (fabsf (__imag__ retval) < FLT_MIN) { volatile float force_underflow = __imag__ retval * __imag__ retval; (void) force_underflow; } } else { if (rcls == FP_ZERO) { /* Real part is 0.0. */ __real__ retval = __copysignf (0.0, negate ? -1.0 : 1.0); __imag__ retval = __nanf ("") + __nanf (""); if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); } else { __real__ retval = __nanf (""); __imag__ retval = __nanf (""); feraiseexcept (FE_INVALID); } } } else if (__builtin_expect (rcls == FP_INFINITE, 1)) { /* Real part is infinite. */ if (__builtin_expect (icls > FP_ZERO, 1)) { /* Imaginary part is finite. */ float sinix, cosix; if (__builtin_expect (icls != FP_SUBNORMAL, 1)) { __sincosf (__imag__ x, &sinix, &cosix); } else { sinix = __imag__ x; cosix = 1.0f; } __real__ retval = __copysignf (HUGE_VALF, cosix); __imag__ retval = __copysignf (HUGE_VALF, sinix); if (negate) __real__ retval = -__real__ retval; } else if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = negate ? -HUGE_VALF : HUGE_VALF; __imag__ retval = __imag__ x; } else { /* The addition raises the invalid exception. */ __real__ retval = HUGE_VALF; __imag__ retval = __nanf ("") + __nanf (""); #ifdef FE_INVALID if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); #endif } } else { __real__ retval = __nanf (""); __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nanf (""); } return retval; }
int main(void) { assert(fpclassify((float)0) == FP_ZERO); assert(fpclassify((float)-0.0) == FP_ZERO); assert(fpclassify((float)1) == FP_NORMAL); assert(fpclassify((float)1000) == FP_NORMAL); #ifndef __alpha__ assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL); #endif assert(fpclassify(HUGE_VALF) == FP_INFINITE); assert(fpclassify((float)HUGE_VAL) == FP_INFINITE); assert(fpclassify((float)HUGE_VALL) == FP_INFINITE); assert(fpclassify(NAN) == FP_NAN); assert(fpclassify((double)0) == FP_ZERO); assert(fpclassify((double)-0) == FP_ZERO); assert(fpclassify((double)1) == FP_NORMAL); assert(fpclassify((double)1000) == FP_NORMAL); #ifndef __alpha__ assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL); #endif assert(fpclassify(HUGE_VAL) == FP_INFINITE); assert(fpclassify((double)HUGE_VALF) == FP_INFINITE); assert(fpclassify((double)HUGE_VALL) == FP_INFINITE); assert(fpclassify((double)NAN) == FP_NAN); assert(fpclassify((long double)0) == FP_ZERO); assert(fpclassify((long double)-0.0) == FP_ZERO); assert(fpclassify((long double)1) == FP_NORMAL); assert(fpclassify((long double)1000) == FP_NORMAL); #ifndef __alpha__ assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL); #endif assert(fpclassify(HUGE_VALL) == FP_INFINITE); assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE); assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE); assert(fpclassify((long double)NAN) == FP_NAN); printf("PASS fpclassify()\n"); exit(0); }
__complex__ long double __ccoshl (__complex__ long double x) { __complex__ long double retval; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls >= FP_ZERO, 1)) { /* Real part is finite. */ if (__builtin_expect (icls >= FP_ZERO, 1)) { /* Imaginary part is finite. */ const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l); long double sinix, cosix; __sincosl (__imag__ x, &sinix, &cosix); if (fabsl (__real__ x) > t) { long double exp_t = __ieee754_expl (t); long double rx = fabsl (__real__ x); if (signbit (__real__ x)) sinix = -sinix; rx -= t; sinix *= exp_t / 2.0L; cosix *= exp_t / 2.0L; if (rx > t) { rx -= t; sinix *= exp_t; cosix *= exp_t; } if (rx > t) { /* Overflow (original real part of x > 3t). */ __real__ retval = LDBL_MAX * cosix; __imag__ retval = LDBL_MAX * sinix; } else { long double exp_val = __ieee754_expl (rx); __real__ retval = exp_val * cosix; __imag__ retval = exp_val * sinix; } } else { __real__ retval = __ieee754_coshl (__real__ x) * cosix; __imag__ retval = __ieee754_sinhl (__real__ x) * sinix; } } else { __imag__ retval = __real__ x == 0.0 ? 0.0 : __nanl (""); __real__ retval = __nanl ("") + __nanl (""); if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); } } else if (__builtin_expect (rcls == FP_INFINITE, 1)) { /* Real part is infinite. */ if (__builtin_expect (icls > FP_ZERO, 1)) { /* Imaginary part is finite. */ long double sinix, cosix; __sincosl (__imag__ x, &sinix, &cosix); __real__ retval = __copysignl (HUGE_VALL, cosix); __imag__ retval = (__copysignl (HUGE_VALL, sinix) * __copysignl (1.0, __real__ x)); } else if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = HUGE_VALL; __imag__ retval = __imag__ x * __copysignl (1.0, __real__ x); } else { /* The addition raises the invalid exception. */ __real__ retval = HUGE_VALL; __imag__ retval = __nanl ("") + __nanl (""); if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); } } else { __real__ retval = __nanl (""); __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nanl (""); } return retval; }
__complex__ float __cexpf (__complex__ float x) { __complex__ float retval; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__glibc_likely (rcls >= FP_ZERO)) { /* Real part is finite. */ if (__glibc_likely (icls >= FP_ZERO)) { /* Imaginary part is finite. */ const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2); float sinix, cosix; if (__glibc_likely (icls != FP_SUBNORMAL)) { __sincosf (__imag__ x, &sinix, &cosix); } else { sinix = __imag__ x; cosix = 1.0f; } if (__real__ x > t) { float exp_t = __ieee754_expf (t); __real__ x -= t; sinix *= exp_t; cosix *= exp_t; if (__real__ x > t) { __real__ x -= t; sinix *= exp_t; cosix *= exp_t; } } if (__real__ x > t) { /* Overflow (original real part of x > 3t). */ __real__ retval = FLT_MAX * cosix; __imag__ retval = FLT_MAX * sinix; } else { float exp_val = __ieee754_expf (__real__ x); __real__ retval = exp_val * cosix; __imag__ retval = exp_val * sinix; } if (fabsf (__real__ retval) < FLT_MIN) { volatile float force_underflow = __real__ retval * __real__ retval; (void) force_underflow; } if (fabsf (__imag__ retval) < FLT_MIN) { volatile float force_underflow = __imag__ retval * __imag__ retval; (void) force_underflow; } } else { /* If the imaginary part is +-inf or NaN and the real part is not +-inf the result is NaN + iNaN. */ __real__ retval = __nanf (""); __imag__ retval = __nanf (""); feraiseexcept (FE_INVALID); } } else if (__glibc_likely (rcls == FP_INFINITE)) { /* Real part is infinite. */ if (__glibc_likely (icls >= FP_ZERO)) { /* Imaginary part is finite. */ float value = signbit (__real__ x) ? 0.0 : HUGE_VALF; if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = value; __imag__ retval = __imag__ x; } else { float sinix, cosix; if (__glibc_likely (icls != FP_SUBNORMAL)) { __sincosf (__imag__ x, &sinix, &cosix); } else { sinix = __imag__ x; cosix = 1.0f; } __real__ retval = __copysignf (value, cosix); __imag__ retval = __copysignf (value, sinix); } } else if (signbit (__real__ x) == 0) { __real__ retval = HUGE_VALF; __imag__ retval = __nanf (""); if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); } else { __real__ retval = 0.0; __imag__ retval = __copysignf (0.0, __imag__ x); } } else { /* If the real part is NaN the result is NaN + iNaN unless the imaginary part is zero. */ __real__ retval = __nanf (""); if (icls == FP_ZERO) __imag__ retval = __imag__ x; else { __imag__ retval = __nanf (""); if (rcls != FP_NAN || icls != FP_NAN) feraiseexcept (FE_INVALID); } } return retval; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void integralz_func(scicos_block *block, int flag) { int i = 0; double *ur = NULL, *ui = NULL; double *yr = NULL, *yi = NULL; ur = GetRealInPortPtrs(block, 1); ui = GetImagInPortPtrs(block, 1); yr = GetRealOutPortPtrs(block, 1); yi = GetImagOutPortPtrs(block, 1); if (flag == 0) { if (block->ng > 0) { for (i = 0; i < (block->nx) / 2; ++i) { if (block->mode[i] == 3) { block->xd[i] = ur[i]; block->xd[i + (block->nx) / 2] = ui[i]; } else { block->xd[i] = 0.0; block->xd[i + (block->nx) / 2] = 0.0; } } } else { for (i = 0; i < (block->nx) / 2; ++i) { block->xd[i] = ur[i]; block->xd[i + (block->nx) / 2] = ui[i]; } } } else if (flag == 1 || flag == 6) { for (i = 0; i < (block->nx) / 2; ++i) { yr[i] = block->x[i]; yi[i] = block->x[i + (block->nx) / 2]; } } else if (flag == 2 && block->nevprt == 1) { for (i = 0; i < (block->nx) / 2; ++i) { block->x[i] = ur[i]; block->x[i + (block->nx) / 2] = ui[i]; } } else if (flag == 9) { for (i = 0; i < (block->nx) / 2; ++i) { if (block->mode[i] == 3) { block->g[i] = (block->x[i] - (block->rpar[i])) * (block->x[i] - (block->rpar[(block->nx) / 2 + i])); block->g[i + (block->nx) / 2] = (block->x[i + (block->nx) / 2] - (block->rpar[i + (block->nx)])) * (block->x[i + (block->nx) / 2] - (block->rpar[3 * (block->nx) / 2 + i])); } else { block->g[i] = ur[i]; block->g[i + (block->nx) / 2] = ui[i]; } if (get_phase_simulation() == 1) { if ((ur[i] >= 0) && (block->x[i] >= block->rpar[i]) && (fpclassify(ui[i >= 0]) != FP_ZERO) && (block->x[i + (block->nx) / 2] >= block->rpar[i + (block->nx)])) { block->mode[i] = 1; } else if (ur[i] <= 0 && block->x[i] <= block->rpar[(block->nx) / 2 + i] && ui[i] <= 0 && block->x[i + (block->nx) / 2] <= block->rpar[3 * (block->nx) / 2 + i]) { block->mode[i] = 2; } else { block->mode[i] = 3; } } } } }
CFLOAT M_DECL_FUNC (__catanh) (CFLOAT x) { CFLOAT res; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__glibc_unlikely (rcls <= FP_INFINITE || icls <= FP_INFINITE)) { if (icls == FP_INFINITE) { __real__ res = M_COPYSIGN (0, __real__ x); __imag__ res = M_COPYSIGN (M_MLIT (M_PI_2), __imag__ x); } else if (rcls == FP_INFINITE || rcls == FP_ZERO) { __real__ res = M_COPYSIGN (0, __real__ x); if (icls >= FP_ZERO) __imag__ res = M_COPYSIGN (M_MLIT (M_PI_2), __imag__ x); else __imag__ res = M_NAN; } else { __real__ res = M_NAN; __imag__ res = M_NAN; } } else if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO)) { res = x; } else { if (M_FABS (__real__ x) >= 16 / M_EPSILON || M_FABS (__imag__ x) >= 16 / M_EPSILON) { __imag__ res = M_COPYSIGN (M_MLIT (M_PI_2), __imag__ x); if (M_FABS (__imag__ x) <= 1) __real__ res = 1 / __real__ x; else if (M_FABS (__real__ x) <= 1) __real__ res = __real__ x / __imag__ x / __imag__ x; else { FLOAT h = M_HYPOT (__real__ x / 2, __imag__ x / 2); __real__ res = __real__ x / h / h / 4; } } else { if (M_FABS (__real__ x) == 1 && M_FABS (__imag__ x) < M_EPSILON * M_EPSILON) __real__ res = (M_COPYSIGN (M_LIT (0.5), __real__ x) * ((FLOAT) M_MLIT (M_LN2) - M_LOG (M_FABS (__imag__ x)))); else { FLOAT i2 = 0; if (M_FABS (__imag__ x) >= M_EPSILON * M_EPSILON) i2 = __imag__ x * __imag__ x; FLOAT num = 1 + __real__ x; num = i2 + num * num; FLOAT den = 1 - __real__ x; den = i2 + den * den; FLOAT f = num / den; if (f < M_LIT (0.5)) __real__ res = M_LIT (0.25) * M_LOG (f); else { num = 4 * __real__ x; __real__ res = M_LIT (0.25) * M_LOG1P (num / den); } } FLOAT absx, absy, den; absx = M_FABS (__real__ x); absy = M_FABS (__imag__ x); if (absx < absy) { FLOAT t = absx; absx = absy; absy = t; } if (absy < M_EPSILON / 2) { den = (1 - absx) * (1 + absx); if (den == 0) den = 0; } else if (absx >= 1) den = (1 - absx) * (1 + absx) - absy * absy; else if (absx >= M_LIT (0.75) || absy >= M_LIT (0.5)) den = -M_SUF (__x2y2m1) (absx, absy); else den = (1 - absx) * (1 + absx) - absy * absy; __imag__ res = M_LIT (0.5) * M_ATAN2 (2 * __imag__ x, den); } math_check_force_underflow_complex (res); } return res; }
__complex__ double __catanh (__complex__ double x) { __complex__ double res; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__glibc_unlikely (rcls <= FP_INFINITE || icls <= FP_INFINITE)) { if (icls == FP_INFINITE) { __real__ res = __copysign (0.0, __real__ x); __imag__ res = __copysign (M_PI_2, __imag__ x); } else if (rcls == FP_INFINITE || rcls == FP_ZERO) { __real__ res = __copysign (0.0, __real__ x); if (icls >= FP_ZERO) __imag__ res = __copysign (M_PI_2, __imag__ x); else __imag__ res = __nan (""); } else { __real__ res = __nan (""); __imag__ res = __nan (""); } } else if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO)) { res = x; } else { if (fabs (__real__ x) >= 16.0 / DBL_EPSILON || fabs (__imag__ x) >= 16.0 / DBL_EPSILON) { __imag__ res = __copysign (M_PI_2, __imag__ x); if (fabs (__imag__ x) <= 1.0) __real__ res = 1.0 / __real__ x; else if (fabs (__real__ x) <= 1.0) __real__ res = __real__ x / __imag__ x / __imag__ x; else { double h = __ieee754_hypot (__real__ x / 2.0, __imag__ x / 2.0); __real__ res = __real__ x / h / h / 4.0; } } else { if (fabs (__real__ x) == 1.0 && fabs (__imag__ x) < DBL_EPSILON * DBL_EPSILON) __real__ res = (__copysign (0.5, __real__ x) * (M_LN2 - __ieee754_log (fabs (__imag__ x)))); else { double i2 = 0.0; if (fabs (__imag__ x) >= DBL_EPSILON * DBL_EPSILON) i2 = __imag__ x * __imag__ x; double num = 1.0 + __real__ x; num = i2 + num * num; double den = 1.0 - __real__ x; den = i2 + den * den; double f = num / den; if (f < 0.5) __real__ res = 0.25 * __ieee754_log (f); else { num = 4.0 * __real__ x; __real__ res = 0.25 * __log1p (num / den); } } double absx, absy, den; absx = fabs (__real__ x); absy = fabs (__imag__ x); if (absx < absy) { double t = absx; absx = absy; absy = t; } if (absy < DBL_EPSILON / 2.0) { den = (1.0 - absx) * (1.0 + absx); if (den == -0.0) den = 0.0; } else if (absx >= 1.0) den = (1.0 - absx) * (1.0 + absx) - absy * absy; else if (absx >= 0.75 || absy >= 0.5) den = -__x2y2m1 (absx, absy); else den = (1.0 - absx) * (1.0 + absx) - absy * absy; __imag__ res = 0.5 * __ieee754_atan2 (2.0 * __imag__ x, den); } math_check_force_underflow_complex (res); } return res; }
_f_int4 _FP_CLASS_I4_R(_f_real8 x) { #if defined(__mips) || (defined(_LITTLE_ENDIAN) && defined(__sv2)) int x_result; x_result = fp_class_d(x); switch(x_result) { case FP_NEG_ZERO: { return (FOR_K_FP_NEG_ZERO); break; } case FP_POS_ZERO: { return (FOR_K_FP_POS_ZERO); break; } case FP_NEG_DENORM: { return (FOR_K_FP_NEG_DENORM); break; } case FP_POS_DENORM: { return (FOR_K_FP_POS_DENORM); break; } case FP_NEG_INF: { return (FOR_K_FP_NEG_INF); break; } case FP_SNAN: { return (FOR_K_FP_SNAN); break; } case FP_QNAN: { return (FOR_K_FP_QNAN); break; } case FP_POS_INF: { return (FOR_K_FP_POS_INF); break; } case FP_NEG_NORM: { return (FOR_K_FP_NEG_NORM); break; } case FP_POS_NORM: { return (FOR_K_FP_POS_NORM); break; } default: { return -1; break; } } /* Switch(x_result) */ #elif (defined(_CRAYIEEE) && !defined(__mips)) || defined(_SOLARIS) /* if we must call fpclassify */ int x_result; union _uval_r x_val; x_result = fpclassify(x); x_val.dwd = x; switch(x_result) { case FP_ZERO: { /* Test for pos/neg */ if(x_val.parts.sign) { return (FOR_K_FP_NEG_ZERO); } else { return (FOR_K_FP_POS_ZERO); } break; } case FP_SUBNORMAL: { /* Test for pos/neg */ if(x_val.parts.sign) { return (FOR_K_FP_NEG_DENORM); } else { return (FOR_K_FP_POS_DENORM); } break; } case FP_INFINITE: { /* Test for pos/neg */ if(x_val.parts.sign) { return (FOR_K_FP_NEG_INF); } else { return (FOR_K_FP_POS_INF); } break; } case FP_NAN: { #ifdef _CRAYT3E /* on the t3e, all NaNs are signal NaNs */ return (FOR_K_FP_SNAN); #else /* test for quiet/signal on others */ if(x_val.parts.q_bit) { return (FOR_K_FP_QNAN); } else { return (FOR_K_FP_SNAN); } #endif /* #ifdef _CRAYT3E */ break; } case FP_NORMAL: { /* Test for pos/neg */ if(x_val.parts.sign) { return (FOR_K_FP_NEG_NORM); } else { return (FOR_K_FP_POS_NORM); } break; } default: { return -1; break; } } /* End switch(x_result); */ #elif defined(_LITTLE_ENDIAN) && !defined(__sv2) union _uval_r x_val; x_val.dwd = x; if(x_val.parts.exp == 0) { if(x_val.parts.up == 0 && x_val.parts.lo == 0 && x_val.parts.q_bit == 0) { if(x_val.parts.sign) return (FOR_K_FP_NEG_ZERO); else return (FOR_K_FP_POS_ZERO); } else { if(x_val.parts.sign) return (FOR_K_FP_NEG_DENORM); else return (FOR_K_FP_POS_DENORM); } } else if(x_val.parts.exp == IEEE_64_EXPO_MAX) { if(x_val.parts.up == 0 && x_val.parts.lo == 0 && x_val.parts.q_bit == 0) { if(x_val.parts.sign) return (FOR_K_FP_NEG_INF); else return (FOR_K_FP_POS_INF); } else { if(x_val.parts.q_bit) return (FOR_K_FP_QNAN); else return (FOR_K_FP_SNAN); } } else if(x_val.parts.sign) return (FOR_K_FP_NEG_NORM); else return (FOR_K_FP_POS_NORM); #endif /* #if defined(__mips) ... #elif defined(_CRAYT3E) && defined(__mips) */ return -1; }
/* * ldtoa() is a wrapper for gdtoa() that makes it smell like dtoa(), * except that the floating point argument is passed by reference. * When dtoa() is passed a NaN or infinity, it sets expt to 9999. * However, a long double could have a valid exponent of 9999, so we * use INT_MAX in ldtoa() instead. */ char * __ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign, char **rve) { FPI fpi = { LDBL_MANT_DIG, /* nbits */ LDBL_MIN_EXP - LDBL_MANT_DIG, /* emin */ LDBL_MAX_EXP - LDBL_MANT_DIG, /* emax */ FLT_ROUNDS, /* rounding */ #ifdef Sudden_Underflow /* unused, but correct anyway */ 1 #else 0 #endif }; int be, kind; char *ret; struct ieee_ext *p = (struct ieee_ext *)ld; uint32_t bits[(LDBL_MANT_DIG + 31) / 32]; void *vbits = bits; /* * gdtoa doesn't know anything about the sign of the number, so * if the number is negative, we need to swap rounding modes of * 2 (upwards) and 3 (downwards). */ *sign = p->ext_sign; fpi.rounding ^= (fpi.rounding >> 1) & p->ext_sign; be = p->ext_exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1); EXT_TO_ARRAY32(p, bits); switch (fpclassify(*ld)) { case FP_NORMAL: kind = STRTOG_Normal; #ifdef EXT_IMPLICIT_NBIT bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32); #endif /* EXT_IMPLICIT_NBIT */ break; case FP_ZERO: kind = STRTOG_Zero; break; case FP_SUBNORMAL: kind = STRTOG_Denormal; be++; break; case FP_INFINITE: kind = STRTOG_Infinite; break; case FP_NAN: kind = STRTOG_NaN; break; default: abort(); } ret = gdtoa(&fpi, be, vbits, &kind, mode, ndigits, decpt, rve); if (*decpt == -32768) *decpt = INT_MAX; return ret; }
__complex__ long double __csinl (__complex__ long double x) { __complex__ long double retval; int negate = signbit (__real__ x); int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); __real__ x = fabsl (__real__ x); if (__glibc_likely (icls >= FP_ZERO)) { /* Imaginary part is finite. */ if (__glibc_likely (rcls >= FP_ZERO)) { /* Real part is finite. */ const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l); long double sinix, cosix; if (__glibc_likely (__real__ x > LDBL_MIN)) { __sincosl (__real__ x, &sinix, &cosix); } else { sinix = __real__ x; cosix = 1.0; } if (negate) sinix = -sinix; if (fabsl (__imag__ x) > t) { long double exp_t = __ieee754_expl (t); long double ix = fabsl (__imag__ x); if (signbit (__imag__ x)) cosix = -cosix; ix -= t; sinix *= exp_t / 2.0L; cosix *= exp_t / 2.0L; if (ix > t) { ix -= t; sinix *= exp_t; cosix *= exp_t; } if (ix > t) { /* Overflow (original imaginary part of x > 3t). */ __real__ retval = LDBL_MAX * sinix; __imag__ retval = LDBL_MAX * cosix; } else { long double exp_val = __ieee754_expl (ix); __real__ retval = exp_val * sinix; __imag__ retval = exp_val * cosix; } } else { __real__ retval = __ieee754_coshl (__imag__ x) * sinix; __imag__ retval = __ieee754_sinhl (__imag__ x) * cosix; } math_check_force_underflow_complex (retval); } else { if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = __nanl (""); __imag__ retval = __imag__ x; if (rcls == FP_INFINITE) feraiseexcept (FE_INVALID); } else { __real__ retval = __nanl (""); __imag__ retval = __nanl (""); feraiseexcept (FE_INVALID); } } } else if (icls == FP_INFINITE) { /* Imaginary part is infinite. */ if (rcls == FP_ZERO) { /* Real part is 0.0. */ __real__ retval = __copysignl (0.0, negate ? -1.0 : 1.0); __imag__ retval = __imag__ x; } else if (rcls > FP_ZERO) { /* Real part is finite. */ long double sinix, cosix; if (__glibc_likely (__real__ x > LDBL_MIN)) { __sincosl (__real__ x, &sinix, &cosix); } else { sinix = __real__ x; cosix = 1.0; } __real__ retval = __copysignl (HUGE_VALL, sinix); __imag__ retval = __copysignl (HUGE_VALL, cosix); if (negate) __real__ retval = -__real__ retval; if (signbit (__imag__ x)) __imag__ retval = -__imag__ retval; } else { /* The addition raises the invalid exception. */ __real__ retval = __nanl (""); __imag__ retval = HUGE_VALL; if (rcls == FP_INFINITE) feraiseexcept (FE_INVALID); } } else { if (rcls == FP_ZERO) __real__ retval = __copysignl (0.0, negate ? -1.0 : 1.0); else __real__ retval = __nanl (""); __imag__ retval = __nanl (""); } return retval; }
int main(int argc, char *argv[]) { double x = 0.0; if (argv) x = fpclassify((double) argc); return 0; }
__complex__ float __clogf (__complex__ float x) { __complex__ float result; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0)) { /* Real and imaginary part are 0.0. */ __imag__ result = signbit (__real__ x) ? M_PI : 0.0; __imag__ result = __copysignf (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabsf (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ float absx = fabsf (__real__ x), absy = fabsf (__imag__ x); int scale = 0; if (absx < absy) { float t = absx; absx = absy; absy = t; } if (absx > FLT_MAX / 2.0f) { scale = -1; absx = __scalbnf (absx, scale); absy = (absy >= FLT_MIN * 2.0f ? __scalbnf (absy, scale) : 0.0f); } else if (absx < FLT_MIN && absy < FLT_MIN) { scale = FLT_MANT_DIG; absx = __scalbnf (absx, scale); absy = __scalbnf (absy, scale); } if (absx == 1.0f && scale == 0) { float absy2 = absy * absy; if (absy2 <= FLT_MIN * 2.0f) { #if __FLT_EVAL_METHOD__ == 0 __real__ result = absy2 / 2.0f - absy2 * absy2 / 4.0f; #else volatile float force_underflow = absy2 * absy2 / 4.0f; __real__ result = absy2 / 2.0f - force_underflow; #endif } else __real__ result = __log1pf (absy2) / 2.0f; } else if (absx > 1.0f && absx < 2.0f && absy < 1.0f && scale == 0) { float d2m1 = (absx - 1.0f) * (absx + 1.0f); if (absy >= FLT_EPSILON) d2m1 += absy * absy; __real__ result = __log1pf (d2m1) / 2.0f; } else if (absx < 1.0f && absx >= 0.75f && absy < FLT_EPSILON / 2.0f && scale == 0) { float d2m1 = (absx - 1.0f) * (absx + 1.0f); __real__ result = __log1pf (d2m1) / 2.0f; } else if (absx < 1.0f && (absx >= 0.75f || absy >= 0.5f) && scale == 0) { float d2m1 = __x2y2m1f (absx, absy); __real__ result = __log1pf (d2m1) / 2.0f; } else { float d = __ieee754_hypotf (absx, absy); __real__ result = __ieee754_logf (d) - scale * (float) M_LN2; } __imag__ result = __ieee754_atan2f (__imag__ x, __real__ x); } else { __imag__ result = __nanf (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VALF; else __real__ result = __nanf (""); } return result; }
__complex__ double __ccosh (__complex__ double x) { __complex__ double retval; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__glibc_likely (rcls >= FP_ZERO)) { /* Real part is finite. */ if (__glibc_likely (icls >= FP_ZERO)) { /* Imaginary part is finite. */ const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2); double sinix, cosix; if (__glibc_likely (fabs (__imag__ x) > DBL_MIN)) { __sincos (__imag__ x, &sinix, &cosix); } else { sinix = __imag__ x; cosix = 1.0; } if (fabs (__real__ x) > t) { double exp_t = __ieee754_exp (t); double rx = fabs (__real__ x); if (signbit (__real__ x)) sinix = -sinix; rx -= t; sinix *= exp_t / 2.0; cosix *= exp_t / 2.0; if (rx > t) { rx -= t; sinix *= exp_t; cosix *= exp_t; } if (rx > t) { /* Overflow (original real part of x > 3t). */ __real__ retval = DBL_MAX * cosix; __imag__ retval = DBL_MAX * sinix; } else { double exp_val = __ieee754_exp (rx); __real__ retval = exp_val * cosix; __imag__ retval = exp_val * sinix; } } else { __real__ retval = __ieee754_cosh (__real__ x) * cosix; __imag__ retval = __ieee754_sinh (__real__ x) * sinix; } if (fabs (__real__ retval) < DBL_MIN) { volatile double force_underflow = __real__ retval * __real__ retval; (void) force_underflow; } if (fabs (__imag__ retval) < DBL_MIN) { volatile double force_underflow = __imag__ retval * __imag__ retval; (void) force_underflow; } } else { __imag__ retval = __real__ x == 0.0 ? 0.0 : __nan (""); __real__ retval = __nan ("") + __nan (""); if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); } } else if (rcls == FP_INFINITE) { /* Real part is infinite. */ if (__glibc_likely (icls > FP_ZERO)) { /* Imaginary part is finite. */ double sinix, cosix; if (__glibc_likely (fabs (__imag__ x) > DBL_MIN)) { __sincos (__imag__ x, &sinix, &cosix); } else { sinix = __imag__ x; cosix = 1.0; } __real__ retval = __copysign (HUGE_VAL, cosix); __imag__ retval = (__copysign (HUGE_VAL, sinix) * __copysign (1.0, __real__ x)); } else if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = HUGE_VAL; __imag__ retval = __imag__ x * __copysign (1.0, __real__ x); } else { /* The addition raises the invalid exception. */ __real__ retval = HUGE_VAL; __imag__ retval = __nan ("") + __nan (""); if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); } } else { __real__ retval = __nan (""); __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nan (""); } return retval; }
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 }
__complex__ float __csinhf (__complex__ float x) { __complex__ float retval; int negate = signbit (__real__ x); int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); __real__ x = fabsf (__real__ x); if (rcls >= FP_ZERO) { /* Real part is finite. */ if (icls >= FP_ZERO) { /* Imaginary part is finite. */ float sinh_val = __ieee754_sinhf (__real__ x); float cosh_val = __ieee754_coshf (__real__ x); float sinix, cosix; __sincosf (__imag__ x, &sinix, &cosix); __real__ retval = sinh_val * cosix; __imag__ retval = cosh_val * sinix; if (negate) __real__ retval = -__real__ retval; } else { if (rcls == FP_ZERO) { /* Real part is 0.0. */ __real__ retval = __copysignf (0.0, negate ? -1.0 : 1.0); __imag__ retval = __nanf ("") + __nanf (""); #ifdef FE_INVALID if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); #endif } else { __real__ retval = __nanf (""); __imag__ retval = __nanf (""); #ifdef FE_INVALID feraiseexcept (FE_INVALID); #endif } } } else if (rcls == FP_INFINITE) { /* Real part is infinite. */ if (icls == FP_ZERO) { /* Imaginary part is 0.0. */ __real__ retval = negate ? -HUGE_VALF : HUGE_VALF; __imag__ retval = __imag__ x; } else if (icls > FP_ZERO) { /* Imaginary part is finite. */ float sinix, cosix; __sincosf (__imag__ x, &sinix, &cosix); __real__ retval = __copysignf (HUGE_VALF, cosix); __imag__ retval = __copysignf (HUGE_VALF, sinix); if (negate) __real__ retval = -__real__ retval; } else { /* The addition raises the invalid exception. */ __real__ retval = HUGE_VALF; __imag__ retval = __nanf ("") + __nanf (""); #ifdef FE_INVALID if (icls == FP_INFINITE) feraiseexcept (FE_INVALID); #endif } } else { __real__ retval = __nanf (""); __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nanf (""); } return retval; }
/* update all values to reflect mouse over image id or no data at all */ static void _metadata_view_update_values(dt_lib_module_t *self) { dt_lib_metadata_view_t *d = (dt_lib_metadata_view_t *)self->data; int32_t mouse_over_id = dt_control_get_mouse_over_id(); if (mouse_over_id == -1) { const dt_view_t *cv = dt_view_manager_get_current_view(darktable.view_manager); if(cv->view((dt_view_t*)cv) == DT_VIEW_DARKROOM) { mouse_over_id = darktable.develop->image_storage.id; } else { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select imgid from selected_images limit 1", -1, &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) mouse_over_id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); } } if(mouse_over_id >= 0) { char value[512]; char pathname[PATH_MAX]; const dt_image_t *img = dt_image_cache_read_get(darktable.image_cache, mouse_over_id); if(!img) goto fill_minuses; if(img->film_id == -1) { dt_image_cache_read_release(darktable.image_cache, img); goto fill_minuses; } /* update all metadata */ dt_image_film_roll(img, value, sizeof(value)); _metadata_update_value(d->metadata[md_internal_filmroll], value); const int tp = 512; char tooltip[tp]; snprintf(tooltip, tp, _("double click to jump to film roll\n%s"), value); g_object_set(G_OBJECT(d->metadata[md_internal_filmroll]), "tooltip-text", tooltip, (char *)NULL); snprintf(value,sizeof(value),"%d", img->id); _metadata_update_value(d->metadata[md_internal_imgid], value); snprintf(value,sizeof(value),"%d", img->group_id); _metadata_update_value(d->metadata[md_internal_groupid], value); _metadata_update_value(d->metadata[md_internal_filename], img->filename); snprintf(value,sizeof(value),"%d", img->version); _metadata_update_value(d->metadata[md_internal_version], value); gboolean from_cache = FALSE; dt_image_full_path(img->id, pathname, sizeof(pathname), &from_cache); _metadata_update_value(d->metadata[md_internal_fullpath], pathname); snprintf(value, sizeof(value), "%s", (img->flags & DT_IMAGE_LOCAL_COPY)?_("yes"):_("no")); _metadata_update_value(d->metadata[md_internal_local_copy], value); // TODO: decide if this should be removed for a release. maybe #ifdef'ing to only add it to git compiles? // the bits of the flags { #define EMPTY_FIELD '.' #define FALSE_FIELD '.' #define TRUE_FIELD '!' char *tooltip = NULL; char *flag_descriptions[] = { N_("unused"), N_("unused/deprecated"), N_("ldr"), N_("raw"), N_("hdr"), N_("marked for deletion"), N_("auto-applying presets applied"), N_("legacy flag. set for all new images"), N_("local copy"), N_("has .txt"), N_("has .wav") }; char *tooltip_parts[13] = { 0 }; int next_tooltip_part = 0; memset(value, EMPTY_FIELD, sizeof(value)); int stars = img->flags & 0x7; char *star_string = NULL; if(stars == 6) { value[0] = 'x'; tooltip_parts[next_tooltip_part++] = _("image rejected"); } else { value[0] = '0' + stars; tooltip_parts[next_tooltip_part++] = star_string = g_strdup_printf(ngettext("image has %d star", "image has %d stars", stars), stars); } if(img->flags & 8) { value[1] = TRUE_FIELD; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[0]); } else value[1] = FALSE_FIELD; if(img->flags & DT_IMAGE_THUMBNAIL_DEPRECATED) { value[2] = TRUE_FIELD; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[1]); } else value[2] = FALSE_FIELD; if(img->flags & DT_IMAGE_LDR) { value[3] = 'l'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[2]); } if(img->flags & DT_IMAGE_RAW) { value[4] = 'r'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[3]); } if(img->flags & DT_IMAGE_HDR) { value[5] = 'h'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[4]); } if(img->flags & DT_IMAGE_REMOVE) { value[6] = 'd'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[5]); } if(img->flags & DT_IMAGE_AUTO_PRESETS_APPLIED) { value[7] = 'a'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[6]); } if(img->flags & DT_IMAGE_NO_LEGACY_PRESETS) { value[8] = 'p'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[7]); } if(img->flags & DT_IMAGE_LOCAL_COPY) { value[9] = 'c'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[8]); } if(img->flags & DT_IMAGE_HAS_TXT) { value[10] = 't'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[9]); } if(img->flags & DT_IMAGE_HAS_WAV) { value[11] = 'w'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[10]); } value[12] = '\0'; tooltip = g_strjoinv("\n", tooltip_parts); _metadata_update_value(d->metadata[md_internal_flags], value); g_object_set(G_OBJECT(d->metadata[md_internal_flags]), "tooltip-text", tooltip, (char *)NULL); g_free(star_string); g_free(tooltip); #undef EMPTY_FIELD #undef FALSE_FIELD #undef TRUE_FIELD } /* EXIF */ _metadata_update_value_end(d->metadata[md_exif_model], img->exif_model); _metadata_update_value_end(d->metadata[md_exif_lens], img->exif_lens); _metadata_update_value_end(d->metadata[md_exif_maker], img->exif_maker); snprintf(value, sizeof(value), "F/%.1f", img->exif_aperture); _metadata_update_value(d->metadata[md_exif_aperture], value); if(img->exif_exposure <= 0.5) snprintf(value, sizeof(value), "1/%.0f", 1.0/img->exif_exposure); else snprintf(value, sizeof(value), "%.1f''", img->exif_exposure); _metadata_update_value(d->metadata[md_exif_exposure], value); snprintf(value, sizeof(value), "%.0f mm", img->exif_focal_length); _metadata_update_value(d->metadata[md_exif_focal_length], value); if (isnan(img->exif_focus_distance) || fpclassify(img->exif_focus_distance) == FP_ZERO) { _metadata_update_value(d->metadata[md_exif_focus_distance], NODATA_STRING); } else { snprintf(value, sizeof(value), "%.2f m", img->exif_focus_distance); _metadata_update_value(d->metadata[md_exif_focus_distance], value); } snprintf(value, sizeof(value), "%.0f", img->exif_iso); _metadata_update_value(d->metadata[md_exif_iso], value); _metadata_update_value(d->metadata[md_exif_datetime], img->exif_datetime_taken); snprintf(value, sizeof(value), "%d", img->height); _metadata_update_value(d->metadata[md_exif_height], value); snprintf(value, sizeof(value), "%d", img->width); _metadata_update_value(d->metadata[md_exif_width], value); /* XMP */ GList *res; if((res = dt_metadata_get(img->id, "Xmp.dc.title", NULL))!=NULL) { snprintf(value, sizeof(value), "%s", (char*)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_title], value); if((res = dt_metadata_get(img->id, "Xmp.dc.creator", NULL))!=NULL) { snprintf(value, sizeof(value), "%s", (char*)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_creator], value); if((res = dt_metadata_get(img->id, "Xmp.dc.rights", NULL))!=NULL) { snprintf(value, sizeof(value), "%s", (char*)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_rights], value); /* geotagging */ /* latitude */ if(isnan(img->latitude)) { _metadata_update_value(d->metadata[md_geotagging_lat], NODATA_STRING); } else { #ifdef HAVE_MAP if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *latitude = osd_latitude_str(img->latitude); _metadata_update_value(d->metadata[md_geotagging_lat], latitude); g_free(latitude); } else { #endif gchar NS = img->latitude<0?'S':'N'; snprintf(value, sizeof(value), "%c %09.6f", NS, fabs(img->latitude)); _metadata_update_value(d->metadata[md_geotagging_lat], value); #ifdef HAVE_MAP } #endif } /* longitude */ if(isnan(img->longitude)) { _metadata_update_value(d->metadata[md_geotagging_lon], NODATA_STRING); } else { #ifdef HAVE_MAP if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *longitude = osd_longitude_str(img->longitude); _metadata_update_value(d->metadata[md_geotagging_lon], longitude); g_free(longitude); } else { #endif gchar EW = img->longitude<0?'W':'E'; snprintf(value, sizeof(value), "%c %010.6f", EW, fabs(img->longitude)); _metadata_update_value(d->metadata[md_geotagging_lon], value); #ifdef HAVE_MAP } #endif } /* release img */ dt_image_cache_read_release(darktable.image_cache, img); } return; /* reset */ fill_minuses: for(int k=0; k<md_size; k++) _metadata_update_value(d->metadata[k],NODATA_STRING); }
void bi_conjugate_gradient_sparse(cs *A, double *b, double* x, int n, double itol){ int i,j,iter; double rho,rho1,alpha,beta,omega; double r[n], r_t[n]; double z[n], z_t[n]; double q[n], q_t[n], temp_q[n]; double p[n], p_t[n], temp_p[n]; double res[n]; //NA VGEI! double precond[n]; //Initializations memset(precond, 0, n*sizeof(double)); memset(r, 0, n*sizeof(double)); memset(r_t, 0, n*sizeof(double)); memset(z, 0, n*sizeof(double)); memset(z_t, 0, n*sizeof(double)); memset(q, 0, n*sizeof(double)); memset(q_t, 0, n*sizeof(double)); memset(temp_q, 0, n*sizeof(double)); memset(p, 0, n*sizeof(double)); memset(p_t, 0, n*sizeof(double)); memset(temp_p, 0, n*sizeof(double)); memset(res, 0, n*sizeof(double)); /* Preconditioner */ double max; int pp; for(j = 0; j < n; ++j){ for(pp = A->p[j], max = fabs(A->x[pp]); pp < A->p[j+1]; pp++) if(fabs(A->x[pp]) > max) //vriskei to diagonio stoixeio max = fabs(A->x[pp]); precond[j] = 1/max; } cs *AT = cs_transpose (A, 1) ; cblas_dcopy (n, x, 1, res, 1); //r=b-Ax cblas_dcopy (n, b, 1, r, 1); memset(p, 0, n*sizeof(double)); cs_gaxpy (A, x, p); for(i=0;i<n;i++){ r[i]=r[i]-p[i]; } cblas_dcopy (n, r, 1, r_t, 1); double r_norm = cblas_dnrm2 (n, r, 1); double b_norm = cblas_dnrm2 (n, b, 1); if(!b_norm) b_norm = 1; iter = 0; while( r_norm/b_norm > itol && iter < n ){ iter++; cblas_dcopy (n, r, 1, z, 1); //gia na min allaksei o r cblas_dcopy (n, r_t, 1, z_t, 1); //gia na min allaksei o r_t for(i=0;i<n;i++){ z[i]=precond[i]*z[i]; z_t[i]=precond[i]*z_t[i]; } rho = cblas_ddot (n, z, 1, r_t, 1); if (fpclassify(fabs(rho)) == FP_ZERO){ printf("RHO aborting Bi-CG due to EPS...\n"); exit(42); } if (iter == 1){ cblas_dcopy (n, z, 1, p, 1); cblas_dcopy (n, z_t, 1, p_t, 1); } else{ //p = z + beta*p; beta = rho/rho1; cblas_dscal (n, beta, p, 1); //rescale p by beta cblas_dscal (n, beta, p_t, 1); //rescale p_t by beta cblas_daxpy (n, 1, z, 1, p, 1); //p = 1*z + p cblas_daxpy (n, 1, z_t, 1, p_t, 1); //p_t = 1*z_t + p_t } rho1 = rho; //q = Ap //q_t = trans(A)*p_t memset(q, 0, n*sizeof(double)); cs_gaxpy (A, p, q); memset(q_t, 0, n*sizeof(double)); cs_gaxpy(AT, p_t, q_t); omega = cblas_ddot (n, p_t, 1, q, 1); if (fpclassify(fabs(omega)) == FP_ZERO){ printf("OMEGA aborting Bi-CG due to EPS...\n"); exit(42); } alpha = rho/omega; //x = x + aplha*p; cblas_dcopy (n, p, 1, temp_p, 1); cblas_dscal (n, alpha, temp_p, 1);//rescale by aplha cblas_daxpy (n, 1, temp_p, 1, res, 1);// sum x = 1*x + temp_p //R = R - aplha*Q; cblas_dcopy (n, q, 1, temp_q, 1); cblas_dscal (n, -alpha, temp_q, 1);//rescale by -aplha cblas_daxpy (n, 1, temp_q, 1, r, 1);// sum r = 1*r - temp_p //~r=~r-alpha*~q cblas_dcopy (n, q_t, 1, temp_q, 1); cblas_dscal (n, -alpha, temp_q, 1);//rescale by -aplha cblas_daxpy (n, 1, temp_q, 1, r_t, 1);// sum r = 1*r - temp_p r_norm = cblas_dnrm2 (n, r, 1); //next step } cblas_dcopy (n, res, 1, x, 1); cs_spfree(AT); }
/* * This procedure converts a double-precision number in IEEE format * into a string of hexadecimal digits and an exponent of 2. Its * behavior is bug-for-bug compatible with dtoa() in mode 2, with the * following exceptions: * * - An ndigits < 0 causes it to use as many digits as necessary to * represent the number exactly. * - The additional xdigs argument should point to either the string * "0123456789ABCDEF" or the string "0123456789abcdef", depending on * which case is desired. * - This routine does not repeat dtoa's mistake of setting decpt * to 9999 in the case of an infinity or NaN. INT_MAX is used * for this purpose instead. * * Note that the C99 standard does not specify what the leading digit * should be for non-zero numbers. For instance, 0x1.3p3 is the same * as 0x2.6p2 is the same as 0x4.cp3. This implementation chooses the * first digit so that subsequent digits are aligned on nibble * boundaries (before rounding). * * Inputs: d, xdigs, ndigits * Outputs: decpt, sign, rve */ char * __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve) { static const int sigfigs = (DBL_MANT_DIG + 3) / 4; struct vax_d_floating *p = (struct vax_d_floating *)&d; char *s, *s0; int bufsize; *sign = p->dflt_sign; switch (fpclassify(d)) { case FP_NORMAL: *decpt = p->dflt_exp - DBL_ADJ; break; case FP_ZERO: *decpt = 1; return (nrv_alloc("0", rve, 1)); default: abort(); } /* FP_NORMAL or FP_SUBNORMAL */ if (ndigits == 0) /* dtoa() compatibility */ ndigits = 1; /* * For simplicity, we generate all the digits even if the * caller has requested fewer. */ bufsize = (sigfigs > ndigits) ? sigfigs : ndigits; s0 = rv_alloc(bufsize); if (s0 == NULL) return (NULL); /* * We work from right to left, first adding any requested zero * padding, then the least significant portion of the * mantissa, followed by the most significant. The buffer is * filled with the byte values 0x0 through 0xf, which are * converted to xdigs[0x0] through xdigs[0xf] after the * rounding phase. */ for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--) *s = 0; for (; s > s0 + sigfigs - (DFLT_FRACLBITS / 4) - 1 && s > s0; s--) { *s = p->dflt_fracl & 0xf; p->dflt_fracl >>= 4; } for (; s > s0; s--) { *s = p->dflt_fracm & 0xf; p->dflt_fracm >>= 4; } for (; s > s0; s--) { *s = p->dflt_frach & 0xf; p->dflt_frach >>= 4; } /* * At this point, we have snarfed all the bits in the * mantissa, with the possible exception of the highest-order * (partial) nibble, which is dealt with by the next * statement. We also tack on the implicit normalization bit. */ *s = p->dflt_frach | (1U << ((DBL_MANT_DIG - 1) % 4)); /* If ndigits < 0, we are expected to auto-size the precision. */ if (ndigits < 0) { for (ndigits = sigfigs; s0[ndigits - 1] == 0; ndigits--) ; } if (sigfigs > ndigits && s0[ndigits] != 0) dorounding(s0, ndigits, p->dflt_sign, decpt); s = s0 + ndigits; if (rve != NULL) *rve = s; *s-- = '\0'; for (; s >= s0; s--) *s = xdigs[(unsigned int)*s]; return (s0); }
// The native fpclassify broken for long doubles with aCC // use portable one instead.... inline int fpclassify BOOST_NO_MACRO_EXPAND(long double t) { return BOOST_FPCLASSIFY_PREFIX fpclassify(t); }
uint_fast64_t fp64enc(fp64_t input) { fp64_t d_mant; unsigned int u_exp; uint_fast64_t u_mant; bool neg; int s_exp; uint_fast64_t bytes; switch (fpclassify(input)) { default: abort(); break; case FP_ZERO: neg = signbit(input); u_mant = 0; u_exp = 0; break; case FP_INFINITE: neg = signbit(input); u_mant = 0; u_exp = EXPONENT_MASK; break; case FP_NAN: neg = false; u_mant = 1; u_exp = EXPONENT_MASK; break; case FP_SUBNORMAL: case FP_NORMAL: /* Handle normal and subnormal together. The number might be one class for double, but another for binary64. */ /* Decompose the input into a significand (mantissa + 1) and an exponent. */ d_mant = XORP_FP64(frexp)(input, &s_exp); /* Extract the sign bit from the mantissa. */ neg = signbit(input); d_mant = XORP_FP64(fabs)(d_mant); /* Offset the exponent so it can be represented as an unsigned value. */ s_exp += EXPONENT_BIAS; /* Now we find out whether the number we represent is normal, subnormal, or overflows binary64. */ if (s_exp >= (long) EXPONENT_MASK) { /* The number is too big for binary64, so use the maximum value. */ u_mant = MANTISSA_MASK; u_exp = EXPONENT_MASK - 1u; } else if (s_exp <= 0) { /* The number is subnormal in binary64. */ /* Shift the mantissa so that it's exponent would be 0. */ u_mant = XORP_FP64(ldexp)(d_mant, MANTISSA_BIT); u_mant >>= -s_exp; u_exp = 0; } else {
GLbitfield GLAPIENTRY _mesa_QueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]) { GLfloat matrix[16]; GLint tmp; GLenum currentMode = GL_FALSE; GLenum desiredMatrix = GL_FALSE; /* The bitfield returns 1 for each component that is invalid (i.e. * NaN or Inf). In case of error, everything is invalid. */ GLbitfield rv; register unsigned int i; unsigned int bit; /* This data structure defines the mapping between the current matrix * mode and the desired matrix identifier. */ static struct { GLenum currentMode; GLenum desiredMatrix; } modes[] = { {GL_MODELVIEW, GL_MODELVIEW_MATRIX}, {GL_PROJECTION, GL_PROJECTION_MATRIX}, {GL_TEXTURE, GL_TEXTURE_MATRIX}, }; /* Call Mesa to get the current matrix in floating-point form. First, * we have to figure out what the current matrix mode is. */ _mesa_GetIntegerv(GL_MATRIX_MODE, &tmp); currentMode = (GLenum) tmp; /* The mode is either GL_FALSE, if for some reason we failed to query * the mode, or a given mode from the above table. Search for the * returned mode to get the desired matrix; if we don't find it, * we can return immediately, as _mesa_GetInteger() will have * logged the necessary error already. */ for (i = 0; i < sizeof(modes)/sizeof(modes[0]); i++) { if (modes[i].currentMode == currentMode) { desiredMatrix = modes[i].desiredMatrix; break; } } if (desiredMatrix == GL_FALSE) { /* Early error means all values are invalid. */ return 0xffff; } /* Now pull the matrix itself. */ _mesa_GetFloatv(desiredMatrix, matrix); rv = 0; for (i = 0, bit = 1; i < 16; i++, bit<<=1) { float normalizedFraction; int exp; switch (fpclassify(matrix[i])) { /* A "subnormal" or denormalized number is too small to be * represented in normal format; but despite that it's a * valid floating point number. FP_ZERO and FP_NORMAL * are both valid as well. We should be fine treating * these three cases as legitimate floating-point numbers. */ case FP_SUBNORMAL: case FP_NORMAL: case FP_ZERO: normalizedFraction = (GLfloat)frexp(matrix[i], &exp); mantissa[i] = FLOAT_TO_FIXED(normalizedFraction); exponent[i] = (GLint) exp; break; /* If the entry is not-a-number or an infinity, then the * matrix component is invalid. The invalid flag for * the component is already set; might as well set the * other return values to known values. We'll set * distinct values so that a savvy end user could determine * whether the matrix component was a NaN or an infinity, * but this is more useful for debugging than anything else * since the standard doesn't specify any such magic * values to return. */ case FP_NAN: mantissa[i] = INT_TO_FIXED(0); exponent[i] = (GLint) 0; rv |= bit; break; case FP_INFINITE: /* Return +/- 1 based on whether it's a positive or * negative infinity. */ if (matrix[i] > 0) { mantissa[i] = INT_TO_FIXED(1); } else { mantissa[i] = -INT_TO_FIXED(1); } exponent[i] = (GLint) 0; rv |= bit; break; /* We should never get here; but here's a catching case * in case fpclassify() is returnings something unexpected. */ default: mantissa[i] = INT_TO_FIXED(2); exponent[i] = (GLint) 0; rv |= bit; break; } } /* for each component */ /* All done */ return rv; }
__complex__ float __clog10f (__complex__ float x) { __complex__ float result; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO)) { /* Real and imaginary part are 0.0. */ __imag__ result = signbit (__real__ x) ? M_PI_LOG10Ef : 0.0; __imag__ result = __copysignf (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabsf (__real__ x); } else if (__glibc_likely (rcls != FP_NAN && icls != FP_NAN)) { /* Neither real nor imaginary part is NaN. */ float absx = fabsf (__real__ x), absy = fabsf (__imag__ x); int scale = 0; if (absx < absy) { float t = absx; absx = absy; absy = t; } if (absx > FLT_MAX / 2.0f) { scale = -1; absx = __scalbnf (absx, scale); absy = (absy >= FLT_MIN * 2.0f ? __scalbnf (absy, scale) : 0.0f); } else if (absx < FLT_MIN && absy < FLT_MIN) { scale = FLT_MANT_DIG; absx = __scalbnf (absx, scale); absy = __scalbnf (absy, scale); } if (absx == 1.0f && scale == 0) { float absy2 = absy * absy; if (absy2 <= FLT_MIN * 2.0f * (float) M_LN10) { float force_underflow = absy2 * absy2; __real__ result = absy2 * ((float) M_LOG10E / 2.0f); math_force_eval (force_underflow); } else __real__ result = __log1pf (absy2) * ((float) M_LOG10E / 2.0f); } else if (absx > 1.0f && absx < 2.0f && absy < 1.0f && scale == 0) { float d2m1 = (absx - 1.0f) * (absx + 1.0f); if (absy >= FLT_EPSILON) d2m1 += absy * absy; __real__ result = __log1pf (d2m1) * ((float) M_LOG10E / 2.0f); } else if (absx < 1.0f && absx >= 0.75f && absy < FLT_EPSILON / 2.0f && scale == 0) { float d2m1 = (absx - 1.0f) * (absx + 1.0f); __real__ result = __log1pf (d2m1) * ((float) M_LOG10E / 2.0f); } else if (absx < 1.0f && (absx >= 0.75f || absy >= 0.5f) && scale == 0) { float d2m1 = __x2y2m1f (absx, absy); __real__ result = __log1pf (d2m1) * ((float) M_LOG10E / 2.0f); } else { float d = __ieee754_hypotf (absx, absy); __real__ result = __ieee754_log10f (d) - scale * M_LOG10_2f; } __imag__ result = M_LOG10E * __ieee754_atan2f (__imag__ x, __real__ x); } else { __imag__ result = __nanf (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VALF; else __real__ result = __nanf (""); } return result; }
__complex__ float __cacoshf (__complex__ float x) { __complex__ float res; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (rcls <= FP_INFINITE || icls <= FP_INFINITE) { if (icls == FP_INFINITE) { __real__ res = HUGE_VALF; if (rcls == FP_NAN) __imag__ res = __nanf (""); else __imag__ res = __copysignf ((rcls == FP_INFINITE ? (__real__ x < 0.0 ? M_PI - M_PI_4 : M_PI_4) : M_PI_2), __imag__ x); } else if (rcls == FP_INFINITE) { __real__ res = HUGE_VALF; if (icls >= FP_ZERO) __imag__ res = __copysignf (signbit (__real__ x) ? M_PI : 0.0, __imag__ x); else __imag__ res = __nanf (""); } else { __real__ res = __nanf (""); __imag__ res = __nanf (""); } } else if (rcls == FP_ZERO && icls == FP_ZERO) { __real__ res = 0.0; __imag__ res = __copysignf (M_PI_2, __imag__ x); } else { #if 1 __complex__ float y; __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0; __imag__ y = 2.0 * __real__ x * __imag__ x; y = __csqrtf (y); if (__real__ x < 0.0) y = -y; __real__ y += __real__ x; __imag__ y += __imag__ x; res = __clogf (y); #else float re2 = __real__ x * __real__ x; float im2 = __imag__ x * __imag__ x; float sq = re2 - im2 - 1.0; float ro = __ieee754_sqrtf (sq * sq + 4 * re2 * im2); float a = __ieee754_sqrtf ((sq + ro) / 2.0); float b = __ieee754_sqrtf ((-sq + ro) / 2.0); __real__ res = 0.5 * __ieee754_logf (re2 + __real__ x * 2 * a + im2 + __imag__ x * 2 * b + ro); __imag__ res = __ieee754_atan2f (__imag__ x + b, __real__ x + a); #endif /* We have to use the positive branch. */ if (__real__ res < 0.0) res = -res; } return res; }
__complex__ long double __csqrtl (__complex__ long double x) { __complex__ long double res; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls <= FP_INFINITE || icls <= FP_INFINITE, 0)) { if (icls == FP_INFINITE) { __real__ res = HUGE_VALL; __imag__ res = __imag__ x; } else if (rcls == FP_INFINITE) { if (__real__ x < 0.0) { __real__ res = icls == FP_NAN ? __nanl ("") : 0; __imag__ res = __copysignl (HUGE_VALL, __imag__ x); } else { __real__ res = __real__ x; __imag__ res = (icls == FP_NAN ? __nanl ("") : __copysignl (0.0, __imag__ x)); } } else { __real__ res = __nanl (""); __imag__ res = __nanl (""); } } else { if (__builtin_expect (icls == FP_ZERO, 0)) { if (__real__ x < 0.0) { __real__ res = 0.0; __imag__ res = __copysignl (__ieee754_sqrtl (-__real__ x), __imag__ x); } else { __real__ res = fabsl (__ieee754_sqrtl (__real__ x)); __imag__ res = __copysignl (0.0, __imag__ x); } } else if (__builtin_expect (rcls == FP_ZERO, 0)) { long double r = __ieee754_sqrtl (0.5 * fabsl (__imag__ x)); __real__ res = r; __imag__ res = __copysignl (r, __imag__ x); } else { long double d, r, s; d = __ieee754_hypotl (__real__ x, __imag__ x); /* Use the identity 2 Re res Im res = Im x to avoid cancellation error in d +/- Re x. */ if (__real__ x > 0) { r = __ieee754_sqrtl (0.5L * d + 0.5L * __real__ x); s = (0.5L * __imag__ x) / r; } else { s = __ieee754_sqrtl (0.5L * d - 0.5L * __real__ x); r = fabsl ((0.5L * __imag__ x) / s); } __real__ res = r; __imag__ res = __copysignl (s, __imag__ x); } } return res; }