Project

General

Profile

Revision 0bca9d53 include/simulink_math_fcn.c

View differences:

include/simulink_math_fcn.c
1 1
#include "simulink_math_fcn.h"
2 2
#include <math.h>
3 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 4

  
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) {
5
int rem_int (int x, int y) {
74 6
  return x%y;
75 7
}
76 8

  
77
int mod_scalar_real_int_int_int (int x, int y) {
9
int mod_int (int x, int y) {
78 10
  int tmp;
79 11
  if (y == 0) { return x; };
80 12
  tmp = x%y;
......
86 18
  }
87 19
}
88 20

  
89
double rem_scalar_real_double_double_double (double x, double y) {
21
double rem_real (double x, double y) {
90 22
  return fmod(x, y);
91 23
}
92 24

  
93
double mod_scalar_real_double_double_double (double x, double y) {
25
double mod_real (double x, double y) {
94 26
  double tmp = 0.;
95 27
  if (y == 0.) { return x; };
96 28
  tmp = fmod(x, y);
......
101 33
    return tmp;
102 34
  }
103 35
}
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; */

Also available in: Unified diff