accuracy of math.pi #16479
-
I have a very simple script which show pi for 15 digits. I wounder about the result: 3.14159274101257. Could anyone pls. help to clarify the different results? import math
d = math.pi
print(f'{d:.15}') Platform: MicroPython v1.24.1 on 2024-11-29; ESP32C3 module with ESP32C3 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Esp32c3 uses single float. So, only 6-7 digits are significant. |
Beta Was this translation helpful? Give feedback.
-
3.14 is accurate enough for the most calculations. |
Beta Was this translation helpful? Give feedback.
-
Thank you @robert-hh for you explanation! @sosi-deadeye: I agree that this might be sufitient for most cases, but I'm running GPS calculations with the Haversine formula on short distance between two GPS points. This requires a more presice calculation. |
Beta Was this translation helpful? Give feedback.
-
Few MicroPython firmwares have FP64 (double precision for floats), like Pyboard : Other solution : |
Beta Was this translation helpful? Give feedback.
Esp32c3 uses single float. So, only 6-7 digits are significant.