Float/Double
Posted: Wed Oct 05, 2022 7:27 pm
Here is a short dummy program:
a=1234.123456789
b=1234.123459876
c=b-a
print('a,b,c=',a,b,c)
print('a={:.9f}'.format(a))
print('b={:.9f}'.format(b))
print('c={:.9f}'.format(c))
Normal python gives the following output:
a,b,c= 1234.123456789 1234.123459876 3.0869998681737343e-06
a=1234.123456789
b=1234.123459876
c=0.000003087
while micropython on my esp32 gives:
a,b,c= 1234.123 1234.123 0.0
a=1234.123468399
b=1234.123468399
c=0.000000000
This is too bad!!!!!
Is there a way to do better in micropython? Double precision? How?
I tried to install the FixedPoint module but I only got error messages!? Is there a different solution?
Poul Riis
Denmark
a=1234.123456789
b=1234.123459876
c=b-a
print('a,b,c=',a,b,c)
print('a={:.9f}'.format(a))
print('b={:.9f}'.format(b))
print('c={:.9f}'.format(c))
Normal python gives the following output:
a,b,c= 1234.123456789 1234.123459876 3.0869998681737343e-06
a=1234.123456789
b=1234.123459876
c=0.000003087
while micropython on my esp32 gives:
a,b,c= 1234.123 1234.123 0.0
a=1234.123468399
b=1234.123468399
c=0.000000000
This is too bad!!!!!
Is there a way to do better in micropython? Double precision? How?
I tried to install the FixedPoint module but I only got error messages!? Is there a different solution?
Poul Riis
Denmark