Debian Codegraph @

plugins/functions/math.c

raw symbols SCIP
1 /*
2 Copyright(C) 2017-2018 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifdef GRN_EMBEDDED
20 # define GRN_PLUGIN_FUNCTION_TAG functions_math
21 #endif
22
23 #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/
24
25 #include <math.h>
26 #include <stdlib.h>
27
28 static grn_objcxx . . $ grn_obj# *
29 func_math_abscxx . . $ func_math_abs(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, int n_args, grn_objcxx . . $ grn_obj# **args,
30 grn_user_datacxx . . $ grn_user_data# *user_data)
31 {
32 grn_objcxx . . $ grn_obj# *number;
33 grn_objcxx . . $ grn_obj# *grn_abs_number = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
34
35 if (n_args != 1) {
36 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_INVALID_ARGUMENT,
37 "math_abs(): wrong number of arguments (%d for 1)",
38 n_args);
39 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
40 }
41
42 number = args[0];
43 if (!(number->headercxx . . $ _grn_obj#header..typecxx . . $ _grn_obj_header#type. == GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`! &&
44 grn_type_id_is_number_familycxx . . $ grn_type_id_is_number_family(a2a496425acc5b40).(ctx, number->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.))) {
45 grn_objcxx . . $ grn_obj# inspected;
46
47 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
48 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, number);
49 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_INVALID_ARGUMENT,
50 "math_abs(): the first argument must be a number: "
51 "<%.*s>",
52 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
53 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
54 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
55 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
56 }
57
58 #define ABS_AS_IScxx . . $ `plugins/functions/math.c:58:9`!(return_type, to_type, getter, setter) { \
59 grn_abs_number = grn_plugin_proc_alloc(ctx, \
60 user_data, \
61 (return_type), \
62 0); \
63 if (!grn_abs_number) { \
64 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; \
65 } \
66 setter(ctx, grn_abs_number, getter(number)); \
67 }
68 #define ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!(func, return_type, to_type, getter, setter) { \
69 grn_abs_number = grn_plugin_proc_alloc(ctx, \
70 user_data, \
71 (return_type), \
72 0); \
73 if (!grn_abs_number) { \
74 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; \
75 } \
76 { \
77 to_type abs_number_raw = (to_type)(func)(getter(number)); \
78 setter(ctx, grn_abs_number, abs_number_raw); \
79 } \
80 }
81
82 switch (number->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.) {
83 case GRN_DB_INT8cxx . . $ GRN_DB_INT8.:
84 ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!(abs, GRN_DB_UINT8, uint8_t, GRN_INT8_VALUEcxx . . $ `include/groonga/groonga.h:3098:9`!, GRN_UINT8_SETcxx . . $ `include/groonga/groonga.h:2889:9`!);
85 break;
86 case GRN_DB_UINT8cxx . . $ GRN_DB_UINT8.:
87 ABS_AS_IScxx . . $ `plugins/functions/math.c:58:9`!(GRN_DB_UINT8, uint8_t, GRN_UINT8_VALUEcxx . . $ `include/groonga/groonga.h:3099:9`!, GRN_UINT8_SETcxx . . $ `include/groonga/groonga.h:2889:9`!);
88 break;
89 case GRN_DB_INT16cxx . . $ GRN_DB_INT16.:
90 ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!(abs, GRN_DB_UINT16, uint16_t, GRN_INT16_VALUEcxx . . $ `include/groonga/groonga.h:3100:9`!, GRN_UINT16_SETcxx . . $ `include/groonga/groonga.h:2899:9`!);
91 break;
92 case GRN_DB_UINT16cxx . . $ GRN_DB_UINT16.:
93 ABS_AS_IScxx . . $ `plugins/functions/math.c:58:9`!(GRN_DB_UINT16, uint16_t, GRN_UINT16_VALUEcxx . . $ `include/groonga/groonga.h:3101:9`!, GRN_UINT16_SETcxx . . $ `include/groonga/groonga.h:2899:9`!);
94 break;
95 case GRN_DB_INT32cxx . . $ GRN_DB_INT32.:
96 ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!(labs, GRN_DB_UINT32, uint32_t, GRN_INT32_VALUEcxx . . $ `include/groonga/groonga.h:3102:9`!, GRN_UINT32_SETcxx . . $ `include/groonga/groonga.h:2909:9`!);
97 break;
98 case GRN_DB_UINT32cxx . . $ GRN_DB_UINT32.:
99 ABS_AS_IScxx . . $ `plugins/functions/math.c:58:9`!(GRN_DB_UINT32, uint32_t, GRN_UINT32_VALUEcxx . . $ `include/groonga/groonga.h:3103:9`!, GRN_UINT32_SETcxx . . $ `include/groonga/groonga.h:2909:9`!);
100 break;
101 case GRN_DB_INT64cxx . . $ GRN_DB_INT64.:
102 ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!(llabs, GRN_DB_UINT64, uint64_t, GRN_INT64_VALUEcxx . . $ `include/groonga/groonga.h:3104:9`!, GRN_UINT64_SETcxx . . $ `include/groonga/groonga.h:2919:9`!);
103 break;
104 case GRN_DB_UINT64cxx . . $ GRN_DB_UINT64.:
105 ABS_AS_IScxx . . $ `plugins/functions/math.c:58:9`!(GRN_DB_UINT64, uint64_t, GRN_UINT64_VALUEcxx . . $ `include/groonga/groonga.h:3105:9`!, GRN_UINT64_SETcxx . . $ `include/groonga/groonga.h:2919:9`!);
106 break;
107 case GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.:
108 ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!(fabs, GRN_DB_FLOAT, double, GRN_FLOAT_VALUEcxx . . $ `include/groonga/groonga.h:3108:9`!, GRN_FLOAT_SETcxx . . $ `include/groonga/groonga.h:2934:9`!);
109 break;
110 default :
111 break;
112 }
113 #undef ABS_CONVERT_TYPEcxx . . $ `plugins/functions/math.c:68:9`!
114 #undef ABS_AS_IScxx . . $ `plugins/functions/math.c:58:9`!
115
116 return grn_abs_number;
117 }
118
119 grn_rccxx . . $ grn_rc#
120 GRN_PLUGIN_INITcxx . . $ `include/groonga/plugin.h:43:9`!(grn_ctxcxx . . $ grn_ctx# *ctx)
121 {
122 return ctx->rccxx . . $ _grn_ctx#rc.;
123 }
124
125 grn_rccxx . . $ grn_rc#
126 GRN_PLUGIN_REGISTERcxx . . $ `include/groonga/plugin.h:44:9`!(grn_ctxcxx . . $ grn_ctx# *ctx)
127 {
128 grn_rccxx . . $ grn_rc# rc = GRN_SUCCESScxx . . $ GRN_SUCCESS.;
129
130 grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx,
131 "math_abs", -1,
132 GRN_PROC_FUNCTIONcxx . . $ GRN_PROC_FUNCTION.,
133 func_math_abscxx . . $ func_math_abs(fd082858389c8bb0).,
134 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
135
136 return rc;
137 }
138
139 grn_rccxx . . $ grn_rc#
140 GRN_PLUGIN_FINcxx . . $ `include/groonga/plugin.h:45:9`!(grn_ctxcxx . . $ grn_ctx# *ctx)
141 {
142 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
143 }