Hi all.
I have come across an interesting phenomenon.
I had a function in a model, which summed up values in a table and alerted me if the sum differed from 1.
When I filled in 20 rows of 0.05, I got an alert.
(The same is true for 10 rows of 0.1, but not two rows of 0.5 or 4 rows of 0.25)
I couldn't understand why this happened, so I did a test.
double value = 0; for(int x=1;x<=20;x++) { value+=0.05; } return value; /*Returns 1*/
This returns 1 as expected, but if I try to compare the result to 1, it returns a false/0 as seen below.
double value = 0; for(int x=1;x<=20;x++) { value+=0.05; } return value==1; /*Returns 0*/
Finally, I tried adding 0.05 together 20 times without the for loop, and FlexSim still returns a 0.
double value = 0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05+0.05; return value==1; /*returns 0, although the value is 1*/ double value = 0.5+0.5; return value==1; /*Returns 1*/
Have I had way too much coffee today, or is something here not working as intended? :-)
Can anyone else recreate this issue? (I got the same results on two different machines - I also tried in the 2018 beta and FlexSim HC 5.1 with the same result)
Best regards
Christian