add clamp_int

This commit is contained in:
2022-03-21 14:32:31 -07:00
parent 7c37a7bd28
commit 91e2ac1994
2 changed files with 10 additions and 0 deletions

View File

@ -16,6 +16,15 @@ int min_int(int a, int b) {
return b;
}
int clamp_int(int i, int low, int high) {
if (i > high) {
return high;
} else if (i < low) {
return low;
}
return i;
}
int binstr_to_int(const char *s) {
int n = 0, m = 1;
for (int i = (int)strlen(s) - 1; i >= 0; --i) {