From unknown Mon Jun 16 23:51:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#42012: Reference Manual and Docstring on number->string Resent-From: Sebastian Miele Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 22 Jun 2020 22:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 42012 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 42012@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Reply-To: sebastian.miele@gmail.com Received: via spool by submit@debbugs.gnu.org id=B.159286629219085 (code B ref -1); Mon, 22 Jun 2020 22:52:01 +0000 Received: (at submit) by debbugs.gnu.org; 22 Jun 2020 22:51:32 +0000 Received: from localhost ([127.0.0.1]:34863 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnVHo-0004xl-Nh for submit@debbugs.gnu.org; Mon, 22 Jun 2020 18:51:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:60858) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnVHk-0004xa-Lg for submit@debbugs.gnu.org; Mon, 22 Jun 2020 18:51:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnVHk-0002MU-Cp for bug-guile@gnu.org; Mon, 22 Jun 2020 18:51:28 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:38877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnVHi-0003GT-UC for bug-guile@gnu.org; Mon, 22 Jun 2020 18:51:28 -0400 Received: by mail-wr1-x42d.google.com with SMTP id z13so6713327wrw.5 for ; Mon, 22 Jun 2020 15:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:reply-to:message-id:date:mime-version; bh=z7So6MxrgX0mqZUhH7C//a2RZg/CacH7bhuXcLPXeJs=; b=iK3UJoaDSY4N3CROaugSk4ZAC6szI+rfamrkIvm11ZbV721dxvKcwStg/rvKcHsYN2 KABZLntd1zJFxbHpyqBpHomdBEnZ19jYnsvS/rNbzHg153IoP72QHENGuxAELdNNnXFE n3Zm/G53U3bLF7aksRtSRvp+Uid6YuVLdfZd3jjp3TqwoGM+AJsLrmWUlRsvLa9EMnCQ 0J5f3m1NhfsGNTB/s2T5A2iaUebx8ghm8omVyR6Zv5BLQMYfEpJmG3T+3UKEJMi7Jf2m k+tDxq+HdyOZomc/PMVY8ue4N9VaLS4M/YTWFpsX0u6vT2c2MZyl9D6EfgCYxA/VnukZ 6K4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:reply-to:message-id :date:mime-version; bh=z7So6MxrgX0mqZUhH7C//a2RZg/CacH7bhuXcLPXeJs=; b=Bcw7iQ9O0J2EDLdHdU+77PI8/juXoMS2Ivx9DCnHS4XbeiCVgPwgFccyHKj6Ks2St5 UKdSdG2UoJ7vxcbRKp4PPM/7n91q+PNVTOdt9qRnu5KzFHo5UKYddUimeLF8nl2uve5O pW8Mn0kax0v1R3IxYzsz7tv4gZwnoEMMsLonOCKgNajPGhRbbTvbEYCxGFv+3krIhBpe UxEPL2Gj1Bhns9BQJstZQBEE48omrcp86zEAL2xaeBsQ61yYqHroUOQ5OS7ZpLT2X8SD fIUtZ7XI0sZPPUmDShyYxjNxR38wPi1oe3UiOCM30j9tLNAp73dpWJ29Hido42tVox/u jcCg== X-Gm-Message-State: AOAM531TR5YpdMntzmT+AMoWdHvWtxhC7PcgAx4f0P7036g4KyzbLm2Q zeCIAXl+rWhkU7YSlkTtpVaPlj4M X-Google-Smtp-Source: ABdhPJzRln9qq1vRfwsHkb55dgx9Iel+CZpaQLcS/gnkVkOosEM7Hh1Lugfc2U3dzlW3bV/kINllEQ== X-Received: by 2002:adf:f18c:: with SMTP id h12mr20680585wro.375.1592866285221; Mon, 22 Jun 2020 15:51:25 -0700 (PDT) Received: from huette ([2a02:908:175c:4260:33a6:b2b0:4ad5:928d]) by smtp.gmail.com with ESMTPSA id h18sm19690005wru.7.2020.06.22.15.51.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 15:51:24 -0700 (PDT) User-agent: mu4e 1.4.10; emacs 26.3 From: Sebastian Miele Message-ID: <871rm6lno4.fsf@gmail.com> Date: Tue, 23 Jun 2020 00:51:23 +0200 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=sebastian.miele@gmail.com; helo=mail-wr1-x42d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: 0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Guile 3.0.3. The reference manual and the docstring of number->string say: "If N is inexact, a radix of 10 will be used." But that is not what happens, e.g., (let ((x 4.0)) (and (inexact? x) (number->string x 3))) evaluates to "11.0" instead of #f or "4.0". Probably "if RADIX is not supplied, a radix of 10 will be used" is meant. From unknown Mon Jun 16 23:51:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#42012: Reference Manual and Docstring on number->string Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 23 Jun 2020 08:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42012 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 42012@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15929012679133 (code B ref -1); Tue, 23 Jun 2020 08:35:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Jun 2020 08:34:27 +0000 Received: from localhost ([127.0.0.1]:35401 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jneNu-0002NE-Nl for submit@debbugs.gnu.org; Tue, 23 Jun 2020 04:34:26 -0400 Received: from lists.gnu.org ([209.51.188.17]:37802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jneNs-0002N6-40 for submit@debbugs.gnu.org; Tue, 23 Jun 2020 04:34:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jneNr-0006U9-8j for bug-guile@gnu.org; Tue, 23 Jun 2020 04:34:23 -0400 Received: from mail.tuxteam.de ([5.199.139.25]:52453) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1jneNo-0007Eq-Pc for bug-guile@gnu.org; Tue, 23 Jun 2020 04:34:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:Date; bh=y2hhL0pMwFgintlQrev+Fg9YFREc/BAWGoAIfrgprvM=; b=PzPa6dNSKGK67j6h3fzE42/QdR3+cUKl/iEPgZUF1SRkdkgEmJYsRdDqw9+GZ/Nxk27i+UJ1ck40l08CDVYoUHBBR4w4bnnIOKmKMVJo5JOKLZw3SpCooXJ61qNV3Safl6gN+y49crj1WuZvXymM97YTx7eucBR3uWheFOG+FXDomqQhoQMqcBBNufljiI9pBWihjpXps3hQdQT3qtQQVJg3Hwj86+EE7riTVgzqGjNIADvJDDI6hpjMmfJ2UK1BXou/E+c/m3PGEWyuMxP1MzCL27ifwrQA4HcsgSwGQUHY1p6m2W6/fj5wz/zEn5QBB35v90jQzt6y/oG7k8rFDQ==; Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1jneNg-0001Af-4e for bug-guile@gnu.org; Tue, 23 Jun 2020 10:34:12 +0200 Date: Tue, 23 Jun 2020 10:34:12 +0200 Message-ID: <20200623083412.GA3290@tuxteam.de> References: <871rm6lno4.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3V7upXqbjpZ4EhLz" Content-Disposition: inline In-Reply-To: <871rm6lno4.fsf@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) From: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/23 04:34:12 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, LOTS_OF_MONEY=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 23, 2020 at 12:51:23AM +0200, Sebastian Miele wrote: > Guile 3.0.3. The reference manual and the docstring of number->string > say: "If N is inexact, a radix of 10 will be used." But that is not what > happens, e.g., >=20 > (let ((x 4.0)) (and (inexact? x) (number->string x 3))) >=20 > evaluates to "11.0" instead of #f or "4.0". Probably "if RADIX is not > supplied, a radix of 10 will be used" is meant. Confirmed for 3.0.2. At first I thought that the fractional part being zero could be significant (as in your example), but scheme@(guile-user)> (number->string 0.3333333333333333 3) $5 =3D "0.1" is clearly being done in radix 3, fractional part and all. Cheers -- t --3V7upXqbjpZ4EhLz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAl7xvoQACgkQBcgs9XrR2kYk+ACfU4M/km29NheRod8fGjg0sXzB pKQAn2Os/9Pebo3EaSPBPQgKwTSSHKJW =R2kY -----END PGP SIGNATURE----- --3V7upXqbjpZ4EhLz-- From unknown Mon Jun 16 23:51:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#42012: Reference Manual and Docstring on number->string Resent-From: Bengt Richter Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 24 Jun 2020 03:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42012 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: tomas@tuxteam.de Cc: 42012@debbugs.gnu.org Reply-To: Bengt Richter Received: via spool by 42012-submit@debbugs.gnu.org id=B42012.15929706225207 (code B ref 42012); Wed, 24 Jun 2020 03:51:01 +0000 Received: (at 42012) by debbugs.gnu.org; 24 Jun 2020 03:50:22 +0000 Received: from localhost ([127.0.0.1]:37556 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnwQX-0001Lv-Gm for submit@debbugs.gnu.org; Tue, 23 Jun 2020 23:50:21 -0400 Received: from imta-35.everyone.net ([216.200.145.35]:55906 helo=imta-38.everyone.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnwQU-0001Lj-2m for 42012@debbugs.gnu.org; Tue, 23 Jun 2020 23:50:20 -0400 Received: from pps.filterd (m0004961.ppops.net [127.0.0.1]) by imta-38.everyone.net (8.16.0.27/8.16.0.27) with SMTP id 05O3mpjg027709; Tue, 23 Jun 2020 20:50:15 -0700 X-Eon-Originating-Account: 81AwT3MS3VvPs0Wg0IDVw9iIEswT3_ygqpmYw8d20LU X-Eon-Dm: m0116952.ppops.net Received: by m0116952.mta.everyone.net (EON-AUTHRELAY2 - 53b928f4) id m0116952.5ef2521e.919e; Tue, 23 Jun 2020 20:50:13 -0700 X-Eon-Sig: AQMHrIJe8s114oIauAIAAAAC,263a852f91b277379290ba5b53927fb1 X-Eip: 21LVHMRVLwkik59zaI6K09oqFoiFn7MlJuV34QS-c4E Date: Wed, 24 Jun 2020 05:49:58 +0200 From: Bengt Richter Message-ID: <20200624034958.GA2949@LionPure> References: <871rm6lno4.fsf@gmail.com> <20200623083412.GA3290@tuxteam.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20200623083412.GA3290@tuxteam.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-24_01:2020-06-23, 2020-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2004280000 definitions=main-2006240027 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On +2020-06-23 10:34:12 +0200, tomas@tuxteam.de wrote: > On Tue, Jun 23, 2020 at 12:51:23AM +0200, Sebastian Miele wrote: > > Guile 3.0.3. The reference manual and the docstring of number->string > > say: "If N is inexact, a radix of 10 will be used." But that is not what > > happens, e.g., > >=20 > > (let ((x 4.0)) (and (inexact? x) (number->string x 3))) > >=20 > > evaluates to "11.0" instead of #f or "4.0". Probably "if RADIX is not > > supplied, a radix of 10 will be used" is meant. >=20 > Confirmed for 3.0.2. At first I thought that the fractional part being > zero could be significant (as in your example), but >=20 > scheme@(guile-user)> (number->string 0.3333333333333333 3) > $5 =3D "0.1" >=20 > is clearly being done in radix 3, fractional part and all. >=20 > Cheers > -- t There are some other things that might be mentioned also, like the characters used by number->string and more surprisingly by string-= >number :-) You can try copying the following into ./show-string2num-chars.scm somewher= e and chmod 755 it and try running it, but it will produce one item per line, so it will be ha= ndy to let pr format that, like ./show-string2num-chars.scm|pr -t -8|uniq|sed -e 's:^:;;;; :' Unless your system is different, you should get the table in the comments = below. Since string->number will accept characters past #\z there may be a bug? See some experiments and speculations below the "BTW" ;-) --8<---------------cut here---------------start------------->8--- #!/usr/bin/env -S guile --no-auto-compile -e main -s !# ;;;; show-string2num-chars.scm (define (main args) (begin (let*((chrs255 (cdr (map integer->char (iota 256)))) (ints255 (map (lambda (c) (string->number (string c) 256)) chrs255)) (c2iprs (map (lambda (c i) (cons c i)) chrs255 ints255)) (okprs (filter (lambda (pr) (cdr pr)) c2iprs)) ;; ) (begin (map (lambda (pr) (format #t "~a=3D~a\n" (car pr) (cdr pr))) okprs) ;; )) ;; )) ;;;; running this from emacs right after the following line showing the ema= cs command: ;;;; Esc 1 Esc ! ./show-string2num-chars.scm|pr -t -8|uniq|sed -e 's:^:;;;;= :' ;;;; 0=3D0 9=3D9 I=3D18 R=3D27 Z=3D35 h=3D17 p=3D25 x= =3D33 ;;;; 1=3D1 A=3D10 J=3D19 S=3D28 a=3D10 i=3D18 q=3D26 = y=3D34 ;;;; 2=3D2 B=3D11 K=3D20 T=3D29 b=3D11 j=3D19 r=3D27 = z=3D35 ;;;; 3=3D3 C=3D12 L=3D21 U=3D30 c=3D12 k=3D20 s=3D28 = {=3D36 ;;;; 4=3D4 D=3D13 M=3D22 V=3D31 d=3D13 l=3D21 t=3D29 = |=3D37 ;;;; 5=3D5 E=3D14 N=3D23 W=3D32 e=3D14 m=3D22 u=3D30 = }=3D38 ;;;; 6=3D6 F=3D15 O=3D24 X=3D33 f=3D15 n=3D23 v=3D31 = ~=3D39 ;;;; 7=3D7 G=3D16 P=3D25 Y=3D34 g=3D16 o=3D24 w=3D32 = =7F=3D40 ;;;; 8=3D8 H=3D17 Q=3D26 ;;;; #\z=3D35 #\{=3D36 #\|=3D37 #\}=3D38 #\delete=3D#f=20 ;;;; scheme@(guile-user) [6]>=20 ;;;; BTW ;;;; scheme@(guile-user) [6]> (string-for-each (lambda (c) (format #t "~s= =3D~a " c (string->number (string c) 40))) "z{|}\x7f")(newline) ;;;; ;;;; #\z=3D35 #\{=3D36 #\|=3D37 #\}=3D38 #\delete=3D#f ;;;; scheme@(guile-user) [6]> =20 ;;;; it will also apparently happily accept multiple characters z through \= x7f and convert them with any radix exceeding ;;;; the largest "digit value ;;;; scheme@(guile-user) [8]> (for-each (lambda (s) (format #t "~s=3D~a " s= (string->number s 1000))) '("0" "1" "10" "z{" "|}" "\x7f")) (newline) ;;;; "0"=3D0 "1"=3D1 "10"=3D1000 "z{"=3D35036 "|}"=3D37038 "\x7f"=3D40=20 ;;;; scheme@(guile-user) [8]>=20 ;;;; the following makes me think possibly the unicode value is taken and m= asked with 0x7f for ascii and then ;;;; accepted if >=3D 97 (#\a) (accidentally including > 122 (#\z), only ch= ecking for [0-9] and [A-Z] if maked value is less than 97 (#\a) ;;;;scheme@(guile-user) [8]> (for-each (lambda (s) (format #t "~s=3D~a " s = (string->number s 1000))) '("0" "1" "10" "111" "z{" "|}" "\x7f\x80" "\x80\x= 7f" "\u807e")) (newline) ;;;; "0"=3D0 "1"=3D1 "10"=3D1000 "111"=3D1001001 "z{"=3D35036 "|}"=3D37038 = "\x7f\x80"=3D40041 "\x80\x7f"=3D#f "=E8=81=BE"=3D39=20 ;;;; I'll leave it to others to explore further :) ;;;; Note, though, that the inverse -- number->string -- will not accept a = radix outide of 2-36: ;;;; scheme@(guile-user) [10]> (number->string (+ (* 34 36) 35) 36) ;;;; $18 =3D "yz" ;;;; scheme@(guile-user) [10]> (number->string (+ (* 34 36) 35) 40) ;;;; ERROR: In procedure number->string: ;;;; Value out of range 2 to 36: 40 ;;;;=20 ;;;; Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. ;;;; scheme@(guile-user) [11]> (number->string (+ (* 34 36) 35) 37) ;;;; ERROR: In procedure number->string: ;;;; Value out of range 2 to 36: 37 ;;;;=20 --8<---------------cut here---------------end--------------->8--- --=20 Regards, Bengt Richter