Debian Codegraph @

src/c/numbers/cosh.d

raw
1 /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
3
4 /*
5 * ecl_constants.h - contstant values for all_symbols.d
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 #define ECL_INCLUDE_MATH_H
16 #include <ecl/ecl.h>
17 #include <ecl/internal.h>
18 #include <ecl/impl/math_dispatch.h>
19
20 #pragma STDC FENV_ACCESS ON
21
22 cl_object
23 cl_cosh(cl_object x)
24 {
25 @(return ecl_cosh(x));
26 }
27
28 static cl_object
29 ecl_cosh_rational(cl_object x)
30 {
31 return ecl_make_single_float(coshf(ecl_to_float(x)));
32 }
33
34 static cl_object
35 ecl_cosh_single_float(cl_object x)
36 {
37 return ecl_make_single_float(coshf(ecl_single_float(x)));
38 }
39
40 static cl_object
41 ecl_cosh_double_float(cl_object x)
42 {
43 return ecl_make_double_float(cosh(ecl_double_float(x)));
44 }
45
46 static cl_object
47 ecl_cosh_long_float(cl_object x)
48 {
49 return ecl_make_long_float(coshl(ecl_long_float(x)));
50 }
51
52 static cl_object
53 ecl_cosh_complex(cl_object x)
54 {
55 /*
56 z = x + I y
57 cosh(z) = (exp(z)+exp(-z))/2
58 = (exp(x)*(cos(y)+Isin(y))+exp(-x)*(cos(y)-Isin(y)))/2
59 = cosh(x)*cos(y) + Isinh(x)*sin(y);
60 */
61 cl_object dx = x->gencomplex.real;
62 cl_object dy = x->gencomplex.imag;
63 cl_object a = ecl_times(ecl_cosh(dx), ecl_cos(dy));
64 cl_object b = ecl_times(ecl_sinh(dx), ecl_sin(dy));
65 return ecl_make_complex(a, b);
66 }
67
68 #ifdef ECL_COMPLEX_FLOAT
69 static cl_object
70 ecl_cosh_csfloat(cl_object x)
71 {
72 cl_object result = ecl_alloc_object(t_csfloat);
73 ecl_csfloat(result) = ccoshf(ecl_csfloat(x));
74 return result;
75 }
76
77 static cl_object
78 ecl_cosh_cdfloat(cl_object x)
79 {
80 cl_object result = ecl_alloc_object(t_cdfloat);
81 ecl_cdfloat(result) = ccosh(ecl_cdfloat(x));
82 return result;
83 }
84
85 static cl_object
86 ecl_cosh_clfloat(cl_object x)
87 {
88 cl_object result = ecl_alloc_object(t_clfloat);
89 ecl_clfloat(result) = ccoshl(ecl_clfloat(x));
90 return result;
91 }
92 #endif
93
94 MATH_DEF_DISPATCH1(cosh, @[cosh], @[number],
95 ecl_cosh_rational, ecl_cosh_rational, ecl_cosh_rational,
96 ecl_cosh_single_float, ecl_cosh_double_float, ecl_cosh_long_float,
97 ecl_cosh_complex,
98 ecl_cosh_csfloat, ecl_cosh_cdfloat, ecl_cosh_clfloat);