forked from dale48/levawc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
63 lines (53 loc) · 1.17 KB
/
utils.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
63
/*
* _____
* ANSI / ___/
* / /__
* \___/
*
* Filename: utils.c
* Author : Dan Levin
* Date : Fri Mar 22 12:40:45 GMT 2013
* Version : 0.40
* ---
* Description: Miscellanenous utility functions
*
*/
/**
* @file utils.c
**/
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
/* FUNCTION DEFINITIONS */
/* --- Function: int randint(int low, int high) --- */
int randint(int low, int high)
{
return low+rand()%(high-low+1);
}
/* --- Function: int dn_up_lim(int maxval, int minval, int val) --- */
int dn_up_lim(int minval, int maxval, int val)
{
val = val < minval ? minval : val;
val = val > maxval ? maxval : val;
return val;
}
/* --- Function: int dn_lim(int minval, int val) --- */
int dn_lim(int minval, int val)
{
return val < minval ? minval : val;
}
/* --- Function: int up_lim(int maxval, int val) --- */
int up_lim(int maxval, int val)
{
return val > maxval ? maxval : val;
}
/* --- Function: int maxval(int val1, int val2) --- */
int maxval(int val1, int val2)
{
return val1>val2 ? val1 : val2;
}
/* --- Function: int minval(int val1, int val2) --- */
int minval(int val1, int val2)
{
return val1<val2 ? val1 : val2;
}