Debian Codegraph @

src/h/impl/math_dispatch.h

raw symbols SCIP
1 /* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */
3
4 /*
5 * Copyright (c) 2010, Juan Jose Garcia Ripoll.
6 *
7 * See file 'LICENSE' for the copyright details.
8 *
9 */
10
11 /* math_dispatch.h -- fast dispatch for math functions */
12 #ifndef ECL_MATH_DISPATCH_H
13 #define ECL_MATH_DISPATCH_H
14
15 #include <ecl/internal.h> /* for unlikely_if */
16 #include <ecl/impl/math_fenv.h>
17
18 typedef cl_object (*math_one_arg_fn)(cl_object);
19
20 #ifdef ECL_COMPLEX_FLOAT
21 #define MATH_CFLOAT(c1,c2,c3) c1, c2, c3
22 #else
23 #define MATH_CFLOAT(c1,c2,c3)
24 #endif
25
26 #define MATH_DEF_DISPATCH1_NE(name,id,type,fix,big,ratio, \
27 single_float,double_float,long_float, \
28 complex,csfloat,cdfloat,clfloat) \
29 static cl_object name##failed(cl_object x) { \
30 FEwrong_type_only_arg(id, x, type); \
31 } \
32 static const math_one_arg_fn name##dispatch[t_last_number+1]= { \
33 name##failed, /* t_start */ \
34 name##failed, /* t_list */ \
35 name##failed, /* t_character */ \
36 fix, big, ratio, /* t_fixnum, t_bignum, t_ratio */ \
37 single_float, /* t_singlefloat */ \
38 double_float, /* t_doublefloat */ \
39 long_float, /* t_longfloat */ \
40 complex, /* t_complex */ \
41 MATH_CFLOAT(csfloat,cdfloat,clfloat) /* t_c?float */ }; \
42 cl_object ecl_##name(cl_object arg) \
43 { \
44 int t = ECL_IMMEDIATE(arg); \
45 if (t == 0) { \
46 t = arg->d.t; \
47 unlikely_if (t > t_last_number) return name##failed(arg); \
48 } \
49 return name##dispatch[t](arg); \
50 }
51
52 #define MATH_DEF_DISPATCH1(name,id,type,fix,big,ratio, \
53 single_float,double_float,long_float, \
54 complex,csfloat,cdfloat,clfloat) \
55 MATH_DEF_DISPATCH1_NE(name##_ne,id,type,fix,big,ratio, \
56 single_float,double_float,long_float, \
57 complex,csfloat,cdfloat,clfloat) \
58 cl_object ecl_##name(cl_object arg) \
59 { \
60 cl_object out; \
61 ECL_MATHERR_CLEAR; \
62 out = ecl_##name##_ne(arg); \
63 ECL_MATHERR_TEST; \
64 return out; \
65 }
66
67 typedef int (*math_one_arg_bool_fn)(cl_object);
68 #define MATH_DEF_DISPATCH1_BOOL(name,id,type,fix,big,ratio, \
69 single_float,double_float,long_float, \
70 complex,csfloat,cdfloat,clfloat) \
71 static int name##failed(cl_object x) { \
72 FEwrong_type_only_arg(id, x, type); \
73 } \
74 static const math_one_arg_bool_fn name##dispatch[t_last_number+1]= {\
75 name##failed, /* t_start */ \
76 name##failed, /* t_list */ \
77 name##failed, /* t_character */ \
78 fix, big, ratio, /* t_fixnum, t_bignum, t_ratio */ \
79 single_float, /* t_singlefloat */ \
80 double_float, /* t_doublefloat */ \
81 long_float, /* t_longfloat */ \
82 complex, /* t_complex */ \
83 MATH_CFLOAT(csfloat,cdfloat,clfloat) /* t_c?float */ }; \
84 int ecl_##name(cl_object arg) \
85 { \
86 int t = ECL_IMMEDIATE(arg); \
87 if (t == 0) { \
88 t = arg->d.t; \
89 unlikely_if (t > t_last_number) return name##failed(arg); \
90 } \
91 return name##dispatch[t](arg); \
92 }
93 #endif /* ECL_MATH_DISPATCH_H */