Skip to content

various macros and functions for validating and guarding signals in c (Bounds, Clamps, etc...)

License

Notifications You must be signed in to change notification settings

mofosyne/bound_and_clamp.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bound_and_clamp.c

CI/CD Status Badge

various macros and functions for validating and guarding signals in c (Bounds, Clamps, etc...)

install

$ clib install mofosyne/bound_and_clamp.c

usage

bound.h

  • is_above_bound(value, max)
  • is_below_bound(value, min)
  • is_within_bound(value, min, max)
  • is_out_of_bound(value, min, max)

clamp.h

  • clamp_upper(value, max)
  • clamp_lower(value, min)
  • clamp_range(value, min, max)

Expected Test Output

This is useful to get a sense of how this will work.

So Given:

  • min = -2
  • max = 2

Clamped Value Macros Outputs

i clamp_upper clamp_lower clamp_range
-5 -5 -2 -2
-4 -4 -2 -2
-3 -3 -2 -2
-2 -2 -2 -2
-1 -1 -1 -1
0 0 0 0
1 1 1 1
2 2 2 2
3 2 3 2
4 2 4 2
5 2 5 2

Bounded Value Macros Outputs

i is_below_bound is_above_bound is_within_bound is_out_of_bound
-5 true false false true
-4 true false false true
-3 true false false true
-2 false false true false
-1 false false true false
0 false false true false
1 false false true false
2 false false true false
3 false true false true
4 false true false true
5 false true false true

license

GNUv3

About

various macros and functions for validating and guarding signals in c (Bounds, Clamps, etc...)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published