VirtualPhotonics / VTS

Virtual Tissue Simulator
https://virtualphotonics.org
Other
34 stars 9 forks source link

MC paramsweepdelta errors due to floating point precision #21

Closed hayakawa16 closed 5 years ago

hayakawa16 commented 5 years ago

Using MCCL with paramsweepdelta=mus1,0.01,0.03,0.002 creates a DoubleRange Count value of 10 instead of 11 producing a Delta of 0.00222222...

Expected behavior is a Count value 11 which would produce a Delta of 0.002.

hayakawa16 commented 5 years ago

Here is the original code: sweepRange = new DoubleRange(start, stop, (int)((stop - start) / delta) + 1); For start=0.01, stop=0.03 and delta=0.002, count (last parameter of DoubleRange) was 10. This is because (stop-start)=0.019999999... divided by 0.002 gives 9.99999 plus 1 then (int) is 10.

Proposed new code: sweepRange = new DoubleRange(start, stop, (int)(Math.Round((stop - start) / delta)) + 1); This will produce a count of 11.

hayakawa16 commented 5 years ago

Fix is in Monte Carlo Command Line Application 4.8 Beta