ESP-IDF precision of double limited to 7 decimal places?
Posted: Thu Dec 21, 2023 7:20 am
Dear all,
I am working on a project that involves handling latitude and longitude information, and require a precision of at least 8 decimal places.
It seems like doubles are strictly limited to 7 decimal places in ESP-IDF? Is there anyway to bypass this?
In the following code,
1: we take in a latitude value in string format (p) that has been multiplied by 100 (this is the format passed on via UART from the gps module)
->eg: 2219.00753
2: we convert this from a list of characters (string) to double using atof(2219.00753)
->this is converted correctly and there is no loss of precison (output: 2219.00753)
3: I have to move the decimal places 2 spaces forwards (as latitude should be a value from -90 to +90, not -9000 to +9000)
-> expected output: 22.1900753, actual output: 22.190075
I have made sure to log to the terminal using %lf (ie. double) and that all the variables involved here (temp_lat) is defined as double. Is this a limitation of ESP-IDF and if so, is there anyway to override it? I must have at least 7d.p. to have the required resolution of around 1cm.
Many thanks for your help.
-Clement
I am working on a project that involves handling latitude and longitude information, and require a precision of at least 8 decimal places.
It seems like doubles are strictly limited to 7 decimal places in ESP-IDF? Is there anyway to bypass this?
In the following code,
1: we take in a latitude value in string format (p) that has been multiplied by 100 (this is the format passed on via UART from the gps module)
->eg: 2219.00753
2: we convert this from a list of characters (string) to double using atof(2219.00753)
->this is converted correctly and there is no loss of precison (output: 2219.00753)
3: I have to move the decimal places 2 spaces forwards (as latitude should be a value from -90 to +90, not -9000 to +9000)
-> expected output: 22.1900753, actual output: 22.190075
I have made sure to log to the terminal using %lf (ie. double) and that all the variables involved here (temp_lat) is defined as double. Is this a limitation of ESP-IDF and if so, is there anyway to override it? I must have at least 7d.p. to have the required resolution of around 1cm.
Code: Select all
temp_lat=atof(p)/100;
ESP_LOGI("gps decode v2", "what is p for lat %s, what is atof(p) %lf, atof(p)/100 %10lf, templat %lf",p,atof(p),atof(p)/100,temp_lat);
-Clement