Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <vjjcnl$3tdnk$1@dont-email.me>
Deutsch   English   Français   Italiano  
<vjjcnl$3tdnk$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Martin Ruppert <ruppert@hs-worms.de>
Newsgroups: comp.lang.python
Subject: Division-Bug in decimal and mpmath
Date: Sat, 14 Dec 2024 07:39:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <vjjcnl$3tdnk$1@dont-email.me>
Reply-To: ruppert@hs-worms.de
Injection-Date: Sat, 14 Dec 2024 08:39:35 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1e9732918c36f47788273ed53a25e352";
	logging-data="4110068"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX194S6L8xhsQ7s6uglAfc7GL"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/4.19.0-6-amd64 (x86_64))
Cancel-Lock: sha1:MjkRp6ohI726n5VTfJjcL1Ocz9o=
Bytes: 2425

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.

0.0571428571428571460292086417861615440675190516880580357142857 decimal: 0.4/7
0.0571428571428571460292086417861615440675190516880580357142857 mpmath: 0.4/7
0.0571428571428571428571428571428571428571428571428571428571428 dc: 0.4/7
0.0571428571428571428571428571428571428571428571428571428571429 calc: 0.4/7
0.05714285714285715 builtin: 0.4/7

Both decimal and mpmath give an identical result, which is not a
periodic decimal fraction with at most six digits.

calc and dc provide as well an identical result, which *is* a periodic
decimal fraction with six digits, so I think that's right.

Below ist the python-script, with which the computation was done.

Best regards
Martin Ruppert

#!/usr/bin/env python3
from decimal import Decimal as dec
from mpmath import *
from os import popen
import decimal

z=.4
nen=7

decimal.getcontext().prec=60
print(dec(z)/dec(nen),end=' ');print(f"decimal: {z}/{nen}")

mp.dps=60
a=fdiv(z,nen);print(a,end=' ');print(f"mpmath: {z}/{nen}")

f=popen(f"dc -e'61k{z} {nen}/f'")
for i in f:i=i.rstrip()
f.close()
print(f"0{i}",end=' ');print(f"dc: {z}/{nen}")

f=popen(f"calc 'config(\"display\",61);{z}/{nen}'")
j=0
for i in f:
    if j>0:i=i.rstrip();print(i,end=' ');print(f"calc: {z}/{nen}")
    j+=1
f.close()

print(f"{z/nen}",end=' ');print(f"builtin: {z}/{nen}")

-- 
ruppert@hs-worms.de