From nobody Sat Dec 09 18:11:42 2023 X-Original-To: standards@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SnbgM38lCz537Yd for ; Sat, 9 Dec 2023 18:11:43 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SnbgL50Cpz4PfB for ; Sat, 9 Dec 2023 18:11:42 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702145502; a=rsa-sha256; cv=none; b=CieH3I20GG7Owq43Y6ibW4U6hOIrzKB3MApiskAqK2tOzKij/fjM0XL+RS6QVmaruGVj6n t9j/rxoad/x3Q1oinV5JvJ1eZDOuNzGZK5ffhv5+t9lmWFmBgiRK2LdWriXEOFEYd5liS3 jN5FWRCyOBHzoDi/b2Ixby/7nFICldK3wsgNNs/9OoX9pzyUB9Cb6979OPmDaFc20sMf7H J1X4B6pLy3f8u8GS2n3K+/vTnXQ59Ya0DLYv/cPxxtUOQVyi40CxXi0ClD1RyJrkJbVPwZ aJaGBCYbLpp97jO6a2u2ySCqQSplKNBvsNzw3ludmD3lnusin4Anwxo8iI/wbA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702145502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EOQgwoTRWBqMIwcWXdh1/7ryb9X/hNVci6jRf0MZNZo=; b=McCBejXt86R1HC0crc3leBuCrhUxpyDOsEbnuRm+FT1bWPVbGNCZDpfUL2PCG/Bn3sbHNL tvpjqLySPaq04ue3Xpps7ApqeR/kc3S8493VxZDmkwVanFuPP/MDWxo5H9/NhPZagOVG0C FnfqkMtYPd45I2NlKcUEMFBbSzWnOwTxl12FDwhHhbtIce4VCxSzlXtEi2wvmVEQQFUQET SeV+EqSS7yseGq0uO37nvXf72TcYkwQGSo6lHhie9f3F4pZBX8OFtW/TGf1CBfLDZWiGmD YDzAV5C+KkSk0MFiOhqPeZS5BzWd8RCnYpKqaWJc1Bjcr+omHfSEaO5pOL9Lbg== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SnbgL43Rlzbr for ; Sat, 9 Dec 2023 18:11:42 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 3B9IBgLI065334 for ; Sat, 9 Dec 2023 18:11:42 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 3B9IBgPD065333 for standards@FreeBSD.org; Sat, 9 Dec 2023 18:11:42 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: standards@FreeBSD.org Subject: [Bug 275661] /usr/bin/dc hangs with a trivial calculation Date: Sat, 09 Dec 2023 18:11:42 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: standards X-Bugzilla-Version: 13.2-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: dclarke@blastwave.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: standards@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Standards compliance List-Archive: https://lists.freebsd.org/archives/freebsd-standards List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-standards@freebsd.org X-BeenThere: freebsd-standards@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D275661 Bug ID: 275661 Summary: /usr/bin/dc hangs with a trivial calculation Product: Base System Version: 13.2-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Many People Priority: --- Component: standards Assignee: standards@FreeBSD.org Reporter: dclarke@blastwave.org While having a discussion about an article written by Martin Gardner for Scientific American[1] magazine somewhere in the late '70s I was reminded of the old seven digit calculator problem :=20 enter 1.0000001 if you can square that number repeat the square 27 times in total the result should be 674530.470741 or very close A great many calculators of the era could not even get close to the correct result. The Hewlett Packard HP41C and similar were exceptional in that they compute all intermediate results with greater precision than is displayed. To demonstrate the calculation one may use bc : callisto$ uname -a FreeBSD callisto 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64 callisto$ freebsd-version -kru 13.2-RELEASE-p4 13.2-RELEASE-p4 13.2-RELEASE-p5 callisto$ bc scale=3D16 a=3D1.0000001 b=3Da*a b 1.00000020000001 a=3Db*b a 1.0000004000000600 b=3Da*a b 1.0000008000002800 a=3Db*b a 1.0000016000012000 b=3Da*a b 1.0000032000049600 a=3Db*b a 1.0000064000201600 b=3Da*a b 1.0000128000812802 a=3Db*b a 1.0000256003264024 b=3Da*a b 1.0000512013081815 a=3Db*b a 1.0001024052379369 b=3Da*a b 1.0002048209627065 a=3Db*b a 1.0004096838770397 b=3Da*a b 1.0008195355949585 a=3Db*b a 1.0016397428285084 b=3Da*a b 1.0032821744135604 a=3Db*b a 1.0065751214960018 b=3Da*a b 1.0131934752146907 a=3Db*b a 1.0265610182176220 b=3Da*a b 1.0538275241240008 a=3Db*b a 1.1105524506013214 b=3Da*a b 1.2333267455366004 a=3Db*b a 1.5210948612559022 b=3Da*a b 2.3137295769391123 a=3Db*b a 5.3533445552028435 b=3Da*a b 28.6582979267199303 a=3Db*b a 821.2980400566398555 b=3Da*a b 674530.4706008780046192 ^D callisto$=20 That is not a bad result given that we were limited to 16 decimal digits. The same result *should* be from 1.0000001^( 2 ^ 27 ) : callisto$ bc scale=3D16 2^27 134217728 1.0000001^134217728 ^C^C interrupt (type "quit" to exit) 0: (main) ready for more input ^D callisto$=20 Here we see that the old dc "desk calculator" underneath bc has locked up in some strange way. callisto$ which dc /usr/bin/dc callisto$ echo '16k 1.0000001 2 27^ p ^ pq' | dc 134217728 ^C^C 0: (main) ready for more input callisto$=20 Just hangs. Never seems to return and I left it alone for quite some time. Eventually I hit the CTRL+C and you see the message above. This seems like strange behavior. Curious about where this behavior may have come from I went and powered up an old Sun SPARCStation 20. Yes really ... s20$ uname -a=20 SunOS nix 5.8 Generic_117350-62 sun4m sparc SUNW,SPARCstation-20 s20$ echo '16k 1.0000001 2 27^ p ^ pq' | dc 134217728 exp too big empty stack s20$=20 Similar behavior is seen on an old SGI Indigo running IRIX 5.3 as well as on an IBM OS400 machine on powerpc. The calculation can be easily done with logarithms given that the identity ln( a ^ b ) =3D b * ln( a ) :=20 callisto$ bc -l scale=3D16 e( 2^27 * l( 1.0000001 ) ) 674530.4707410543814025 ^D callisto$=20 It would be best if dc would not just hang. Seemingly forever. Dennis Clarke RISC-V/SPARC/PPC/ARM/CISC UNIX and Linux spoken [1] my memory may have failed me but I think it was Martin Gardner --=20 You are receiving this mail because: You are the assignee for the bug.=