## variable set as int gets reset to real

 Project: Simile Version: 6.3 Component: Code Category: bug report Priority: normal Assigned: robertm Status: active
Description

I have defined a variable as being a variable parameter with a range of 0 to 10 and having units of int. If I set the initial value (in the box below) to 0, when I save the equation and go back in, I see that the units have been changed to real. If I keep everything the same, but set the initial value to 1, the units stay as int. What gives? (using 6.4 on a Mac)

### #1

 Assigned to: Anonymous » robertm

This is the result of several intentional features of Simile's equation language coming together in a way that is not at all intentional.

Normally, if you write an equation with a result whose units would normally be integer, the result is assigned the type integer, as this gives the most efficient computation.

However, there is no guarantee that the modeller actually intended the result to be an integer, and they might later edit the equation to something that produces a real result (or the type of an input parameter might change, with that effect).

Changing an equation so its units no longer match the given units of the result would normally produce an error, but in this case (integer becomes real) the change is quietly accepted since the modeller may not have meant integer in the first place.

So why is a value of 0 causing the type to become real?

Now, if strict unit checking is turned on in Simile, it tries to generate physical units for the result of each equation based on those of the inputs. In this case if you have a value with physical units you cannot add it to or compare it with a numerical value without units -- the numerical value is taken to represent a physical constant and Simile insists that it is given the appropriate units, to catch cases where a number might actually represent e.g., pounds where kilos were intended. If the values have the same dimensions but different units, a conversion will be automatically applied.

This causes problems with conditions comparing or selecting between a value and zero, although it makes no sense to insist that zero has the appropriate units because conversion would not change it. So you can write something like 'if time()<50*"day" then 3.2*"kg" else 0'. For this to work OK, 0 has to have a special status that allows it to combine with any physical dimensions -- and this also causes it to be treated as a real in other equations, including default values for variable parameters.

Obviously this is unexpected, so what's the answer?

• Only give 0 special units if strict unit checking is enabled?
• Give 0.0 special units, but always treat 0 as a dimensionless integer?

Opinions would be welcome. In the mean time, if you want to put a zero in an equation that will be treated as an integer, write (1-1).