added default hypot() implementation

This commit is contained in:
Guido van Rossum 1996-01-12 01:39:11 +00:00
parent b123691384
commit 3206268692
1 changed files with 21 additions and 4 deletions

View File

@ -42,6 +42,27 @@ extern double modf PROTO((double, double *));
#if defined(HAVE_HYPOT) && !defined(NeXT) #if defined(HAVE_HYPOT) && !defined(NeXT)
extern double hypot PROTO((double, double)); 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 #endif
#ifdef i860 #ifdef i860
@ -124,9 +145,7 @@ FUNC1(math_exp, exp)
FUNC1(math_fabs, fabs) FUNC1(math_fabs, fabs)
FUNC1(math_floor, floor) FUNC1(math_floor, floor)
FUNC2(math_fmod, fmod) FUNC2(math_fmod, fmod)
#ifdef HAVE_HYPOT
FUNC2(math_hypot, hypot) FUNC2(math_hypot, hypot)
#endif
FUNC1(math_log, log) FUNC1(math_log, log)
FUNC1(math_log10, log10) FUNC1(math_log10, log10)
#ifdef MPW_3_1 /* This hack is needed for MPW 3.1 but not for 3.2 ... */ #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}, {"floor", math_floor},
{"fmod", math_fmod}, {"fmod", math_fmod},
{"frexp", math_frexp}, {"frexp", math_frexp},
#ifdef HAVE_HYPOT
{"hypot", math_hypot}, {"hypot", math_hypot},
#endif
{"ldexp", math_ldexp}, {"ldexp", math_ldexp},
{"log", math_log}, {"log", math_log},
{"log10", math_log10}, {"log10", math_log10},