Project

General

Profile

Download (3.67 KB) Statistics
| Branch: | Tag: | Revision:
1
#include "simulink_math_fcn.h"
2
#include <math.h>
3

    
4
/* function exp_scalar_real (x: real) returns (y: real) prototype C lib m; */
5
double exp_scalar_real (double x) {
6
  return exp(x);
7
}
8

    
9

    
10
/* function log_scalar_real (x: real) returns (y: real) prototype C lib m; */
11
double log_scalar_real (double x) {
12
  return log(x);
13
}
14
/* function _10u_scalar_real (x: real) returns (y: real) prototype C lib m; */
15
double _10u_scalar_real (double x) {
16
  return pow(10.,x);
17
}
18

    
19
/* function log10_scalar_real (x: real) returns (y: real) prototype C lib m; */
20
double log10_scalar_real (double x) {
21
  return log10(x);
22
}
23

    
24
/* function magnitude_2_scalar_real (x: real) returns (y: real) prototype C lib m; */
25
double magnitude_2_scalar_real (double x) {
26
  return pow(fabs(x), 2.);
27
}
28

    
29
/* function square_scalar_real (x: real) returns (y: real) prototype C lib m; */
30
double square_scalar_real (double x) {
31
  return pow(x, 2.);
32
}
33

    
34
/* function pow_scalar_real (x,y: real) returns (z: real) prototype C lib m; */
35
double pow_scalar_real (double x, double y) {
36
  return pow(x, y);
37
}
38

    
39
/* function conj_scalar_real (x: real) returns (y: real) prototype C lib m; */
40
double conj_scalar_real (double x) {
41
  return x; // identity for real
42
}
43

    
44
/* function reciprocal_scalar_real (x: real) returns (y: real) prototype C lib m; */
45
double reciprocal_scalar_real (double x) {
46
  return 1./x; 
47
}
48

    
49
/* function hypot_scalar_real (x,y: real) returns (z: real) prototype C lib m; */
50
double hypot_scalar_real (double x, double y) {
51
  return sqrt(x*x + y*y); 
52
}
53

    
54

    
55

    
56
/*
57
  mod function produces a result that is either zero or has the same sign as the divisor.
58
  rem function produces a result that is either zero or has the same sign as the dividend.
59
  mod(a,0) returns a
60
  rem(a,0) returns NaN.
61

    
62
function rem_scalar_real_int_int_int (x,y: int) returns (z: int) prototype C lib m;
63
function rem_scalar_real_double_double_double (x,y: double) returns (z: double) prototype C lib m;
64
function rem_scalar_real_double_int_double (x: double; y: int) returns (z: double) prototype C lib m;
65
function rem_scalar_real_int_double_double (x: int; y: double) returns (z: double) prototype C lib m;
66

    
67
function mod_scalar_real_int_int_int (x,y: int) returns (z: int) prototype C lib m;
68
function mod_scalar_real_double_double_double (x,y: double) returns (z: double) prototype C lib m;
69
function mod_scalar_real_double_int_double (x: double; y: int) returns (z: double) prototype C lib m;
70
function mod_scalar_real_int_double_double (x: int; y: double) returns (z: double) prototype C lib m;
71
*/
72

    
73
int rem_scalar_real_int_int_int (int x, int y) {
74
  return x%y;
75
}
76

    
77
int mod_scalar_real_int_int_int (int x, int y) {
78
  int tmp;
79
  if (y == 0) { return x; };
80
  tmp = x%y;
81
  if (y < 0 && tmp > 0) {
82
    return tmp+y;
83
  }
84
  else {
85
    return tmp;
86
  }
87
}
88

    
89
double rem_scalar_real_double_double_double (double x, double y) {
90
  return fmod(x, y);
91
}
92

    
93
double mod_scalar_real_double_double_double (double x, double y) {
94
  double tmp = 0.;
95
  if (y == 0.) { return x; };
96
  tmp = fmod(x, y);
97
  if (y < 0. && tmp > 0.) {
98
    return tmp+y;
99
  }
100
  else {
101
    return tmp;
102
  }
103
}
104

    
105
double rem_scalar_real_double_int_double (double x, int y) {
106
  return rem_scalar_real_double_double_double (x, (double)y);
107
}
108

    
109
double rem_scalar_real_int_double_double (int x, double y) {
110
  return rem_scalar_real_double_double_double ((double)x, y);
111
}
112

    
113

    
114
double mod_scalar_real_double_int_double (double x, int y) {
115
  return (mod_scalar_real_double_double_double (x, (double)y));
116
}
117

    
118
double mod_scalar_real_int_double_double (int x, double y) {
119
  return (mod_scalar_real_double_double_double ((double)x, y));
120
}
121

    
122
/* function transpose_scalar_real (x: real) returns (y: real) prototype C lib m; */
123

    
124
/* function hermitian_scalar_real (x: real) returns (y: real) prototype C lib m; */
(15-15/16)