ucx/cx/compare.h

changeset 16
04c9f8d8f03b
parent 11
0aa8cbd7912e
child 22
112b85020dc9
equal deleted inserted replaced
15:862ab606ee06 16:04c9f8d8f03b
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 /** 28 /**
29 * \file compare.h 29 * @file compare.h
30 * \brief A collection of simple compare functions. 30 * @brief A collection of simple compare functions.
31 * \author Mike Becker 31 * @author Mike Becker
32 * \author Olaf Wintermann 32 * @author Olaf Wintermann
33 * \copyright 2-Clause BSD License 33 * @copyright 2-Clause BSD License
34 */ 34 */
35 35
36 #ifndef UCX_COMPARE_H 36 #ifndef UCX_COMPARE_H
37 #define UCX_COMPARE_H 37 #define UCX_COMPARE_H
38 38
54 * can be used, but they are NOT compatible with this function 54 * can be used, but they are NOT compatible with this function
55 * pointer. 55 * pointer.
56 */ 56 */
57 cx_attr_nonnull 57 cx_attr_nonnull
58 cx_attr_nodiscard 58 cx_attr_nodiscard
59 typedef int(*cx_compare_func)( 59 cx_attr_export
60 const void *left, 60 typedef int (*cx_compare_func)(
61 const void *right 61 const void *left,
62 const void *right
62 ); 63 );
63 64
64 /** 65 /**
65 * Compares two integers of type int. 66 * Compares two integers of type int.
67 *
68 * @note the parameters deliberately have type @c void* to be
69 * compatible with #cx_compare_func without the need of a cast.
66 * 70 *
67 * @param i1 pointer to integer one 71 * @param i1 pointer to integer one
68 * @param i2 pointer to integer two 72 * @param i2 pointer to integer two
69 * @return -1, if *i1 is less than *i2, 0 if both are equal, 73 * @retval -1 if the left argument is less than the right argument
70 * 1 if *i1 is greater than *i2 74 * @retval 0 if both arguments are equal
71 */ 75 * @retval 1 if the left argument is greater than the right argument
72 cx_attr_nonnull 76 */
73 cx_attr_nodiscard 77 cx_attr_nonnull
78 cx_attr_nodiscard
79 cx_attr_export
74 int cx_cmp_int(const void *i1, const void *i2); 80 int cx_cmp_int(const void *i1, const void *i2);
75 81
76 /** 82 /**
77 * Compares two ints. 83 * Compares two integers of type int.
78 * 84 *
79 * @param i1 integer one 85 * @param i1 integer one
80 * @param i2 integer two 86 * @param i2 integer two
81 * @return -1, if i1 is less than i2, 0 if both are equal, 87 * @retval -1 if the left argument is less than the right argument
82 * 1 if i1 is greater than i2 88 * @retval 0 if both arguments are equal
83 */ 89 * @retval 1 if the left argument is greater than the right argument
84 cx_attr_nodiscard 90 */
91 cx_attr_nodiscard
92 cx_attr_export
85 int cx_vcmp_int(int i1, int i2); 93 int cx_vcmp_int(int i1, int i2);
86 94
87 /** 95 /**
88 * Compares two integers of type long int. 96 * Compares two integers of type long int.
97 *
98 * @note the parameters deliberately have type @c void* to be
99 * compatible with #cx_compare_func without the need of a cast.
89 * 100 *
90 * @param i1 pointer to long integer one 101 * @param i1 pointer to long integer one
91 * @param i2 pointer to long integer two 102 * @param i2 pointer to long integer two
92 * @return -1, if *i1 is less than *i2, 0 if both are equal, 103 * @retval -1 if the left argument is less than the right argument
93 * 1 if *i1 is greater than *i2 104 * @retval 0 if both arguments are equal
94 */ 105 * @retval 1 if the left argument is greater than the right argument
95 cx_attr_nonnull 106 */
96 cx_attr_nodiscard 107 cx_attr_nonnull
108 cx_attr_nodiscard
109 cx_attr_export
97 int cx_cmp_longint(const void *i1, const void *i2); 110 int cx_cmp_longint(const void *i1, const void *i2);
98 111
99 /** 112 /**
100 * Compares two long ints. 113 * Compares two integers of type long int.
101 * 114 *
102 * @param i1 long integer one 115 * @param i1 long integer one
103 * @param i2 long integer two 116 * @param i2 long integer two
104 * @return -1, if i1 is less than i2, 0 if both are equal, 117 * @retval -1 if the left argument is less than the right argument
105 * 1 if i1 is greater than i2 118 * @retval 0 if both arguments are equal
106 */ 119 * @retval 1 if the left argument is greater than the right argument
107 cx_attr_nodiscard 120 */
121 cx_attr_nodiscard
122 cx_attr_export
108 int cx_vcmp_longint(long int i1, long int i2); 123 int cx_vcmp_longint(long int i1, long int i2);
109 124
110 /** 125 /**
111 * Compares two integers of type long long. 126 * Compares two integers of type long long.
127 *
128 * @note the parameters deliberately have type @c void* to be
129 * compatible with #cx_compare_func without the need of a cast.
112 * 130 *
113 * @param i1 pointer to long long one 131 * @param i1 pointer to long long one
114 * @param i2 pointer to long long two 132 * @param i2 pointer to long long two
115 * @return -1, if *i1 is less than *i2, 0 if both are equal, 133 * @retval -1 if the left argument is less than the right argument
116 * 1 if *i1 is greater than *i2 134 * @retval 0 if both arguments are equal
117 */ 135 * @retval 1 if the left argument is greater than the right argument
118 cx_attr_nonnull 136 */
119 cx_attr_nodiscard 137 cx_attr_nonnull
138 cx_attr_nodiscard
139 cx_attr_export
120 int cx_cmp_longlong(const void *i1, const void *i2); 140 int cx_cmp_longlong(const void *i1, const void *i2);
121 141
122 /** 142 /**
123 * Compares twolong long ints. 143 * Compares two integers of type long long.
124 * 144 *
125 * @param i1 long long int one 145 * @param i1 long long int one
126 * @param i2 long long int two 146 * @param i2 long long int two
127 * @return -1, if i1 is less than i2, 0 if both are equal, 147 * @retval -1 if the left argument is less than the right argument
128 * 1 if i1 is greater than i2 148 * @retval 0 if both arguments are equal
129 */ 149 * @retval 1 if the left argument is greater than the right argument
130 cx_attr_nodiscard 150 */
151 cx_attr_nodiscard
152 cx_attr_export
131 int cx_vcmp_longlong(long long int i1, long long int i2); 153 int cx_vcmp_longlong(long long int i1, long long int i2);
132 154
133 /** 155 /**
134 * Compares two integers of type int16_t. 156 * Compares two integers of type int16_t.
157 *
158 * @note the parameters deliberately have type @c void* to be
159 * compatible with #cx_compare_func without the need of a cast.
135 * 160 *
136 * @param i1 pointer to int16_t one 161 * @param i1 pointer to int16_t one
137 * @param i2 pointer to int16_t two 162 * @param i2 pointer to int16_t two
138 * @return -1, if *i1 is less than *i2, 0 if both are equal, 163 * @retval -1 if the left argument is less than the right argument
139 * 1 if *i1 is greater than *i2 164 * @retval 0 if both arguments are equal
140 */ 165 * @retval 1 if the left argument is greater than the right argument
141 cx_attr_nonnull 166 */
142 cx_attr_nodiscard 167 cx_attr_nonnull
168 cx_attr_nodiscard
169 cx_attr_export
143 int cx_cmp_int16(const void *i1, const void *i2); 170 int cx_cmp_int16(const void *i1, const void *i2);
144 171
145 /** 172 /**
146 * Compares two integers of type int16_t. 173 * Compares two integers of type int16_t.
147 * 174 *
148 * @param i1 int16_t one 175 * @param i1 int16_t one
149 * @param i2 int16_t two 176 * @param i2 int16_t two
150 * @return -1, if i1 is less than i2, 0 if both are equal, 177 * @retval -1 if the left argument is less than the right argument
151 * 1 if i1 is greater than i2 178 * @retval 0 if both arguments are equal
152 */ 179 * @retval 1 if the left argument is greater than the right argument
153 cx_attr_nodiscard 180 */
181 cx_attr_nodiscard
182 cx_attr_export
154 int cx_vcmp_int16(int16_t i1, int16_t i2); 183 int cx_vcmp_int16(int16_t i1, int16_t i2);
155 184
156 /** 185 /**
157 * Compares two integers of type int32_t. 186 * Compares two integers of type int32_t.
187 *
188 * @note the parameters deliberately have type @c void* to be
189 * compatible with #cx_compare_func without the need of a cast.
158 * 190 *
159 * @param i1 pointer to int32_t one 191 * @param i1 pointer to int32_t one
160 * @param i2 pointer to int32_t two 192 * @param i2 pointer to int32_t two
161 * @return -1, if *i1 is less than *i2, 0 if both are equal, 193 * @retval -1 if the left argument is less than the right argument
162 * 1 if *i1 is greater than *i2 194 * @retval 0 if both arguments are equal
163 */ 195 * @retval 1 if the left argument is greater than the right argument
164 cx_attr_nonnull 196 */
165 cx_attr_nodiscard 197 cx_attr_nonnull
198 cx_attr_nodiscard
199 cx_attr_export
166 int cx_cmp_int32(const void *i1, const void *i2); 200 int cx_cmp_int32(const void *i1, const void *i2);
167 201
168 /** 202 /**
169 * Compares two integers of type int32_t. 203 * Compares two integers of type int32_t.
170 * 204 *
171 * @param i1 int32_t one 205 * @param i1 int32_t one
172 * @param i2 int32_t two 206 * @param i2 int32_t two
173 * @return -1, if i1 is less than i2, 0 if both are equal, 207 * @retval -1 if the left argument is less than the right argument
174 * 1 if i1 is greater than i2 208 * @retval 0 if both arguments are equal
175 */ 209 * @retval 1 if the left argument is greater than the right argument
176 cx_attr_nodiscard 210 */
211 cx_attr_nodiscard
212 cx_attr_export
177 int cx_vcmp_int32(int32_t i1, int32_t i2); 213 int cx_vcmp_int32(int32_t i1, int32_t i2);
178 214
179 /** 215 /**
180 * Compares two integers of type int64_t. 216 * Compares two integers of type int64_t.
217 *
218 * @note the parameters deliberately have type @c void* to be
219 * compatible with #cx_compare_func without the need of a cast.
181 * 220 *
182 * @param i1 pointer to int64_t one 221 * @param i1 pointer to int64_t one
183 * @param i2 pointer to int64_t two 222 * @param i2 pointer to int64_t two
184 * @return -1, if *i1 is less than *i2, 0 if both are equal, 223 * @retval -1 if the left argument is less than the right argument
185 * 1 if *i1 is greater than *i2 224 * @retval 0 if both arguments are equal
186 */ 225 * @retval 1 if the left argument is greater than the right argument
187 cx_attr_nonnull 226 */
188 cx_attr_nodiscard 227 cx_attr_nonnull
228 cx_attr_nodiscard
229 cx_attr_export
189 int cx_cmp_int64(const void *i1, const void *i2); 230 int cx_cmp_int64(const void *i1, const void *i2);
190 231
191 /** 232 /**
192 * Compares two integers of type int64_t. 233 * Compares two integers of type int64_t.
193 * 234 *
194 * @param i1 int64_t one 235 * @param i1 int64_t one
195 * @param i2 int64_t two 236 * @param i2 int64_t two
196 * @return -1, if i1 is less than i2, 0 if both are equal, 237 * @retval -1 if the left argument is less than the right argument
197 * 1 if i1 is greater than i2 238 * @retval 0 if both arguments are equal
198 */ 239 * @retval 1 if the left argument is greater than the right argument
199 cx_attr_nodiscard 240 */
241 cx_attr_nodiscard
242 cx_attr_export
200 int cx_vcmp_int64(int64_t i1, int64_t i2); 243 int cx_vcmp_int64(int64_t i1, int64_t i2);
201 244
202 /** 245 /**
203 * Compares two integers of type unsigned int. 246 * Compares two integers of type unsigned int.
247 *
248 * @note the parameters deliberately have type @c void* to be
249 * compatible with #cx_compare_func without the need of a cast.
204 * 250 *
205 * @param i1 pointer to unsigned integer one 251 * @param i1 pointer to unsigned integer one
206 * @param i2 pointer to unsigned integer two 252 * @param i2 pointer to unsigned integer two
207 * @return -1, if *i1 is less than *i2, 0 if both are equal, 253 * @retval -1 if the left argument is less than the right argument
208 * 1 if *i1 is greater than *i2 254 * @retval 0 if both arguments are equal
209 */ 255 * @retval 1 if the left argument is greater than the right argument
210 cx_attr_nonnull 256 */
211 cx_attr_nodiscard 257 cx_attr_nonnull
258 cx_attr_nodiscard
259 cx_attr_export
212 int cx_cmp_uint(const void *i1, const void *i2); 260 int cx_cmp_uint(const void *i1, const void *i2);
213 261
214 /** 262 /**
215 * Compares two unsigned ints. 263 * Compares two integers of type unsigned int.
216 * 264 *
217 * @param i1 unsigned integer one 265 * @param i1 unsigned integer one
218 * @param i2 unsigned integer two 266 * @param i2 unsigned integer two
219 * @return -1, if i1 is less than i2, 0 if both are equal, 267 * @retval -1 if the left argument is less than the right argument
220 * 1 if i1 is greater than i2 268 * @retval 0 if both arguments are equal
221 */ 269 * @retval 1 if the left argument is greater than the right argument
222 cx_attr_nodiscard 270 */
271 cx_attr_nodiscard
272 cx_attr_export
223 int cx_vcmp_uint(unsigned int i1, unsigned int i2); 273 int cx_vcmp_uint(unsigned int i1, unsigned int i2);
224 274
225 /** 275 /**
226 * Compares two integers of type unsigned long int. 276 * Compares two integers of type unsigned long int.
277 *
278 * @note the parameters deliberately have type @c void* to be
279 * compatible with #cx_compare_func without the need of a cast.
227 * 280 *
228 * @param i1 pointer to unsigned long integer one 281 * @param i1 pointer to unsigned long integer one
229 * @param i2 pointer to unsigned long integer two 282 * @param i2 pointer to unsigned long integer two
230 * @return -1, if *i1 is less than *i2, 0 if both are equal, 283 * @retval -1 if the left argument is less than the right argument
231 * 1 if *i1 is greater than *i2 284 * @retval 0 if both arguments are equal
232 */ 285 * @retval 1 if the left argument is greater than the right argument
233 cx_attr_nonnull 286 */
234 cx_attr_nodiscard 287 cx_attr_nonnull
288 cx_attr_nodiscard
289 cx_attr_export
235 int cx_cmp_ulongint(const void *i1, const void *i2); 290 int cx_cmp_ulongint(const void *i1, const void *i2);
236 291
237 /** 292 /**
238 * Compares two unsigned long ints. 293 * Compares two integers of type unsigned long int.
239 * 294 *
240 * @param i1 unsigned long integer one 295 * @param i1 unsigned long integer one
241 * @param i2 unsigned long integer two 296 * @param i2 unsigned long integer two
242 * @return -1, if i1 is less than i2, 0 if both are equal, 297 * @retval -1 if the left argument is less than the right argument
243 * 1 if i1 is greater than i2 298 * @retval 0 if both arguments are equal
244 */ 299 * @retval 1 if the left argument is greater than the right argument
245 cx_attr_nodiscard 300 */
301 cx_attr_nodiscard
302 cx_attr_export
246 int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2); 303 int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2);
247 304
248 /** 305 /**
249 * Compares two integers of type unsigned long long. 306 * Compares two integers of type unsigned long long.
307 *
308 * @note the parameters deliberately have type @c void* to be
309 * compatible with #cx_compare_func without the need of a cast.
250 * 310 *
251 * @param i1 pointer to unsigned long long one 311 * @param i1 pointer to unsigned long long one
252 * @param i2 pointer to unsigned long long two 312 * @param i2 pointer to unsigned long long two
253 * @return -1, if *i1 is less than *i2, 0 if both are equal, 313 * @retval -1 if the left argument is less than the right argument
254 * 1 if *i1 is greater than *i2 314 * @retval 0 if both arguments are equal
255 */ 315 * @retval 1 if the left argument is greater than the right argument
256 cx_attr_nonnull 316 */
257 cx_attr_nodiscard 317 cx_attr_nonnull
318 cx_attr_nodiscard
319 cx_attr_export
258 int cx_cmp_ulonglong(const void *i1, const void *i2); 320 int cx_cmp_ulonglong(const void *i1, const void *i2);
259 321
260 /** 322 /**
261 * Compares two unsigned long long ints. 323 * Compares two integers of type unsigned long long.
262 * 324 *
263 * @param i1 unsigned long long one 325 * @param i1 unsigned long long one
264 * @param i2 unsigned long long two 326 * @param i2 unsigned long long two
265 * @return -1, if i1 is less than i2, 0 if both are equal, 327 * @retval -1 if the left argument is less than the right argument
266 * 1 if i1 is greater than i2 328 * @retval 0 if both arguments are equal
267 */ 329 * @retval 1 if the left argument is greater than the right argument
268 cx_attr_nodiscard 330 */
331 cx_attr_nodiscard
332 cx_attr_export
269 int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2); 333 int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2);
270 334
271 /** 335 /**
272 * Compares two integers of type uint16_t. 336 * Compares two integers of type uint16_t.
337 *
338 * @note the parameters deliberately have type @c void* to be
339 * compatible with #cx_compare_func without the need of a cast.
273 * 340 *
274 * @param i1 pointer to uint16_t one 341 * @param i1 pointer to uint16_t one
275 * @param i2 pointer to uint16_t two 342 * @param i2 pointer to uint16_t two
276 * @return -1, if *i1 is less than *i2, 0 if both are equal, 343 * @retval -1 if the left argument is less than the right argument
277 * 1 if *i1 is greater than *i2 344 * @retval 0 if both arguments are equal
278 */ 345 * @retval 1 if the left argument is greater than the right argument
279 cx_attr_nonnull 346 */
280 cx_attr_nodiscard 347 cx_attr_nonnull
348 cx_attr_nodiscard
349 cx_attr_export
281 int cx_cmp_uint16(const void *i1, const void *i2); 350 int cx_cmp_uint16(const void *i1, const void *i2);
282 351
283 /** 352 /**
284 * Compares two integers of type uint16_t. 353 * Compares two integers of type uint16_t.
285 * 354 *
286 * @param i1 uint16_t one 355 * @param i1 uint16_t one
287 * @param i2 uint16_t two 356 * @param i2 uint16_t two
288 * @return -1, if i1 is less than i2, 0 if both are equal, 357 * @retval -1 if the left argument is less than the right argument
289 * 1 if i1 is greater than i2 358 * @retval 0 if both arguments are equal
290 */ 359 * @retval 1 if the left argument is greater than the right argument
291 cx_attr_nodiscard 360 */
361 cx_attr_nodiscard
362 cx_attr_export
292 int cx_vcmp_uint16(uint16_t i1, uint16_t i2); 363 int cx_vcmp_uint16(uint16_t i1, uint16_t i2);
293 364
294 /** 365 /**
295 * Compares two integers of type uint32_t. 366 * Compares two integers of type uint32_t.
367 *
368 * @note the parameters deliberately have type @c void* to be
369 * compatible with #cx_compare_func without the need of a cast.
296 * 370 *
297 * @param i1 pointer to uint32_t one 371 * @param i1 pointer to uint32_t one
298 * @param i2 pointer to uint32_t two 372 * @param i2 pointer to uint32_t two
299 * @return -1, if *i1 is less than *i2, 0 if both are equal, 373 * @retval -1 if the left argument is less than the right argument
300 * 1 if *i1 is greater than *i2 374 * @retval 0 if both arguments are equal
301 */ 375 * @retval 1 if the left argument is greater than the right argument
302 cx_attr_nonnull 376 */
303 cx_attr_nodiscard 377 cx_attr_nonnull
378 cx_attr_nodiscard
379 cx_attr_export
304 int cx_cmp_uint32(const void *i1, const void *i2); 380 int cx_cmp_uint32(const void *i1, const void *i2);
305 381
306 /** 382 /**
307 * Compares two integers of type uint32_t. 383 * Compares two integers of type uint32_t.
308 * 384 *
309 * @param i1 uint32_t one 385 * @param i1 uint32_t one
310 * @param i2 uint32_t two 386 * @param i2 uint32_t two
311 * @return -1, if i1 is less than i2, 0 if both are equal, 387 * @retval -1 if the left argument is less than the right argument
312 * 1 if i1 is greater than i2 388 * @retval 0 if both arguments are equal
313 */ 389 * @retval 1 if the left argument is greater than the right argument
314 cx_attr_nodiscard 390 */
391 cx_attr_nodiscard
392 cx_attr_export
315 int cx_vcmp_uint32(uint32_t i1, uint32_t i2); 393 int cx_vcmp_uint32(uint32_t i1, uint32_t i2);
316 394
317 /** 395 /**
318 * Compares two integers of type uint64_t. 396 * Compares two integers of type uint64_t.
397 *
398 * @note the parameters deliberately have type @c void* to be
399 * compatible with #cx_compare_func without the need of a cast.
319 * 400 *
320 * @param i1 pointer to uint64_t one 401 * @param i1 pointer to uint64_t one
321 * @param i2 pointer to uint64_t two 402 * @param i2 pointer to uint64_t two
322 * @return -1, if *i1 is less than *i2, 0 if both are equal, 403 * @retval -1 if the left argument is less than the right argument
323 * 1 if *i1 is greater than *i2 404 * @retval 0 if both arguments are equal
324 */ 405 * @retval 1 if the left argument is greater than the right argument
325 cx_attr_nonnull 406 */
326 cx_attr_nodiscard 407 cx_attr_nonnull
408 cx_attr_nodiscard
409 cx_attr_export
327 int cx_cmp_uint64(const void *i1, const void *i2); 410 int cx_cmp_uint64(const void *i1, const void *i2);
328 411
329 /** 412 /**
330 * Compares two integers of type uint64_t. 413 * Compares two integers of type uint64_t.
331 * 414 *
332 * @param i1 uint64_t one 415 * @param i1 uint64_t one
333 * @param i2 uint64_t two 416 * @param i2 uint64_t two
334 * @return -1, if i1 is less than i2, 0 if both are equal, 417 * @retval -1 if the left argument is less than the right argument
335 * 1 if i1 is greater than i2 418 * @retval 0 if both arguments are equal
336 */ 419 * @retval 1 if the left argument is greater than the right argument
337 cx_attr_nodiscard 420 */
421 cx_attr_nodiscard
422 cx_attr_export
338 int cx_vcmp_uint64(uint64_t i1, uint64_t i2); 423 int cx_vcmp_uint64(uint64_t i1, uint64_t i2);
339 424
340 /** 425 /**
341 * Compares two real numbers of type float with precision 1e-6f. 426 * Compares two real numbers of type float with precision 1e-6f.
427 *
428 * @note the parameters deliberately have type @c void* to be
429 * compatible with #cx_compare_func without the need of a cast.
342 * 430 *
343 * @param f1 pointer to float one 431 * @param f1 pointer to float one
344 * @param f2 pointer to float two 432 * @param f2 pointer to float two
345 * @return -1, if *f1 is less than *f2, 0 if both are equal, 433 * @retval -1 if the left argument is less than the right argument
346 * 1 if *f1 is greater than *f2 434 * @retval 0 if both arguments are equal
347 */ 435 * @retval 1 if the left argument is greater than the right argument
348 cx_attr_nonnull 436 */
349 cx_attr_nodiscard 437 cx_attr_nonnull
438 cx_attr_nodiscard
439 cx_attr_export
350 int cx_cmp_float(const void *f1, const void *f2); 440 int cx_cmp_float(const void *f1, const void *f2);
351 441
352 /** 442 /**
353 * Compares two real numbers of type float with precision 1e-6f. 443 * Compares two real numbers of type float with precision 1e-6f.
354 * 444 *
355 * @param f1 float one 445 * @param f1 float one
356 * @param f2 float two 446 * @param f2 float two
357 * @return -1, if f1 is less than f2, 0 if both are equal, 447 * @retval -1 if the left argument is less than the right argument
358 * 1 if f1 is greater than f2 448 * @retval 0 if both arguments are equal
359 */ 449 * @retval 1 if the left argument is greater than the right argument
360 cx_attr_nodiscard 450 */
451 cx_attr_nodiscard
452 cx_attr_export
361 int cx_vcmp_float(float f1, float f2); 453 int cx_vcmp_float(float f1, float f2);
362 454
363 /** 455 /**
364 * Compares two real numbers of type double with precision 1e-14. 456 * Compares two real numbers of type double with precision 1e-14.
457 *
458 * @note the parameters deliberately have type @c void* to be
459 * compatible with #cx_compare_func without the need of a cast.
365 * 460 *
366 * @param d1 pointer to double one 461 * @param d1 pointer to double one
367 * @param d2 pointer to double two 462 * @param d2 pointer to double two
368 * @return -1, if *d1 is less than *d2, 0 if both are equal, 463 * @retval -1 if the left argument is less than the right argument
369 * 1 if *d1 is greater than *d2 464 * @retval 0 if both arguments are equal
370 */ 465 * @retval 1 if the left argument is greater than the right argument
371 cx_attr_nonnull 466 */
372 cx_attr_nodiscard 467 cx_attr_nonnull
468 cx_attr_nodiscard
469 cx_attr_export
373 int cx_cmp_double(const void *d1, const void *d2); 470 int cx_cmp_double(const void *d1, const void *d2);
374 471
375 /** 472 /**
376 * Convenience function 473 * Compares two real numbers of type double with precision 1e-14.
377 * 474 *
378 * @param d1 double one 475 * @param d1 double one
379 * @param d2 double two 476 * @param d2 double two
380 * @return -1, if d1 is less than d2, 0 if both are equal, 477 * @retval -1 if the left argument is less than the right argument
381 * 1 if d1 is greater than d2 478 * @retval 0 if both arguments are equal
382 */ 479 * @retval 1 if the left argument is greater than the right argument
383 cx_attr_nodiscard 480 */
481 cx_attr_nodiscard
482 cx_attr_export
384 int cx_vcmp_double(double d1, double d2); 483 int cx_vcmp_double(double d1, double d2);
385 484
386 /** 485 /**
387 * Compares the integer representation of two pointers. 486 * Compares the integer representation of two pointers.
487 *
488 * @note the parameters deliberately have type @c void* to be
489 * compatible with #cx_compare_func without the need of a cast.
388 * 490 *
389 * @param ptr1 pointer to pointer one (const intptr_t*) 491 * @param ptr1 pointer to pointer one (const intptr_t*)
390 * @param ptr2 pointer to pointer two (const intptr_t*) 492 * @param ptr2 pointer to pointer two (const intptr_t*)
391 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, 493 * @retval -1 if the left argument is less than the right argument
392 * 1 if *ptr1 is greater than *ptr2 494 * @retval 0 if both arguments are equal
393 */ 495 * @retval 1 if the left argument is greater than the right argument
394 cx_attr_nonnull 496 */
395 cx_attr_nodiscard 497 cx_attr_nonnull
498 cx_attr_nodiscard
499 cx_attr_export
396 int cx_cmp_intptr(const void *ptr1, const void *ptr2); 500 int cx_cmp_intptr(const void *ptr1, const void *ptr2);
397 501
398 /** 502 /**
399 * Compares the integer representation of two pointers. 503 * Compares the integer representation of two pointers.
400 * 504 *
401 * @param ptr1 pointer one 505 * @param ptr1 pointer one
402 * @param ptr2 pointer two 506 * @param ptr2 pointer two
403 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, 507 * @retval -1 if the left argument is less than the right argument
404 * 1 if ptr1 is greater than ptr2 508 * @retval 0 if both arguments are equal
405 */ 509 * @retval 1 if the left argument is greater than the right argument
406 cx_attr_nodiscard 510 */
511 cx_attr_nodiscard
512 cx_attr_export
407 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2); 513 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2);
408 514
409 /** 515 /**
410 * Compares the unsigned integer representation of two pointers. 516 * Compares the unsigned integer representation of two pointers.
517 *
518 * @note the parameters deliberately have type @c void* to be
519 * compatible with #cx_compare_func without the need of a cast.
411 * 520 *
412 * @param ptr1 pointer to pointer one (const uintptr_t*) 521 * @param ptr1 pointer to pointer one (const uintptr_t*)
413 * @param ptr2 pointer to pointer two (const uintptr_t*) 522 * @param ptr2 pointer to pointer two (const uintptr_t*)
414 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, 523 * @retval -1 if the left argument is less than the right argument
415 * 1 if *ptr1 is greater than *ptr2 524 * @retval 0 if both arguments are equal
416 */ 525 * @retval 1 if the left argument is greater than the right argument
417 cx_attr_nonnull 526 */
418 cx_attr_nodiscard 527 cx_attr_nonnull
528 cx_attr_nodiscard
529 cx_attr_export
419 int cx_cmp_uintptr(const void *ptr1, const void *ptr2); 530 int cx_cmp_uintptr(const void *ptr1, const void *ptr2);
420 531
421 /** 532 /**
422 * Compares the unsigned integer representation of two pointers. 533 * Compares the unsigned integer representation of two pointers.
423 * 534 *
424 * @param ptr1 pointer one 535 * @param ptr1 pointer one
425 * @param ptr2 pointer two 536 * @param ptr2 pointer two
426 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, 537 * @retval -1 if the left argument is less than the right argument
427 * 1 if ptr1 is greater than ptr2 538 * @retval 0 if both arguments are equal
428 */ 539 * @retval 1 if the left argument is greater than the right argument
429 cx_attr_nodiscard 540 */
541 cx_attr_nodiscard
542 cx_attr_export
430 int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2); 543 int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2);
431 544
432 /** 545 /**
433 * Compares the pointers specified in the arguments without de-referencing. 546 * Compares the pointers specified in the arguments without dereferencing.
434 * 547 *
435 * @param ptr1 pointer one 548 * @param ptr1 pointer one
436 * @param ptr2 pointer two 549 * @param ptr2 pointer two
437 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, 550 * @retval -1 if the left argument is less than the right argument
438 * 1 if ptr1 is greater than ptr2 551 * @retval 0 if both arguments are equal
439 */ 552 * @retval 1 if the left argument is greater than the right argument
440 cx_attr_nonnull 553 */
441 cx_attr_nodiscard 554 cx_attr_nonnull
555 cx_attr_nodiscard
556 cx_attr_export
442 int cx_cmp_ptr(const void *ptr1, const void *ptr2); 557 int cx_cmp_ptr(const void *ptr1, const void *ptr2);
443 558
444 #ifdef __cplusplus 559 #ifdef __cplusplus
445 } // extern "C" 560 } // extern "C"
446 #endif 561 #endif

mercurial