From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Bengt Richter Newsgroups: gmane.lisp.guile.bugs Subject: bug#42012: Reference Manual and Docstring on number->string Date: Wed, 24 Jun 2020 05:49:58 +0200 Message-ID: <20200624034958.GA2949@LionPure> References: <871rm6lno4.fsf@gmail.com> <20200623083412.GA3290@tuxteam.de> Reply-To: Bengt Richter Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="90513"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 42012@debbugs.gnu.org To: tomas@tuxteam.de Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Wed Jun 24 05:51:08 2020 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnwRH-000NR0-75 for guile-bugs@m.gmane-mx.org; Wed, 24 Jun 2020 05:51:07 +0200 Original-Received: from localhost ([::1]:40158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnwRF-0005GN-MD for guile-bugs@m.gmane-mx.org; Tue, 23 Jun 2020 23:51:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnwRC-0005GD-4Y for bug-guile@gnu.org; Tue, 23 Jun 2020 23:51:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54243) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnwRB-0001fq-QE for bug-guile@gnu.org; Tue, 23 Jun 2020 23:51:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jnwRB-0001Mu-Ok for bug-guile@gnu.org; Tue, 23 Jun 2020 23:51:01 -0400 X-Loop: help-debbugs@gnu.org 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 Original-Received: via spool by 42012-submit@debbugs.gnu.org id=B42012.15929706225207 (code B ref 42012); Wed, 24 Jun 2020 03:51:01 +0000 Original-Received: (at 42012) by debbugs.gnu.org; 24 Jun 2020 03:50:22 +0000 Original-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 Original-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 Original-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 Original-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 Content-Disposition: inline In-Reply-To: <20200623083412.GA3290@tuxteam.de> 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9829 Archived-At: 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