dimanche 17 juillet 2022

Calculation of large numbers C++11

I'm trying to find the point where 2 lines intersect. I am using this example on geeks for geeks.

This works well for small numbers. I am using "accurate" latitude and longitude points which are scaled by 10000000. So a latitude of 40.4381311 would be 404381311 in my program. I can't use double as I will lose accuracy and the whole point of getting the points scaled like this is for accuracy.

So in the geeks for geeks example I changed everywhere they use double to use int64_t. But unfortunately this is still not enough.

By the time you get to:

double determinant = a1*b2 - a2*b1;

or:

double x = (b2*c1 - b1*c2)/determinant;
double y = (a1*c2 - a2*c1)/determinant;

The number will be too big for int64_t. What is my best way around this issue while still keeping accuracy.

I am writing this code for an ESP32 and it doesn't seem to have __int128/__int128_t.

Thanks!

Aucun commentaire:

Enregistrer un commentaire