summaryrefslogtreecommitdiffstats
path: root/newlib/libm/common/hypotl.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libm/common/hypotl.c')
-rw-r--r--newlib/libm/common/hypotl.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/newlib/libm/common/hypotl.c b/newlib/libm/common/hypotl.c
index 3934b8ecc..cf67ccf58 100644
--- a/newlib/libm/common/hypotl.c
+++ b/newlib/libm/common/hypotl.c
@@ -29,14 +29,61 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include <math.h>
-#include "local.h"
+#include <errno.h>
+#include "fdlibm.h"
-/* On platforms where long double is as wide as double. */
-#ifdef _LDBL_EQ_DBL
long double
hypotl (long double x, long double y)
{
+#ifdef _LDBL_EQ_DBL
+
+ /* On platforms where long double is as wide as double. */
return hypot(x, y);
-}
+
+#else
+
+ long double z;
+
+ z = __ieee754_hypotl (x, y);
+
+ if (_LIB_VERSION == _IEEE_)
+ return z;
+
+ if ((! finitel (z)) && finitel (x) && finitel (y))
+ {
+ /* hypot (finite, finite) overflow. */
+ struct exception exc;
+
+ exc.type = OVERFLOW;
+ exc.name = "hypotl";
+ exc.err = 0;
+ exc.arg1 = x;
+ exc.arg2 = y;
+
+ if (_LIB_VERSION == _SVID_)
+ exc.retval = HUGE;
+ else
+ {
+#ifndef HUGE_VAL
+#define HUGE_VAL inf
+ double inf = 0.0;
+
+ SET_HIGH_WORD (inf, 0x7ff00000); /* Set inf to infinite. */
#endif
+ exc.retval = HUGE_VAL;
+ }
+ if (_LIB_VERSION == _POSIX_)
+ errno = ERANGE;
+ else if (! matherr (& exc))
+ errno = ERANGE;
+
+ if (exc.err != 0)
+ errno = exc.err;
+
+ return (long double) exc.retval;
+ }
+
+ return z;
+#endif /* ! _LDBL_EQ_DBL */
+}