From 8fc1ee8e587c4224862f0dec0772627dc6f6acfa Mon Sep 17 00:00:00 2001 From: Todd Fincannon <66087780+ToddFincannonEI@users.noreply.github.com> Date: Thu, 8 Dec 2022 13:09:06 -0800 Subject: [PATCH] feat: add the Vensim POWER functions as a C macro (#286) Fixes #283 --- models/power/power.dat | 20 ++++++++++++++++++++ models/power/power.mdl | 10 ++++++++++ packages/cli/src/c/vensim.h | 1 + 3 files changed, 31 insertions(+) create mode 100644 models/power/power.dat create mode 100644 models/power/power.mdl diff --git a/models/power/power.dat b/models/power/power.dat new file mode 100644 index 00000000..0ac76f23 --- /dev/null +++ b/models/power/power.dat @@ -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 diff --git a/models/power/power.mdl b/models/power/power.mdl new file mode 100644 index 00000000..bbabae27 --- /dev/null +++ b/models/power/power.mdl @@ -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 ~~| diff --git a/packages/cli/src/c/vensim.h b/packages/cli/src/c/vensim.h index b5fb37b4..ca38e743 100644 --- a/packages/cli/src/c/vensim.h +++ b/packages/cli/src/c/vensim.h @@ -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)