]> granicus.if.org Git - python/commitdiff
added default hypot() implementation
authorGuido van Rossum <guido@python.org>
Fri, 12 Jan 1996 01:39:11 +0000 (01:39 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 12 Jan 1996 01:39:11 +0000 (01:39 +0000)
Modules/mathmodule.c

index 9cff9e0fc0ff007e3fa08dd5f59c8a33ca75a102..4e704bfa95338666eab0ccf1f9e06a42dc64a738 100644 (file)
@@ -42,6 +42,27 @@ extern double modf PROTO((double, double *));
 
 #if defined(HAVE_HYPOT) && !defined(NeXT)
 extern double hypot PROTO((double, double));
+#else
+double hypot(x,y)
+       double x;
+       double y;
+{
+       double yx;
+
+       x = fabs(x);
+       y = fabs(y);
+       if (x < y) {
+               double temp = x;
+               x = y;
+               y = temp;
+       }
+       if (x == 0.)
+               return 0.;
+       else {
+               yx = y/x;
+               return x*sqrt(1.+yx*yx);
+       }
+}
 #endif
 
 #ifdef i860
@@ -124,9 +145,7 @@ FUNC1(math_exp, exp)
 FUNC1(math_fabs, fabs)
 FUNC1(math_floor, floor)
 FUNC2(math_fmod, fmod)
-#ifdef HAVE_HYPOT
 FUNC2(math_hypot, hypot)
-#endif
 FUNC1(math_log, log)
 FUNC1(math_log10, log10)
 #ifdef MPW_3_1 /* This hack is needed for MPW 3.1 but not for 3.2 ... */
@@ -213,9 +232,7 @@ static struct methodlist math_methods[] = {
        {"floor", math_floor},
        {"fmod", math_fmod},
        {"frexp", math_frexp},
-#ifdef HAVE_HYPOT
        {"hypot", math_hypot},
-#endif
        {"ldexp", math_ldexp},
        {"log", math_log},
        {"log10", math_log10},