docs/Writerside/topics/compare.h.md

changeset 1188
b0300de92b72
parent 1174
ee473780cc0d
equal deleted inserted replaced
1187:0f70bb04f7ba 1188:b0300de92b72
1 # Compare Functions
2
3 The `compare.h` header file contains a collection of compare functions for various primitive types.
4
5 They come in two flavors:
6 - prefixed with `cx_vcmp` they are taking the values directly as arguments
7 - prefixed with `cx_cmp` the signature is designed to be compatible with the `cx_compare_func` function pointer type.
8
9 ## Examples
10
11 In the following example we use `cx_cmp_int32` as compare function for a `CxList` of `int32_t` values.
12
13 ```C
14 CxList *list = cxArrayListCreate(
15 cxDefaultAllocator, // use the default stdlib allocator
16 cx_cmp_int32, // the compare function for the elements
17 sizeof(int32_t), // the size of one element
18 256 // reseve space for 256 elements
19 );
20 ```
21
22 In the next example we simply want to compare two `double` values with rounding tolerance.
23 Note how the use of the `cx_vcmp` flavour makes it unnecessary to store the literal in a variable just to be able to take an address.
24 ```C
25 double x = ...
26
27 if (0 == cx_vcmp(x, 47.11)) {
28 // do something when equal (except tolerance)
29 }
30 ```
31
32 ## List of Functions
33
34 ```C
35 #include <cx/compare.h>
36
37 // Value Flavour
38 cx_vcmp_double
39 cx_vcmp_float
40 cx_vcmp_int
41 cx_vcmp_int16
42 cx_vcmp_int32
43 cx_vcmp_int64
44 cx_vcmp_intptr
45 cx_vcmp_longint
46 cx_vcmp_longlong
47 cx_vcmp_uint
48 cx_vcmp_uint16
49 cx_vcmp_uint32
50 cx_vcmp_uint64
51 cx_vcmp_uintptr
52 cx_vcmp_ulongint
53 cx_vcmp_ulonglong
54
55 // Pointer Flavour
56 cx_cmp_double
57 cx_cmp_float
58 cx_cmp_int
59 cx_cmp_int16
60 cx_cmp_int32
61 cx_cmp_int64
62 cx_cmp_intptr
63 cx_cmp_longint
64 cx_cmp_longlong
65 cx_cmp_ptr
66 cx_cmp_uint
67 cx_cmp_uint16
68 cx_cmp_uint32
69 cx_cmp_uint64
70 cx_cmp_uintptr
71 cx_cmp_ulongint
72 cx_cmp_ulonglong
73 ```
74
75 <seealso>
76 <category ref="apidoc">
77 <a href="https://ucx.sourceforge.io/api/compare_8h.html">compare.h</a>
78 </category>
79 </seealso>

mercurial