Martin Ruppert wrote:...
Hi,
the division 0.4/7 provides a wrong result. It should give a periodic decimal fraction with at most six digits, but it doesn't.
Below is the comparison of the result of decimal, mpmath, dc and calc.
I looks like you might be running into limitations in floating-point
numbers. At least with decimal, calculating 4/70 instead of 0.4/7
appears to give the correct result. As does:
```
from decimal import Decimal as dec
z2 = dec(4) / dec(10)
print(z2 / dec(nen))
```
You can also pass a string, and `dec("0.4")/dec(10)` gives the correct
result as well.
mpf('0.0571428571428571428571428571428571428571428571428571428571428549')from mpmath import mp
mp.dps = 60
mp.mpf('0.4') / 7
2/35from sympy import Rational
a = Rational('0.4') / 7
a
0.0571428571428571428571428571428571428571428571428571428571429a.evalf(60)
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,073 |
Nodes: | 10 (0 / 10) |
Uptime: | 210:28:46 |
Calls: | 13,782 |
Calls today: | 1 |
Files: | 186,987 |
D/L today: |
4,315 files (1,168M bytes) |
Messages: | 2,434,517 |