| 1 |
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 |
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ |
| 3 |
|
| 4 |
/* |
| 5 |
* sinh.d - trascendental functions: exponential |
| 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_exp(cl_object x) |
| 24 |
{ |
| 25 |
@(return ecl_exp(x)); |
| 26 |
} |
| 27 |
|
| 28 |
static cl_object |
| 29 |
ecl_exp_rational(cl_object x) |
| 30 |
{ |
| 31 |
return ecl_make_single_float(expf(ecl_to_float(x))); |
| 32 |
} |
| 33 |
|
| 34 |
static cl_object |
| 35 |
ecl_exp_single_float(cl_object x) |
| 36 |
{ |
| 37 |
return ecl_make_single_float(expf(ecl_single_float(x))); |
| 38 |
} |
| 39 |
|
| 40 |
static cl_object |
| 41 |
ecl_exp_double_float(cl_object x) |
| 42 |
{ |
| 43 |
return ecl_make_double_float(exp(ecl_double_float(x))); |
| 44 |
} |
| 45 |
|
| 46 |
static cl_object |
| 47 |
ecl_exp_long_float(cl_object x) |
| 48 |
{ |
| 49 |
return ecl_make_long_float(expl(ecl_long_float(x))); |
| 50 |
} |
| 51 |
|
| 52 |
static cl_object |
| 53 |
ecl_exp_complex(cl_object x) |
| 54 |
{ |
| 55 |
cl_object y, y1; |
| 56 |
y = x->gencomplex.imag; |
| 57 |
x = ecl_exp(x->gencomplex.real); |
| 58 |
y1 = ecl_cos(y); |
| 59 |
y = ecl_sin(y); |
| 60 |
y = ecl_make_complex(y1, y); |
| 61 |
return ecl_times(x, y); |
| 62 |
} |
| 63 |
|
| 64 |
#ifdef ECL_COMPLEX_FLOAT |
| 65 |
static cl_object |
| 66 |
ecl_exp_csfloat(cl_object x) |
| 67 |
{ |
| 68 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 69 |
ecl_csfloat(result) = cexpf(ecl_csfloat(x)); |
| 70 |
return result; |
| 71 |
} |
| 72 |
|
| 73 |
static cl_object |
| 74 |
ecl_exp_cdfloat(cl_object x) |
| 75 |
{ |
| 76 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 77 |
ecl_cdfloat(result) = cexp(ecl_cdfloat(x)); |
| 78 |
return result; |
| 79 |
} |
| 80 |
|
| 81 |
static cl_object |
| 82 |
ecl_exp_clfloat(cl_object x) |
| 83 |
{ |
| 84 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 85 |
ecl_clfloat(result) = cexpl(ecl_clfloat(x)); |
| 86 |
return result; |
| 87 |
} |
| 88 |
#endif |
| 89 |
|
| 90 |
MATH_DEF_DISPATCH1(exp, @[exp], @[number], |
| 91 |
ecl_exp_rational, ecl_exp_rational, ecl_exp_rational, |
| 92 |
ecl_exp_single_float, ecl_exp_double_float, ecl_exp_long_float, |
| 93 |
ecl_exp_complex, |
| 94 |
ecl_exp_csfloat, ecl_exp_cdfloat, ecl_exp_clfloat); |