From 1d73a4f04efde528d27c76cbe6bccd5d02247684 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 26 Feb 1991 18:08:25 +0000 Subject: [PATCH] Added hypot.c --- lang/cem/libcc.ansi/misc/.distr | 1 + lang/cem/libcc.ansi/misc/LIST | 1 + lang/cem/libcc.ansi/misc/hypot.c | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 lang/cem/libcc.ansi/misc/hypot.c diff --git a/lang/cem/libcc.ansi/misc/.distr b/lang/cem/libcc.ansi/misc/.distr index 5aab4d88b..f2c13a92c 100644 --- a/lang/cem/libcc.ansi/misc/.distr +++ b/lang/cem/libcc.ansi/misc/.distr @@ -21,3 +21,4 @@ sleep.c telldir.c termcap.c mktemp.c +hypot.c diff --git a/lang/cem/libcc.ansi/misc/LIST b/lang/cem/libcc.ansi/misc/LIST index 37407a345..bcf708244 100644 --- a/lang/cem/libcc.ansi/misc/LIST +++ b/lang/cem/libcc.ansi/misc/LIST @@ -19,3 +19,4 @@ seekdir.c telldir.c isatty.c mktemp.c +hypot.c diff --git a/lang/cem/libcc.ansi/misc/hypot.c b/lang/cem/libcc.ansi/misc/hypot.c new file mode 100644 index 000000000..b136ea0d0 --- /dev/null +++ b/lang/cem/libcc.ansi/misc/hypot.c @@ -0,0 +1,38 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Ceriel J.H. Jacobs + */ + +#include + +/* $Header$ */ + +double +hypot(double x,double y) +{ + /* Computes sqrt(x*x+y*y), avoiding overflow */ + + if (x < 0) x = -x; + if (y < 0) y = -y; + if (x > y) { + double t = y; + y = x; + x = t; + } + /* sqrt(x*x+y*y) = sqrt(y*y*(x*x/(y*y)+1.0)) = y*sqrt(x*x/(y*y)+1.0) */ + if (y == 0.0) return 0.0; + x /= y; + return y*sqrt(x*x+1.0); +} + +struct complex { + double r,i; +}; + +double +cabs(struct complex p_compl) +{ + return hypot(p_compl.r, p_compl.i); +} -- 2.34.1