Mercurial > mxe-octave
comparison src/build-msvctools/math/atanhf.c @ 3061:f8299bb6c872
Initial support for native MSVC compilation.
* add MSVC support files: compiler wrappers and support libraries
* adapt libiconv to work with MSVC
* adapt gettext to work with MSVC
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 17 Jun 2013 22:43:11 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3060:cbdf4575016d | 3061:f8299bb6c872 |
---|---|
1 #include <math.h> | |
2 #include <errno.h> | |
3 #include "fastmath.h" | |
4 | |
5 /* atanh (x) = 0.5 * log ((1.0 + x)/(1.0 - x)) */ | |
6 float atanhf (float x) | |
7 { | |
8 float z; | |
9 if isnan (x) | |
10 return x; | |
11 z = fabsf (x); | |
12 if (z == 1.0) | |
13 { | |
14 errno = ERANGE; | |
15 return (x > 0 ? INFINITY : -INFINITY); | |
16 } | |
17 if ( z > 1.0) | |
18 { | |
19 errno = EDOM; | |
20 return nanf(""); | |
21 } | |
22 /* Rearrange formula to avoid precision loss for small x. | |
23 | |
24 atanh(x) = 0.5 * log ((1.0 + x)/(1.0 - x)) | |
25 = 0.5 * log1p ((1.0 + x)/(1.0 - x) - 1.0) | |
26 = 0.5 * log1p ((1.0 + x - 1.0 + x) /(1.0 - x)) | |
27 = 0.5 * log1p ((2.0 * x ) / (1.0 - x)) */ | |
28 z = 0.5 * __fast_log1p ((z + z) / (1.0 - z)); | |
29 return x >= 0 ? z : -z; | |
30 } |