| 1 | /** |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. |
| 3 | * This file is part of the mingw-w64 runtime package. |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 | */ |
| 6 | #include "cephes_mconf.h" |
| 7 | #ifndef _SET_ERRNO |
| 8 | #define _SET_ERRNO(x) |
| 9 | #endif |
| 10 | |
| 11 | #if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ |
| 12 | #include <math.h> |
| 13 | |
| 14 | long double tanhl(long double x) |
| 15 | { |
| 16 | return tanh(x); |
| 17 | } |
| 18 | #else |
| 19 | |
| 20 | #ifdef UNK |
| 21 | static uLD P[] = { |
| 22 | { { -6.8473739392677100872869E-5L } }, |
| 23 | { { -9.5658283111794641589011E-1L } }, |
| 24 | { { -8.4053568599672284488465E1L } }, |
| 25 | { { -1.3080425704712825945553E3L } } |
| 26 | }; |
| 27 | static uLD Q[] = { |
| 28 | { { 9.6259501838840336946872E1L } }, |
| 29 | { { 1.8218117903645559060232E3L } }, |
| 30 | { { 3.9241277114138477845780E3L } } |
| 31 | }; |
| 32 | #endif |
| 33 | |
| 34 | #ifdef IBMPC |
| 35 | static uLD P[] = { |
| 36 | { { 0xd2a4,0x1b0c,0x8f15,0x8f99,0xbff1, 0, 0, 0 } }, |
| 37 | { { 0x5959,0x9111,0x9cc7,0xf4e2,0xbffe, 0, 0, 0 } }, |
| 38 | { { 0xb576,0xef5e,0x6d57,0xa81b,0xc005, 0, 0, 0 } }, |
| 39 | { { 0xe3be,0xbfbd,0x5cbc,0xa381,0xc009, 0, 0, 0 } } |
| 40 | }; |
| 41 | static uLD Q[] = { |
| 42 | { { 0x687f,0xce24,0xdd6c,0xc084,0x4005, 0, 0, 0 } }, |
| 43 | { { 0x3793,0xc95f,0xfa2f,0xe3b9,0x4009, 0, 0, 0 } }, |
| 44 | { { 0xd5a2,0x1f9c,0x0b1b,0xf542,0x400a, 0, 0, 0 } } |
| 45 | }; |
| 46 | #endif |
| 47 | |
| 48 | #ifdef MIEEE |
| 49 | static uLD P[] = { |
| 50 | { { 0xbff10000,0x8f998f15,0x1b0cd2a4, 0 } }, |
| 51 | { { 0xbffe0000,0xf4e29cc7,0x91115959, 0 } }, |
| 52 | { { 0xc0050000,0xa81b6d57,0xef5eb576, 0 } }, |
| 53 | { { 0xc0090000,0xa3815cbc,0xbfbde3be, 0 } } |
| 54 | }; |
| 55 | static uLD Q[] = { |
| 56 | { { 0x40050000,0xc084dd6c,0xce24687f, 0 } }, |
| 57 | { { 0x40090000,0xe3b9fa2f,0xc95f3793, 0 } }, |
| 58 | { { 0x400a0000,0xf5420b1b,0x1f9cd5a2, 0 } } |
| 59 | }; |
| 60 | #endif |
| 61 | |
| 62 | long double tanhl(long double x) |
| 63 | { |
| 64 | long double s, z; |
| 65 | |
| 66 | #ifdef MINUSZERO |
| 67 | if (x == 0.0L) |
| 68 | return (x); |
| 69 | #endif |
| 70 | if (isnanl(x)) |
| 71 | { |
| 72 | _SET_ERRNO (EDOM); |
| 73 | return x; |
| 74 | } |
| 75 | |
| 76 | z = fabsl(x); |
| 77 | if (z > 0.5L * MAXLOGL) |
| 78 | { |
| 79 | _SET_ERRNO (ERANGE); |
| 80 | if (x > 0) |
| 81 | return (1.0L); |
| 82 | else |
| 83 | return (-1.0L); |
| 84 | } |
| 85 | if (z >= 0.625L) |
| 86 | { |
| 87 | s = expl(2.0*z); |
| 88 | z = 1.0L - 2.0/(s + 1.0L); |
| 89 | if (x < 0) |
| 90 | z = -z; |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | s = x * x; |
| 95 | z = polevll( s, P, 3 )/p1evll(s, Q, 3); |
| 96 | z = x * s * z; |
| 97 | z = x + z; |
| 98 | } |
| 99 | return (z); |
| 100 | } |
| 101 | #endif |