Skip to content

Commit

Permalink
feat: add the Vensim POWER functions as a C macro (#286)
Browse files Browse the repository at this point in the history
Fixes #283
  • Loading branch information
ToddFincannonEI authored Dec 8, 2022
1 parent 5e2f60c commit 8fc1ee8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions models/power/power.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
a
0 4
1 4
b
0 1.41421
1 1.41421
base
0 2
c
0 2.82843
1 2.82843
FINAL TIME
0 1
INITIAL TIME
0 0
SAVEPER
0 1
1 1
TIME STEP
0 1
10 changes: 10 additions & 0 deletions models/power/power.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{UTF-8}
base = 2 ~~|
a = POWER(base, 2) ~~|
b = POWER(base, 0.5) ~~|
c = POWER(base, 1.5) ~~|

INITIAL TIME = 0 ~~|
FINAL TIME = 1 ~~|
TIME STEP = 1 ~~|
SAVEPER = TIME STEP ~~|
1 change: 1 addition & 0 deletions packages/cli/src/c/vensim.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {
#define _MAX(a, b) fmax(a, b)
#define _MIN(a, b) fmin(a, b)
#define _MODULO(a, b) fmod(a, b)
#define _POWER(a, b) pow(a, b)
#define _QUANTUM(a, b) ((b) <= 0 ? (a) : (b) * trunc((a) / (b)))
#define _SAMPLE_IF_TRUE(current, condition, input) (bool_cond(condition) ? (input) : (current))
#define _SIN(x) sin(x)
Expand Down

0 comments on commit 8fc1ee8

Please sign in to comment.