| 1 |
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 |
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ |
| 3 |
|
| 4 |
/* |
| 5 |
* tanh.d - trascendental functions: hyperbolic tangent |
| 6 |
* |
| 7 |
* Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya |
| 8 |
* Copyright (c) 1990 Giuseppe Attardi |
| 9 |
* Copyright (c) 2001 Juan Jose Garcia Ripoll |
| 10 |
* |
| 11 |
* See file 'LICENSE' for the copyright details. |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
|
| 16 |
#define ECL_INCLUDE_MATH_H |
| 17 |
#include <ecl/ecl.h> |
| 18 |
#include <ecl/internal.h> |
| 19 |
#include <ecl/impl/math_dispatch.h> |
| 20 |
|
| 21 |
#pragma STDC FENV_ACCESS ON |
| 22 |
|
| 23 |
cl_object |
| 24 |
cl_tanh(cl_object x) |
| 25 |
{ |
| 26 |
@(return ecl_tanh(x)); |
| 27 |
} |
| 28 |
|
| 29 |
static cl_object |
| 30 |
ecl_tanh_rational(cl_object x) |
| 31 |
{ |
| 32 |
return ecl_make_single_float(tanhf(ecl_to_float(x))); |
| 33 |
} |
| 34 |
|
| 35 |
static cl_object |
| 36 |
ecl_tanh_single_float(cl_object x) |
| 37 |
{ |
| 38 |
return ecl_make_single_float(tanhf(ecl_single_float(x))); |
| 39 |
} |
| 40 |
|
| 41 |
static cl_object |
| 42 |
ecl_tanh_double_float(cl_object x) |
| 43 |
{ |
| 44 |
return ecl_make_double_float(tanh(ecl_double_float(x))); |
| 45 |
} |
| 46 |
|
| 47 |
static cl_object |
| 48 |
ecl_tanh_long_float(cl_object x) |
| 49 |
{ |
| 50 |
return ecl_make_long_float(tanhl(ecl_long_float(x))); |
| 51 |
} |
| 52 |
|
| 53 |
static cl_object |
| 54 |
ecl_tanh_complex(cl_object x) |
| 55 |
{ |
| 56 |
cl_object a = ecl_sinh(x); |
| 57 |
cl_object b = ecl_cosh(x); |
| 58 |
return ecl_divide(a, b); |
| 59 |
} |
| 60 |
|
| 61 |
#ifdef ECL_COMPLEX_FLOAT |
| 62 |
static cl_object |
| 63 |
ecl_tanh_csfloat(cl_object x) |
| 64 |
{ |
| 65 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 66 |
ecl_csfloat(result) = ctanhf(ecl_csfloat(x)); |
| 67 |
return result; |
| 68 |
} |
| 69 |
|
| 70 |
static cl_object |
| 71 |
ecl_tanh_cdfloat(cl_object x) |
| 72 |
{ |
| 73 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 74 |
ecl_cdfloat(result) = ctanh(ecl_cdfloat(x)); |
| 75 |
return result; |
| 76 |
} |
| 77 |
|
| 78 |
static cl_object |
| 79 |
ecl_tanh_clfloat(cl_object x) |
| 80 |
{ |
| 81 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 82 |
ecl_clfloat(result) = ctanhl(ecl_clfloat(x)); |
| 83 |
return result; |
| 84 |
} |
| 85 |
#endif |
| 86 |
|
| 87 |
MATH_DEF_DISPATCH1(tanh, @[tanh], @[number], |
| 88 |
ecl_tanh_rational, ecl_tanh_rational, ecl_tanh_rational, |
| 89 |
ecl_tanh_single_float, ecl_tanh_double_float, ecl_tanh_long_float, |
| 90 |
ecl_tanh_complex, |
| 91 |
ecl_tanh_csfloat, ecl_tanh_cdfloat, ecl_tanh_clfloat); |