forked from waynegramlich/fiducials
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unsigned.c
63 lines (53 loc) · 1.93 KB
/
Unsigned.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) by Wayne C. Gramlich. All rights reserved.
#include "Integer.h"
#include "Logical.h"
#include "Unsigned.h"
/// @brief Return -1, 0, or 1 if depending on sort order.
/// @param unsigned1 is the left *Unsigned* to compare.
/// @param unsigned2 is the right *Unsigned* to compare.
/// @returns -1, 0, 1 depending on sort order.
///
/// *Unsigned__compare*() will return -1 if *unsigned1* is less than
/// *unsigned2*, zero if they are equal, and 1 if *unsigned1* greater
/// than *unsigned2*.
Integer Unsigned__compare(Unsigned unsigned1, Unsigned unsigned2) {
Integer result = 0;
if (unsigned1 < unsigned2) {
result = -1;
} else if (unsigned1 > unsigned2) {
result = 1;
}
return result;
}
/// @brief Return true if *unsigned1* equals *unsigned2*.
/// @param unsigned1 is the first *Unsigned* to compare.
/// @param unsigned2 is the second *Unsigned* to compare.
/// @returns true if *unsigned1* is equal to *unsigned2*.
///
/// *Unsigned__equal*() will return true (i.e. (*Logical*)1) if *unsigned1*
/// is equal to *unsigned2* and false (i.e. (*Logical*)0) otherwise.
Logical Unsigned__equal(Unsigned unsigned1, Unsigned unsigned2) {
return (Logical)(unsigned1 == unsigned2);
}
/// @brief Return a hash of *unsigned1*
/// @param unsigned1 the value to hash.
/// @returns hash value.
///
/// *Unsigned__hash*() will return a hash of *unsigned1*.
Unsigned Unsigned__hash(Unsigned unsigned1) {
return unsigned1;
}
/// @brief Return the minumum of *unsigned1* and *unsigned2*.
/// @param unsigned1 is the first *Unsigned* to compare.
/// @param unsigned2 is the second *Unsigned* to compare.
/// @returns the minumum of *unsigned1* and *unsigned2*.
///
/// *Unsigned__minimum*() will return the minimum of *unsigned1*
/// and *unsigned2*.
Unsigned Unsigned__minimum(Unsigned unsigned1, Unsigned unsigned2) {
Unsigned result = unsigned1;
if (unsigned2 < result) {
result = unsigned2;
}
return result;
}