I have a function that converts two points of latitude and longitude into distance traveled but, in a certain part of the code, the value is rounded.
Code (function) below:
line1: float CalculaDistancia()
line2: {
line3: float Radius = 6378.137;
line4: float Pi = 3.1415926535897932384626433832795;
line5: float Distancia;
line6: float deg2radMultiplier = (Pi / 180);
line7:
line8: float auxiliar1;
line9: float auxiliar2;
line10: float auxiliar3;
line11: float auxiliar4;
line12:
line13: float LatInicial = (-22.905261 * deg2radMultiplier);
line14: float LonInicial = (-47.102654 * deg2radMultiplier);
line15: float LatFinal = (-22.905969 * deg2radMultiplier);
line16: float LonFinal = (-47.102664 * deg2radMultiplier);
line17:
line18: float LonDelta = LonFinal - LonInicial;
line19:
line20: auxiliar1 = sin(LatInicial) * sin(LatFinal);
line21: auxiliar2 = cos(LatInicial) * cos(LatFinal) * cos(LonDelta);
line22: auxiliar3 = (auxiliar1 + auxiliar2);
line23: auxiliar4 = acos(auxiliar3);
line24:
line25: Distancia = auxiliar4 * Radius;
line26: Distancia = Distancia * 1000;
line27:
line28: return Distancia;
line29: }
The value auxiliar1 is = 0.15148772239685058593750000000000 in the line 20,
The value auxiliar2 is = 0.84851226806640625000000000000000 in the line 21,
In the line 22, the value auxiliar3 should be = 0,999999990463256000000000 but is rounded to 1 and is a problem for my application.
How can I solved this problem? the variable auxiliar3 can not be rounded.
Thank you!!!