diff options
author | axtlos <axtlos@disroot.org> | 2024-09-23 23:01:51 +0200 |
---|---|---|
committer | axtlos <axtlos@disroot.org> | 2024-09-23 23:01:51 +0200 |
commit | 8996ee7580ed85b42b6399f9f64e29092ce21c41 (patch) | |
tree | 3cec945364e91e6504edf9a6c533fa104a0d3f34 /src | |
parent | d9aeb51683449ef79339c9ca3c80059c17dec599 (diff) | |
download | extlib-8996ee7580ed85b42b6399f9f64e29092ce21c41.tar.gz extlib-8996ee7580ed85b42b6399f9f64e29092ce21c41.tar.bz2 |
Add cap,min,max functions
Diffstat (limited to 'src')
-rw-r--r-- | src/extlib.c | 18 | ||||
-rw-r--r-- | src/extlib.h | 9 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/extlib.c b/src/extlib.c index e1fdb14..108e3e5 100644 --- a/src/extlib.c +++ b/src/extlib.c @@ -96,3 +96,21 @@ rrmdir (char *pathname) return err; return 0; } + +inline float +min (float v, float min_v) +{ + return (v < min_v) ? min_v : v; +} + +inline float +max (float v, float max_v) +{ + return (v > max_v) ? max_v : v; +} + +inline float +cap (float v, float min_v, float max_v) +{ + return min(max(v, max_v), min_v); +} diff --git a/src/extlib.h b/src/extlib.h index c62c374..c36b919 100644 --- a/src/extlib.h +++ b/src/extlib.h @@ -67,3 +67,12 @@ char *replace_str (char *s, char *old, char *replace); /// Join an array of strings into one string char *join_str (char **s, size_t len, char delim); + +/// Limit a value to a maximum +float max (float v, float max_v); + +/// Limit a value to a minimum +float min (float v, float min_v); + +/// Limit a value between min and max +float cap (float v, float min_v, float max_v); |