-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_bounds.c
37 lines (36 loc) · 1.02 KB
/
check_bounds.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
/**************************************************************
*
* check_bounds.c
*
* Assignment: arith
* Authors: Adam Weiss and Auriel Wish
* Date: 3/7/2023
*
* Purpose: contain function used in compression and
* decompression that ensures a supplied value
* is within bounds.
*
**************************************************************/
/*
* Name: ensure_in_bounds_decompress
* Purpose: keep given float in desired bounds
* Parameters: given float, minimum and maximum desired float values
* Returns: the bounded float
* Notes: there is an equivalent function in compress.c
*/
float ensure_in_bounds(float val, float min, float max)
{
/*
* if value is below minimum, return minimum, and if value is above
* maximum, return maximum
*/
if (val < min) {
return min;
}
else if (val > max) {
return max;
}
else {
return val;
}
}