I have a complex data processing algorithm implemented using Java 8 and using Double as data type. Given the same input (many hundred thousand database rows) this algorithm outputs different Double values. Sometimes value a is returned, sometimes value b. These two values alternate each execution. The difference between a and b is ~0.0001. I am aware that Double datatype does not grant exact values like Decimal does. I am not sure, however, if it grants repeatable results, assuming exactly same input. I.e. would it be possible that rounding policies are applied in a non-consistent way? My purpose here would be to explain why I get different values with same input.
Other details: I am using Tomcat 8 runtime environment, deployment done on SAP HCP. Datatype at database level is Decimal, we need Double at Java level for historical reasons.
Given the same input, floating point number calculations (on the same platform) will result in the same output.
However, you may get different results if you feed in the input numbers in different orders (even though that would not make a difference mathematically). Maybe that is what is happening here (seeing that you pull the numbers out of a relational database, which has no defined order unless you explicitly sort). Same thing can happen if you have parallel computations using multiple CPU and the data is divided and combined differently each time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With