__complex__ float __kernel_casinhf (__complex__ float x, int adj) { __complex__ float res; float rx, ix; __complex__ float y; /* Avoid cancellation by reducing to the first quadrant. */ rx = fabsf (__real__ x); ix = fabsf (__imag__ x); if (rx >= 1.0f / FLT_EPSILON || ix >= 1.0f / FLT_EPSILON) { /* For large x in the first quadrant, x + csqrt (1 + x * x) is sufficiently close to 2 * x to make no significant difference to the result; avoid possible overflow from the squaring and addition. */ __real__ y = rx; __imag__ y = ix; if (adj) { float t = __real__ y; __real__ y = __copysignf (__imag__ y, __imag__ x); __imag__ y = t; } res = __clogf (y); __real__ res += (float) M_LN2; } else { __real__ y = (rx - ix) * (rx + ix) + 1.0; __imag__ y = 2.0 * rx * ix; y = __csqrtf (y); __real__ y += rx; __imag__ y += ix; if (adj) { float t = __real__ y; __real__ y = __copysignf (__imag__ y, __imag__ x); __imag__ y = t; } res = __clogf (y); } /* Give results the correct sign for the original argument. */ __real__ res = __copysignf (__real__ res, __real__ x); __imag__ res = __copysignf (__imag__ res, (adj ? 1.0f : __imag__ x)); return res; }
__complex__ float __casinhf (__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 = __copysignf (HUGE_VALF, __real__ x); if (rcls == FP_NAN) __imag__ res = __nanf (""); else __imag__ res = __copysignf (rcls >= FP_ZERO ? M_PI_2 : M_PI_4, __imag__ x); } else if (rcls <= FP_INFINITE) { __real__ res = __real__ x; if ((rcls == FP_INFINITE && icls >= FP_ZERO) || (rcls == FP_NAN && icls == FP_ZERO)) __imag__ res = __copysignf (0.0, __imag__ x); else __imag__ res = __nanf (""); } else { __real__ res = __nanf (""); __imag__ res = __nanf (""); } } else if (rcls == FP_ZERO && icls == FP_ZERO) { res = x; } else { __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); __real__ y += __real__ x; __imag__ y += __imag__ x; res = __clogf (y); } return res; }
__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__ float __kernel_casinhf (__complex__ float x, int adj) { __complex__ float res; float rx, ix; __complex__ float y; /* Avoid cancellation by reducing to the first quadrant. */ rx = fabsf (__real__ x); ix = fabsf (__imag__ x); if (rx >= 1.0f / FLT_EPSILON || ix >= 1.0f / FLT_EPSILON) { /* For large x in the first quadrant, x + csqrt (1 + x * x) is sufficiently close to 2 * x to make no significant difference to the result; avoid possible overflow from the squaring and addition. */ __real__ y = rx; __imag__ y = ix; if (adj) { float t = __real__ y; __real__ y = __copysignf (__imag__ y, __imag__ x); __imag__ y = t; } res = __clogf (y); __real__ res += (float) M_LN2; } else if (rx >= 0.5f && ix < FLT_EPSILON / 8.0f) { float s = __ieee754_hypotf (1.0f, rx); __real__ res = __ieee754_logf (rx + s); if (adj) __imag__ res = __ieee754_atan2f (s, __imag__ x); else __imag__ res = __ieee754_atan2f (ix, s); } else if (rx < FLT_EPSILON / 8.0f && ix >= 1.5f) { float s = __ieee754_sqrtf ((ix + 1.0f) * (ix - 1.0f)); __real__ res = __ieee754_logf (ix + s); if (adj) __imag__ res = __ieee754_atan2f (rx, __copysignf (s, __imag__ x)); else __imag__ res = __ieee754_atan2f (s, rx); } else if (ix > 1.0f && ix < 1.5f && rx < 0.5f) { if (rx < FLT_EPSILON * FLT_EPSILON) { float ix2m1 = (ix + 1.0f) * (ix - 1.0f); float s = __ieee754_sqrtf (ix2m1); __real__ res = __log1pf (2.0f * (ix2m1 + ix * s)) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (rx, __copysignf (s, __imag__ x)); else __imag__ res = __ieee754_atan2f (s, rx); } else { float ix2m1 = (ix + 1.0f) * (ix - 1.0f); float rx2 = rx * rx; float f = rx2 * (2.0f + rx2 + 2.0f * ix * ix); float d = __ieee754_sqrtf (ix2m1 * ix2m1 + f); float dp = d + ix2m1; float dm = f / dp; float r1 = __ieee754_sqrtf ((dm + rx2) / 2.0f); float r2 = rx * ix / r1; __real__ res = __log1pf (rx2 + dp + 2.0f * (rx * r1 + ix * r2)) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (rx + r1, __copysignf (ix + r2, __imag__ x)); else __imag__ res = __ieee754_atan2f (ix + r2, rx + r1); } } else if (ix == 1.0f && rx < 0.5f) { if (rx < FLT_EPSILON / 8.0f) { __real__ res = __log1pf (2.0f * (rx + __ieee754_sqrtf (rx))) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (__ieee754_sqrtf (rx), __copysignf (1.0f, __imag__ x)); else __imag__ res = __ieee754_atan2f (1.0f, __ieee754_sqrtf (rx)); } else { float d = rx * __ieee754_sqrtf (4.0f + rx * rx); float s1 = __ieee754_sqrtf ((d + rx * rx) / 2.0f); float s2 = __ieee754_sqrtf ((d - rx * rx) / 2.0f); __real__ res = __log1pf (rx * rx + d + 2.0f * (rx * s1 + s2)) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (rx + s1, __copysignf (1.0f + s2, __imag__ x)); else __imag__ res = __ieee754_atan2f (1.0f + s2, rx + s1); } } else if (ix < 1.0f && rx < 0.5f) { if (ix >= FLT_EPSILON) { if (rx < FLT_EPSILON * FLT_EPSILON) { float onemix2 = (1.0f + ix) * (1.0f - ix); float s = __ieee754_sqrtf (onemix2); __real__ res = __log1pf (2.0f * rx / s) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (s, __imag__ x); else __imag__ res = __ieee754_atan2f (ix, s); } else { float onemix2 = (1.0f + ix) * (1.0f - ix); float rx2 = rx * rx; float f = rx2 * (2.0f + rx2 + 2.0f * ix * ix); float d = __ieee754_sqrtf (onemix2 * onemix2 + f); float dp = d + onemix2; float dm = f / dp; float r1 = __ieee754_sqrtf ((dp + rx2) / 2.0f); float r2 = rx * ix / r1; __real__ res = __log1pf (rx2 + dm + 2.0f * (rx * r1 + ix * r2)) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (rx + r1, __copysignf (ix + r2, __imag__ x)); else __imag__ res = __ieee754_atan2f (ix + r2, rx + r1); } } else { float s = __ieee754_hypotf (1.0f, rx); __real__ res = __log1pf (2.0f * rx * (rx + s)) / 2.0f; if (adj) __imag__ res = __ieee754_atan2f (s, __imag__ x); else __imag__ res = __ieee754_atan2f (ix, s); } if (__real__ res < FLT_MIN) { volatile float force_underflow = __real__ res * __real__ res; (void) force_underflow; } } else { __real__ y = (rx - ix) * (rx + ix) + 1.0f; __imag__ y = 2.0f * rx * ix; y = __csqrtf (y); __real__ y += rx; __imag__ y += ix; if (adj) { float t = __real__ y; __real__ y = __copysignf (__imag__ y, __imag__ x); __imag__ y = t; } res = __clogf (y); } /* Give results the correct sign for the original argument. */ __real__ res = __copysignf (__real__ res, __real__ x); __imag__ res = __copysignf (__imag__ res, (adj ? 1.0f : __imag__ x)); return res; }