uPython calculation (division) accuracy #16189
Replies: 7 comments 2 replies
-
Not 8 bit precision. |
Beta Was this translation helpful? Give feedback.
-
Use a FixPoint library setup for an arbitrary precision. |
Beta Was this translation helpful? Give feedback.
-
Use a board that supports double float with 15 digit precision with MicroPython instead of 7.5. Like PYBD or Teensy 4.x. |
Beta Was this translation helpful? Give feedback.
-
Thank you all for quick response. |
Beta Was this translation helpful? Give feedback.
-
As a small workaround, instead of simple division a/b, I used the operation int(a/b) + fmod(a,b)/b, which improves the result several times in position 10exp-6. |
Beta Was this translation helpful? Give feedback.
-
In case you need a tiny bit of higher precision… ;-) from spfpm import FXfamily, FXnum
fam = FXfamily(1000)
result = FXnum(900000000, fam) / FXnum(640030, fam)
print(result)
1406.18408512100995265846913425933159383153914660250300767151539771573207505898
1610237020139680952455353655297407934003093604987266221895848632095370529506429
3861225255066168773338749746105651297595425214443072980954017780416542974548068
059309719856881708669906098151649141446494695561145571301345249441432 |
Beta Was this translation helpful? Give feedback.
-
I'm really impress about this accuracy: |
Beta Was this translation helpful? Give feedback.
-
I need double precision, and in the meantime it turns out that division in uPython has 8-bit precision(?).
For example, in uPython 9000000000/6400010 = 1406.184082 but the exact value (e.g. from the system calculator) is 1406.184085121. Unfortunately, for programming the Si5351 generator I need the exact value of the fraction from the division, i.e. 0.184085121, which is then multiplied by hudge numbers (hundreds of thousands or millions) and generates unacceptable errors when calculated by uPython. How can I improve the precision of division in uPython or get around this problem?
Beta Was this translation helpful? Give feedback.
All reactions