mariamkiran / cloudsim

Automatically exported from code.google.com/p/cloudsim
0 stars 0 forks source link

precision of floating point arithmetic #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run CloudSim with some Cloudlets
2. Watch the results of isFinished() for a Cloudlet

What is the expected output? What do you see instead?
 Cloudlet should be finished 

What version of the product are you using? On what operating system?
 Win 7 64bit -> Cloudsim 3.0

Please provide any additional information below.
 In updateVmProcessing() of every scheduler a subtraction of doubles is used to calculate the timespan:
 double timeSpam = currentTime - getPreviousTime();
 in my example this gives => 39.9999999999 = 80.1 - 40.1
 which isn't correct and should be 40.

To control the precision of floating point arithmetic, you should use 
java.math.BigDecimal. See 
http://stackoverflow.com/questions/179427/how-to-resolve-a-java-rounding-double-
issue for the complete solution.

Original issue reported on code.google.com by edcon...@intec.ugent.be on 3 Oct 2012 at 8:41

GoogleCodeExporter commented 8 years ago
This is not an issue of CloudSim, but an issue of floating pointing operations 
in general (in any language). Changing everything to big decimal would "solve" 
the issue. But this can be handled by users if they they require.

Original comment by rodrigo.calheiros on 9 Oct 2012 at 11:13