Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / include / simulink_math_fcn.c @ master

History | View | Annotate | Download (607 Bytes)

1 40ad675e ploc
#include "simulink_math_fcn.h"
2
#include <math.h>
3
4
5 dd29e0c7 Bourbouh
int rem_int (int x, int y) {
6 40ad675e ploc
  return x%y;
7
}
8
9 dd29e0c7 Bourbouh
int mod_int (int x, int y) {
10 40ad675e ploc
  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 dd29e0c7 Bourbouh
double rem_real (double x, double y) {
22 239f4429 Bourbouh
    if (x == 0.0 || y == 0.0){
23
        return 0.0;
24
    }else{
25
        return fmod(x, y);
26
    }
27 40ad675e ploc
}
28
29 dd29e0c7 Bourbouh
double mod_real (double x, double y) {
30 40ad675e ploc
  double tmp = 0.;
31
  if (y == 0.) { return x; };
32 239f4429 Bourbouh
  if (x == 0.) { return 0; };
33 40ad675e ploc
  tmp = fmod(x, y);
34 239f4429 Bourbouh
  if (y*tmp < 0.) {
35 40ad675e ploc
    return tmp+y;
36
  }
37
  else {
38
    return tmp;
39
  }
40
}