2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
11 This implementation is based largely on Cephes library
12 function cabsl (cmplxl.c), which bears the following notice:
14 Cephes Math Library Release 2.1: January, 1989
15 Copyright 1984, 1987, 1989 by Stephen L. Moshier
16 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
20 Modified for use in libmingwex.a
21 02 Sept 2002 Danny Smith <dannysmith@users.sourceforege.net>
22 Calls to ldexpl replaced by logbl and calls to frexpl replaced
23 by scalbnl to avoid duplicated range checks.
29 hypotl (long double x
, long double y
)
34 long double xx
=fabsl(x
);
35 long double yy
=fabsl(y
);
36 if (!isfinite(xx
) || !isfinite(yy
))
38 /* Annex F.9.4.3, hypot returns +infinity if
39 either component is an infinity, even when the
40 other component is NaN. */
41 return (isinf(xx
) || isinf(yy
)) ? INFINITY
: NAN
;
53 /* Check if large differences in scale */
60 /* Exponent of approximate geometric mean (x 2) */
61 scale
= (exx
+ eyy
) >> 1;
63 /* Rescale: Geometric mean is now about 2 */
64 x
= scalbnl(xx
, -scale
);
65 y
= scalbnl(yy
, -scale
);
67 xx
= sqrtl(x
* x
+ y
* y
);
69 /* Check for overflow and underflow */
72 if (exx
> LDBL_MAX_EXP
)
77 if (exx
< LDBL_MIN_EXP
)
81 return (scalbnl (xx
, scale
));