I converted a relatively simple algorithm that performs a large number of calculations on double
from C ++ to Java, however, the algorithm works on two platforms, but the same computer produces slightly different results. The algorithm multiplies and sums a lot of paired and ints. I force ints to double the Java algorithm; algorithm C is not applied.
For example, in one pass I get the results:
- (Java) 64684970
- (C ++) 65296408
(Printed to ignore decimal places)
Naturally, there may be a mistake in my algorithm, however, before I start spending time debugging, is it possible that the difference can be explained by floating-point processing in C ++ and Java? If so, can I prove that this is a problem?
An update β a place where types differ from each other β is a multiplication between two ints, which is then added to the current resulting double. By changing the C code, both are currently:
mydouble += (double)int1 * (double)int2
source share