One of the compiler issues that is affecting the model in discussion #557 is shown in the following simplified example taken from a construct in that model (from the equation Priorities[xjt,xlt]):
xlt: (xlt1-xlt5) -> Edu ~~|
xjt: (xjt1-xjt5) -> Edu ~~|
Priority Test 1[xjt,xlt] = IF THEN ELSE(xjt-xlt = -1, 1, 0) ~~|
Priority Test 2[xjt,xlt] = xjt-xlt ~~|
These will produce incorrect values for cases like [xjt1,xlt2]:
- Expected (what Vensim produces): -1
- Actual (what SDE produces): 4294967295
The reason it fails is because the C code generator represents loop index variables using the unsigned size_t type, so doing math with these types will not produce a negative value (thus the large positive representation of -1). We should cast to double when generating code involving loop index variables in expression position.
This only affects C code generation, since for JS code generation the numbers are all signed types.
One of the compiler issues that is affecting the model in discussion #557 is shown in the following simplified example taken from a construct in that model (from the equation
Priorities[xjt,xlt]):These will produce incorrect values for cases like
[xjt1,xlt2]:The reason it fails is because the C code generator represents loop index variables using the unsigned
size_ttype, so doing math with these types will not produce a negative value (thus the large positive representation of -1). We should cast todoublewhen generating code involving loop index variables in expression position.This only affects C code generation, since for JS code generation the numbers are all signed types.