@sdeverywhere/cli 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/cli",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "Contains the `sde` command line interface for the SDEverywhere tool suite.",
5
5
  "type": "module",
6
6
  "files": [
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@sdeverywhere/build": "^0.2.0",
15
- "@sdeverywhere/compile": "^0.7.1",
15
+ "@sdeverywhere/compile": "^0.7.2",
16
16
  "bufx": "^1.0.5",
17
17
  "byline": "^5.0.0",
18
18
  "ramda": "^0.27.0",
package/src/c/vensim.c CHANGED
@@ -434,11 +434,19 @@ FixedDelay* __new_fixed_delay(FixedDelay* fixed_delay, double delay_time, double
434
434
  // The delay time is quantized to an integral number of time steps.
435
435
  // The FixedDelay should be constructed at init time to latch the delay time and initial value.
436
436
  // Allocate memory on the first call only. Pass the same pointer back in on subsequent runs.
437
+ size_t n = (size_t)ceil(delay_time / _time_step);
438
+ size_t bufsize = n * sizeof(double);
437
439
  if (fixed_delay == NULL) {
440
+ // Create the FixedDelay object and allocate its data buffer.
438
441
  fixed_delay = malloc(sizeof(FixedDelay));
439
- fixed_delay->n = (size_t)ceil(delay_time / _time_step);
440
- fixed_delay->data = malloc(sizeof(double) * fixed_delay->n);
442
+ fixed_delay->data = malloc(bufsize);
443
+ } else if (fixed_delay->n != n) {
444
+ // The delay time has changed since a previous run. Reallocate the data buffer.
445
+ free(fixed_delay->data);
446
+ fixed_delay->data = malloc(bufsize);
441
447
  }
448
+ // Reset state at the start of each run.
449
+ fixed_delay->n = n;
442
450
  fixed_delay->data_index = 0;
443
451
  fixed_delay->initial_value = initial_value;
444
452
  return fixed_delay;
package/src/c/vensim.h CHANGED
@@ -26,6 +26,7 @@ extern "C" {
26
26
  #define _MAX(a, b) fmax(a, b)
27
27
  #define _MIN(a, b) fmin(a, b)
28
28
  #define _MODULO(a, b) fmod(a, b)
29
+ #define _POWER(a, b) pow(a, b)
29
30
  #define _QUANTUM(a, b) ((b) <= 0 ? (a) : (b) * trunc((a) / (b)))
30
31
  #define _SAMPLE_IF_TRUE(current, condition, input) (bool_cond(condition) ? (input) : (current))
31
32
  #define _SIN(x) sin(x)