src/cx/compare.h

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

mercurial