lustrec / include / simulink_math_fcn.c @ master
History  View  Annotate  Download (607 Bytes)
1 
#include "simulink_math_fcn.h" 

2 
#include <math.h> 
3  
4  
5 
int rem_int (int x, int y) { 
6 
return x%y;

7 
} 
8  
9 
int mod_int (int x, int y) { 
10 
int tmp;

11 
if (y == 0) { return x; }; 
12 
tmp = x%y; 
13 
if (y < 0 && tmp > 0) { 
14 
return tmp+y;

15 
} 
16 
else {

17 
return tmp;

18 
} 
19 
} 
20  
21 
double rem_real (double x, double y) { 
22 
if (x == 0.0  y == 0.0){ 
23 
return 0.0; 
24 
}else{

25 
return fmod(x, y);

26 
} 
27 
} 
28  
29 
double mod_real (double x, double y) { 
30 
double tmp = 0.; 
31 
if (y == 0.) { return x; }; 
32 
if (x == 0.) { return 0; }; 
33 
tmp = fmod(x, y); 
34 
if (y*tmp < 0.) { 
35 
return tmp+y;

36 
} 
37 
else {

38 
return tmp;

39 
} 
40 
} 