Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the Vensim POWER functions as a C macro #286

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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