double hypot(double x, double y)/* wrapper hypot */ { #ifdef _IEEE_LIBM return __ieee754_hypot(x,y); #else double z; z = __ieee754_hypot(x,y); if(_LIB_VERSION == _IEEE_) return z; if((!finite(z))&&finite(x)&&finite(y)) return __kernel_standard(x,y,4); /* hypot overflow */ else return z; #endif }
__complex__ double __clog10 (__complex__ double x) { __complex__ 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_PI : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ __real__ result = __ieee754_log10 (__ieee754_hypot (__real__ x, __imag__ x)); __imag__ result = M_LOG10E * __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }
double hypot(double x, double y) { double z = __ieee754_hypot(x, y); if (_LIB_VERSION == _IEEE_) return z; if ((!isfinite(z)) && isfinite(x) && isfinite(y)) return __kernel_standard(x, y, 4); /* hypot overflow */ return z; }
void Math_hypot(void *fp) { F_Math_hypot *f; f = fp; *f->ret = __ieee754_hypot(f->x, f->y); }
double __hypot (double x, double y) { double z = __ieee754_hypot(x,y); if(__builtin_expect(!isfinite(z), 0) && isfinite(x) && isfinite(y) && _LIB_VERSION != _IEEE_) return __kernel_standard(x, y, 4); /* hypot overflow */ return z; }
__complex__ double __clog (__complex__ double x) { __complex__ 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_PI : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ double d; int scale = 0; if (fabs (__real__ x) > DBL_MAX / 2.0 || fabs (__imag__ x) > DBL_MAX / 2.0) { scale = -1; __real__ x = __scalbn (__real__ x, scale); __imag__ x = __scalbn (__imag__ x, scale); } else if (fabs (__real__ x) < DBL_MIN && fabs (__imag__ x) < DBL_MIN) { scale = DBL_MANT_DIG; __real__ x = __scalbn (__real__ x, scale); __imag__ x = __scalbn (__imag__ x, scale); } d = __ieee754_hypot (__real__ x, __imag__ x); __real__ result = __ieee754_log (d) - scale * M_LN2; __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }
//------------------------------------------------------------------------------ double Cmath::hypot( double x, double y ) // wrapper hypot { double z; struct fexception exc; z = __ieee754_hypot( x, y ); if( m_fdlib_version == _IEEE_ ) { return z; } if( (!finite( z ) ) && finite( x ) && finite( y ) ) { // hypot(finite,finite) overflow # ifndef HUGE_VAL # define HUGE_VAL inf double inf = 0.0; set_high_word( inf, 0x7ff00000 ); // set inf to infinite # endif exc.type = EX_OVERFLOW; exc.name = "hypot"; exc.err = 0; exc.arg1 = x; exc.arg2 = y; if( m_fdlib_version == _SVID_ ) { exc.retval = Huge(); } else { exc.retval = HUGE_VAL; } if( m_fdlib_version == _POSIX_ ) { errno = ERANGE; } else if( !matherr( &exc ) ) { errno = ERANGE; } if( exc.err != 0 ) { errno = exc.err; } return exc.retval; } else { return z; } }
EXPORT(sqInt) primitiveHypot(void) { double rcvr; double result; double arg; arg = interpreterProxy->stackFloatValue(0); rcvr = interpreterProxy->stackFloatValue(1); if (interpreterProxy->failed()) { return null; } result = __ieee754_hypot(rcvr, arg); if (isnan(result)) { return interpreterProxy->primitiveFail(); } interpreterProxy->pop((interpreterProxy->methodArgumentCount()) + 1); interpreterProxy->pushFloat(result); }
primitiveHypot(void) { // FloatMathPlugin>>#primitiveHypot double arg; double rcvr; double result; arg = stackFloatValue(0); rcvr = stackFloatValue(1); if (failed()) { return null; } result = __ieee754_hypot(rcvr, arg); if (isnan(result)) { return primitiveFail(); } pop((methodArgumentCount()) + 1); pushFloat(result); }
double hypot(double x, double y)/* wrapper hypot */ { return __ieee754_hypot(x,y); }
Err mathlib_hypot(UInt16 refnum, double x, double y, double *result) { #pragma unused(refnum) *result = __ieee754_hypot(x, y); return mlErrNone; }
__complex__ double __kernel_casinh (__complex__ double x, int adj) { __complex__ double res; double rx, ix; __complex__ double y; /* Avoid cancellation by reducing to the first quadrant. */ rx = fabs (__real__ x); ix = fabs (__imag__ x); if (rx >= 1.0 / DBL_EPSILON || ix >= 1.0 / DBL_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) { double t = __real__ y; __real__ y = __copysign (__imag__ y, __imag__ x); __imag__ y = t; } res = __clog (y); __real__ res += M_LN2; } else if (rx >= 0.5 && ix < DBL_EPSILON / 8.0) { double s = __ieee754_hypot (1.0, rx); __real__ res = __ieee754_log (rx + s); if (adj) __imag__ res = __ieee754_atan2 (s, __imag__ x); else __imag__ res = __ieee754_atan2 (ix, s); } else if (rx < DBL_EPSILON / 8.0 && ix >= 1.5) { double s = __ieee754_sqrt ((ix + 1.0) * (ix - 1.0)); __real__ res = __ieee754_log (ix + s); if (adj) __imag__ res = __ieee754_atan2 (rx, __copysign (s, __imag__ x)); else __imag__ res = __ieee754_atan2 (s, rx); } else if (ix > 1.0 && ix < 1.5 && rx < 0.5) { if (rx < DBL_EPSILON * DBL_EPSILON) { double ix2m1 = (ix + 1.0) * (ix - 1.0); double s = __ieee754_sqrt (ix2m1); __real__ res = __log1p (2.0 * (ix2m1 + ix * s)) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (rx, __copysign (s, __imag__ x)); else __imag__ res = __ieee754_atan2 (s, rx); } else { double ix2m1 = (ix + 1.0) * (ix - 1.0); double rx2 = rx * rx; double f = rx2 * (2.0 + rx2 + 2.0 * ix * ix); double d = __ieee754_sqrt (ix2m1 * ix2m1 + f); double dp = d + ix2m1; double dm = f / dp; double r1 = __ieee754_sqrt ((dm + rx2) / 2.0); double r2 = rx * ix / r1; __real__ res = __log1p (rx2 + dp + 2.0 * (rx * r1 + ix * r2)) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (rx + r1, __copysign (ix + r2, __imag__ x)); else __imag__ res = __ieee754_atan2 (ix + r2, rx + r1); } } else if (ix == 1.0 && rx < 0.5) { if (rx < DBL_EPSILON / 8.0) { __real__ res = __log1p (2.0 * (rx + __ieee754_sqrt (rx))) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (__ieee754_sqrt (rx), __copysign (1.0, __imag__ x)); else __imag__ res = __ieee754_atan2 (1.0, __ieee754_sqrt (rx)); } else { double d = rx * __ieee754_sqrt (4.0 + rx * rx); double s1 = __ieee754_sqrt ((d + rx * rx) / 2.0); double s2 = __ieee754_sqrt ((d - rx * rx) / 2.0); __real__ res = __log1p (rx * rx + d + 2.0 * (rx * s1 + s2)) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (rx + s1, __copysign (1.0 + s2, __imag__ x)); else __imag__ res = __ieee754_atan2 (1.0 + s2, rx + s1); } } else if (ix < 1.0 && rx < 0.5) { if (ix >= DBL_EPSILON) { if (rx < DBL_EPSILON * DBL_EPSILON) { double onemix2 = (1.0 + ix) * (1.0 - ix); double s = __ieee754_sqrt (onemix2); __real__ res = __log1p (2.0 * rx / s) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (s, __imag__ x); else __imag__ res = __ieee754_atan2 (ix, s); } else { double onemix2 = (1.0 + ix) * (1.0 - ix); double rx2 = rx * rx; double f = rx2 * (2.0 + rx2 + 2.0 * ix * ix); double d = __ieee754_sqrt (onemix2 * onemix2 + f); double dp = d + onemix2; double dm = f / dp; double r1 = __ieee754_sqrt ((dp + rx2) / 2.0); double r2 = rx * ix / r1; __real__ res = __log1p (rx2 + dm + 2.0 * (rx * r1 + ix * r2)) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (rx + r1, __copysign (ix + r2, __imag__ x)); else __imag__ res = __ieee754_atan2 (ix + r2, rx + r1); } } else { double s = __ieee754_hypot (1.0, rx); __real__ res = __log1p (2.0 * rx * (rx + s)) / 2.0; if (adj) __imag__ res = __ieee754_atan2 (s, __imag__ x); else __imag__ res = __ieee754_atan2 (ix, s); } math_check_force_underflow_nonneg (__real__ res); } else { __real__ y = (rx - ix) * (rx + ix) + 1.0; __imag__ y = 2.0 * rx * ix; y = __csqrt (y); __real__ y += rx; __imag__ y += ix; if (adj) { double t = __real__ y; __real__ y = __copysign (__imag__ y, __imag__ x); __imag__ y = t; } res = __clog (y); } /* Give results the correct sign for the original argument. */ __real__ res = __copysign (__real__ res, __real__ x); __imag__ res = __copysign (__imag__ res, (adj ? 1.0 : __imag__ x)); 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; }
__complex__ double __csqrt (__complex__ double x) { __complex__ 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_VAL; __imag__ res = __imag__ x; } else if (rcls == FP_INFINITE) { if (__real__ x < 0.0) { __real__ res = icls == FP_NAN ? __nan ("") : 0; __imag__ res = __copysign (HUGE_VAL, __imag__ x); } else { __real__ res = __real__ x; __imag__ res = (icls == FP_NAN ? __nan ("") : __copysign (0.0, __imag__ x)); } } else { __real__ res = __nan (""); __imag__ res = __nan (""); } } else { if (__builtin_expect (icls == FP_ZERO, 0)) { if (__real__ x < 0.0) { __real__ res = 0.0; __imag__ res = __copysign (__ieee754_sqrt (-__real__ x), __imag__ x); } else { __real__ res = fabs (__ieee754_sqrt (__real__ x)); __imag__ res = __copysign (0.0, __imag__ x); } } else if (__builtin_expect (rcls == FP_ZERO, 0)) { double r; if (fabs (__imag__ x) >= 2.0 * DBL_MIN) r = __ieee754_sqrt (0.5 * fabs (__imag__ x)); else r = 0.5 * __ieee754_sqrt (2.0 * fabs (__imag__ x)); __real__ res = r; __imag__ res = __copysign (r, __imag__ x); } else { double d, r, s; int scale = 0; if (fabs (__real__ x) > DBL_MAX / 4.0) { scale = 1; __real__ x = __scalbn (__real__ x, -2 * scale); __imag__ x = __scalbn (__imag__ x, -2 * scale); } else if (fabs (__imag__ x) > DBL_MAX / 4.0) { scale = 1; if (fabs (__real__ x) >= 4.0 * DBL_MIN) __real__ x = __scalbn (__real__ x, -2 * scale); else __real__ x = 0.0; __imag__ x = __scalbn (__imag__ x, -2 * scale); } else if (fabs (__real__ x) < DBL_MIN && fabs (__imag__ x) < DBL_MIN) { scale = -(DBL_MANT_DIG / 2); __real__ x = __scalbn (__real__ x, -2 * scale); __imag__ x = __scalbn (__imag__ x, -2 * scale); } d = __ieee754_hypot (__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_sqrt (0.5 * (d + __real__ x)); s = 0.5 * (__imag__ x / r); } else { s = __ieee754_sqrt (0.5 * (d - __real__ x)); r = fabs (0.5 * (__imag__ x / s)); } if (scale) { r = __scalbn (r, scale); s = __scalbn (s, scale); } __real__ res = r; __imag__ res = __copysign (s, __imag__ x); } } return res; }
__complex__ double __clog (__complex__ double x) { __complex__ double 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 : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__glibc_likely (rcls != FP_NAN && icls != FP_NAN)) { /* Neither real nor imaginary part is NaN. */ double absx = fabs (__real__ x), absy = fabs (__imag__ x); int scale = 0; if (absx < absy) { double t = absx; absx = absy; absy = t; } if (absx > DBL_MAX / 2.0) { scale = -1; absx = __scalbn (absx, scale); absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0); } else if (absx < DBL_MIN && absy < DBL_MIN) { scale = DBL_MANT_DIG; absx = __scalbn (absx, scale); absy = __scalbn (absy, scale); } if (absx == 1.0 && scale == 0) { __real__ result = __log1p (absy * absy) / 2.0; math_check_force_underflow_nonneg (__real__ result); } else if (absx > 1.0 && absx < 2.0 && absy < 1.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); if (absy >= DBL_EPSILON) d2m1 += absy * absy; __real__ result = __log1p (d2m1) / 2.0; } else if (absx < 1.0 && absx >= 0.5 && absy < DBL_EPSILON / 2.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); __real__ result = __log1p (d2m1) / 2.0; } else if (absx < 1.0 && absx >= 0.5 && scale == 0 && absx * absx + absy * absy >= 0.5) { double d2m1 = __x2y2m1 (absx, absy); __real__ result = __log1p (d2m1) / 2.0; } else { double d = __ieee754_hypot (absx, absy); __real__ result = __ieee754_log (d) - scale * M_LN2; } __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }
__complex__ double __clog10 (__complex__ double x) { __complex__ 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_PI : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ double absx = fabs (__real__ x), absy = fabs (__imag__ x); int scale = 0; if (absx < absy) { double t = absx; absx = absy; absy = t; } if (absx > DBL_MAX / 2.0) { scale = -1; absx = __scalbn (absx, scale); absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0); } else if (absx < DBL_MIN && absy < DBL_MIN) { scale = DBL_MANT_DIG; absx = __scalbn (absx, scale); absy = __scalbn (absy, scale); } if (absx == 1.0 && scale == 0) { double absy2 = absy * absy; if (absy2 <= DBL_MIN * 2.0 * M_LN10) { #if __FLT_EVAL_METHOD__ == 0 __real__ result = (absy2 / 2.0 - absy2 * absy2 / 4.0) * M_LOG10E; #else volatile double force_underflow = absy2 * absy2 / 4.0; __real__ result = (absy2 / 2.0 - force_underflow) * M_LOG10E; #endif } else __real__ result = __log1p (absy2) * (M_LOG10E / 2.0); } else if (absx > 1.0 && absx < 2.0 && absy < 1.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); if (absy >= DBL_EPSILON) d2m1 += absy * absy; __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0); } else if (absx < 1.0 && absx >= 0.75 && absy < DBL_EPSILON / 2.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0); } else if (absx < 1.0 && (absx >= 0.75 || absy >= 0.5) && scale == 0) { double d2m1 = __x2y2m1 (absx, absy); __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0); } else { double d = __ieee754_hypot (absx, absy); __real__ result = __ieee754_log10 (d) - scale * M_LOG10_2; } __imag__ result = M_LOG10E * __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }