I know that similar questions have been asked before, but none of the answers solves my problem.
I have 2 functions:
Java
public static void main(String[] args) {
double h, z, lat0, n0, eSq;
z = 4488055.516;
lat0 = 0.7853981634671384;
n0 = 6388838.290122733;
eSq = 0.0066943799901975545;
h = z / Math.sin(lat0) - n0 * (1 - eSq);
System.out.println(h);
}
C#
public static void Main (string[] args)
{
double h, z, lat0, n0, eSq;
z = 4488055.516;
lat0 = 0.7853981634671384;
n0 = 6388838.290122733;
eSq = 0.0066943799901975545;
h = z / Math.Sin(lat0) - n0 * (1 - eSq);
Console.WriteLine(h);
}
or
4488055,516/sin(0,7853981634671384)-6388838,290122733*(1-0,0066943799901975545)
for SpeedCrunch, Maxima and LibreOffice Calc.
Results are:
Java: 1000.0000555226579 (same with and without strictfp)
C#: 1000,00005552359
SpeedCrunch (15): 1000,000055524055155
SpeedCrunch (50): 1000,00005552405515548724762598846216107366705932894830
LibreOffice Calc: 1000,000055523590000
Maxima: 1000.000055523589
Maxima: 1.00000005552391142b3 (bfloat - fpprec:20)
As you can see, Java and C# are different at the 9th decimal place. Others are not so uniform either. This is tested on the same OS and same CPU. Tests are done also on 32-bit and 64-bit systems.
How to solve this kind of problem? I thought that precision should be equal to 15 decimal places.