Skip to content

Commit

Permalink
Implemented built-in functions div, mod and rem. rem might not be cor…
Browse files Browse the repository at this point in the history
…rect yet

though.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4763 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jan 11, 2010
1 parent 854515c commit eb715d7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions c_runtime/modelica.h
Expand Up @@ -91,8 +91,19 @@ typedef modelica_real max_rettype;
typedef modelica_real min_rettype;
typedef modelica_real arctan_rettype;
typedef modelica_real atan2_rettype;
typedef modelica_real div_rettype;
typedef modelica_real mod_rettype;
typedef modelica_real rem_rettype;
#define arctan atan

/* div is already defined in stdlib, so it's redefined here to modelica_div so
* that it can be implemented without changing the name. Hopefully no one uses
* the stdlib div and includes this header... */
#define div modelica_div

/* fmod in math.h does not work in the same way as mod defined by modelica, so
* we need to define our own mod. */
#define mod modelica_mod

/* Special Modelica builtin functions*/
typedef modelica_real pre_rettype;
Expand Down
14 changes: 14 additions & 0 deletions c_runtime/utility.c
Expand Up @@ -48,4 +48,18 @@ int in_range_real(modelica_real i,
return 0;
}

modelica_real modelica_div(modelica_real x, modelica_real y)
{
return (modelica_real)((modelica_integer)(x/y));
}

modelica_real modelica_mod(modelica_real x, modelica_real y)
{
return (x - floor(x/y) * y);
}

modelica_real rem(modelica_real x, modelica_real y)
{
return fmod(x, y);
}

4 changes: 4 additions & 0 deletions c_runtime/utility.h
Expand Up @@ -42,4 +42,8 @@ int in_range_real(modelica_real i,
modelica_real start,
modelica_real stop);

modelica_real modelica_div(modelica_real x, modelica_real y);
modelica_real modelica_mod(modelica_real x, modelica_real y);
modelica_real rem(modelica_real x, modelica_real y);

#endif

0 comments on commit eb715d7

Please sign in to comment.