diff options
| author | Kristian Evers <kristianevers@gmail.com> | 2018-04-14 16:47:53 +0200 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2018-04-16 22:55:06 +0200 |
| commit | 327a8f8b5a850167901a92747767e14ffe77c03b (patch) | |
| tree | c1681555e256f97258b8624f2190b813c7fdd2c2 /src/hypot.c | |
| parent | ee22447de347c78944af849b10e0c9fd10184c28 (diff) | |
| download | PROJ-327a8f8b5a850167901a92747767e14ffe77c03b.tar.gz PROJ-327a8f8b5a850167901a92747767e14ffe77c03b.zip | |
Collect custom C99 math functions in proj_math.h
We are relying more and more on C99 math functions. On C89 systems where
those functions are not available our own custom versions of those
functions are used instead. So far these has been spread across the code
base. This commit gathers them in the same file and introduces the
proj_math.h header. The build system checks for C99 math functions. If
not found the proj_math.h header make sure that C99 functions are
defined as their pj_ equivalent.
Ideally proj_math.h is included instead of math.h. This removes the need
for any checks against HAVE_C99_MATH in the code making it easier to
read.
For this commit the functions hypot, log1p and asinh has been taken care
of.
Diffstat (limited to 'src/hypot.c')
| -rw-r--r-- | src/hypot.c | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/src/hypot.c b/src/hypot.c deleted file mode 100644 index 822c4595..00000000 --- a/src/hypot.c +++ /dev/null @@ -1,36 +0,0 @@ -/* hypot - sqrt(x * x + y * y) -** -** Because this was omitted from the ANSI standards, this version -** is included for those systems that do not include hypot as an -** extension to libm.a. Note: GNU version was not used because it -** was not properly coded to minimize potential overflow. -** -** The proper technique for determining hypot is to factor out the -** larger of the two terms, thus leaving a possible case of float -** overflow when max(x,y)*sqrt(2) > max machine value. This allows -** a wider range of numbers than the alternative of the sum of the -** squares < max machine value. For an Intel x87 IEEE double of -** approximately 1.8e308, only argument values > 1.27e308 are at -** risk of causing overflow. Whereas, not using this method limits -** the range to values less that 9.5e153 --- a considerable reduction -** in range! -*/ -extern double sqrt(double); - double -hypot(double x, double y) { - if ( x < 0.) - x = -x; - else if (x == 0.) - return (y < 0. ? -y : y); - if (y < 0.) - y = -y; - else if (y == 0.) - return (x); - if ( x < y ) { - x /= y; - return ( y * sqrt( 1. + x * x ) ); - } else { - y /= x; - return ( x * sqrt( 1. + y * y ) ); - } -} |
