c-template
safe_math.h
Go to the documentation of this file.
1 #include <limits.h>
2 #include <stdbool.h>
3 
4 // flag should represent the *_MIN macro for vairous types
5 #define Abs(i, flag) ((i) >= 0 ? (i): ((i) == (flag) ? (flag) : -(i)))
6 
7 
8 int safe_add_int(int x, int y, bool *passed);
9 int safe_sub_int(int x, int y, bool *passed);
10 int safe_div_int(int x, int y, bool *passed);
11 int safe_mod_int(int x, int y, bool *passed);
12 unsigned int safe_sub_uint(unsigned int x, unsigned int y, bool *passed);
13 unsigned int safe_add_uint(unsigned int x, unsigned int y, bool *passed);
14 unsigned int safe_div_uint(unsigned int x, unsigned int y, bool *passed);
15 unsigned int safe_mod_uint(unsigned int x, unsigned int y, bool *passed);
16 unsigned int safe_mul_uint(unsigned int x, unsigned int y, bool *passed);
safe_mod_int
int safe_mod_int(int x, int y, bool *passed)
Definition: safe_math.c:35
safe_mod_uint
unsigned int safe_mod_uint(unsigned int x, unsigned int y, bool *passed)
Definition: safe_math.c:74
safe_add_uint
unsigned int safe_add_uint(unsigned int x, unsigned int y, bool *passed)
Definition: safe_math.c:54
safe_div_int
int safe_div_int(int x, int y, bool *passed)
Definition: safe_math.c:25
safe_mul_uint
unsigned int safe_mul_uint(unsigned int x, unsigned int y, bool *passed)
Definition: safe_math.c:84
safe_div_uint
unsigned int safe_div_uint(unsigned int x, unsigned int y, bool *passed)
Definition: safe_math.c:64
safe_add_int
int safe_add_int(int x, int y, bool *passed)
Definition: safe_math.c:5
safe_sub_int
int safe_sub_int(int x, int y, bool *passed)
Definition: safe_math.c:15
safe_sub_uint
unsigned int safe_sub_uint(unsigned int x, unsigned int y, bool *passed)
Definition: safe_math.c:44