I am porting program from C# to java. I’ve faced a fact that
Java
Math.pow(0.392156862745098,1./3.) = 0.7319587495200227
C#
Math.Pow( 0.392156862745098, 1.0 / 3.0) =0.73195874952002271
this last digit leads to sufficient differences in further calculations. Is there any way to emulate c#’s pow?
Thanx
Just to confirm what Chris Shain wrote, I get the same binary values:
Output of both: 4604768117848454313
In other words, the double values are exactly the same bit pattern, and any differences you’re seeing (assuming you’d get the same results) are due to formatting rather than a difference in value. By the way, the exact value of that double is
Now it’s worth noting that distinctly weird things can happen in floating point arithmetic, particularly when optimizations allow 80-bit arithmetic in some situations but not others, etc.
As Henk says, if a difference in the last bit or two causes you problems, then your design is broken.