From unknown Tue Sep 09 11:59:51 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#11887 <11887@debbugs.gnu.org> To: bug#11887 <11887@debbugs.gnu.org> Subject: Status: string->number edge cases Reply-To: bug#11887 <11887@debbugs.gnu.org> Date: Tue, 09 Sep 2025 18:59:51 +0000 retitle 11887 string->number edge cases reassign 11887 guile submitter 11887 Ian Price severity 11887 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 09 08:35:26 2012 Received: (at submit) by debbugs.gnu.org; 9 Jul 2012 12:35:26 +0000 Received: from localhost ([127.0.0.1]:57695 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SoDBU-0000th-2i for submit@debbugs.gnu.org; Mon, 09 Jul 2012 08:35:26 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39518) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SoDBK-0000tR-PI for submit@debbugs.gnu.org; Mon, 09 Jul 2012 08:35:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoD67-0004y6-Fb for submit@debbugs.gnu.org; Mon, 09 Jul 2012 08:29:59 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, NORMAL_HTTP_TO_IP, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:56925) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoD67-0004xx-Bd for submit@debbugs.gnu.org; Mon, 09 Jul 2012 08:29:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoD62-0003Xf-PZ for bug-guile@gnu.org; Mon, 09 Jul 2012 08:29:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoD5u-0004t4-5B for bug-guile@gnu.org; Mon, 09 Jul 2012 08:29:46 -0400 Received: from plane.gmane.org ([80.91.229.3]:50108) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoD5t-0004sL-Jk for bug-guile@gnu.org; Mon, 09 Jul 2012 08:29:38 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SoD5q-0003cV-N9 for bug-guile@gnu.org; Mon, 09 Jul 2012 14:29:34 +0200 Received: from host31-53-23-51.range31-53.btcentralplus.com ([31.53.23.51]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 Jul 2012 14:29:34 +0200 Received: from ianprice90 by host31-53-23-51.range31-53.btcentralplus.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 Jul 2012 14:29:34 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: bug-guile@gnu.org From: Ian Price Subject: string->number edge cases Date: Mon, 09 Jul 2012 13:29:16 +0100 Lines: 904 Message-ID: <87sjd1qfs3.fsf@Kagami.home> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: host31-53-23-51.range31-53.btcentralplus.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:We4Brep+8IvdT3yO6OOw+SmSDtQ= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -6.9 (------) X-Debbugs-Envelope-To: submit Cc: Peter.Bex@xs4all.nl X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi guilers, I've mentioned these to Mark Weaver on IRC off-hand before, but I'm posting this bug report to "formalise" it, and make sure we don't forget. Peter Bex, as one of the maintainers of the chicken "numbers" egg, created a thorough test suite for string->number a while ago[0], and it points out a number of possible and actual errors in the handling of string->number. I've attached a copy with the modifications for guile already applied, and a copy of the full results, but the summary is as follows. If the number contains a division by zero, we get a numerical overflow error. scheme@(guile−user)> (string->number "3/0") ERROR: In procedure string−>number: ERROR: Throw to key `numerical−overflow' with args `("make−ratio" "Numerical overflow" #f #f)'. Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile−user) [1]> ,q This contradicts the r6rs specification[1], which mandates a return value of #f. IMO, this is the correct behaviour, since otherwise, we have created a special case in the API for one type of invalid number. (These tests cause the program to stop, and so are commented out in the attached version.) The rest of the errors are less serious, and show that we treat nans and infinity someone inconsistently in guile. Specifically, we are strict on case, and lenient on the numerical prefix. 0. http://bugs.call-cc.org/browser/release/4/numbers/trunk/tests/string-conversion.scm 1. http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_idx_584 Peter, Thanks for these -- Ian Price "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled" --=-=-= Content-Disposition: attachment; filename=string-conversion.scm Content-Description: Conversion tests courtesy of Peter Bex ;;; ;;; Numerical syntax "torture test" ;;; ;;; This tries to test a lot of edge cases in Scheme's numerical syntax. ;;; ;;; Output is written so that if you run it through "grep ERROR" it will ;;; output nothing (and exit status will be nonzero) if there are no errors. ;;; If you run it through "tail -n 1" you will just get the total error summary. ;;; ;;; This code assumes that string->number accepts numbers with embedded radix ;;; specifiers (R5RS mentions that it's allowed to return #f in those cases). ;;; It also doesn't try to support Schemes which support *only* integers or ;;; *only* flonums (which is also allowed by R5RS). ;;; ;;; ;; The prelude below is messy but required to get everything working ;; with some of the major Schemes. ;; ;; Also note that to test with Gambit, it appears you first need to type in ;; (load "~~/lib/syntax-case") and then load this file, or use gsi's -:s switch ;;; ;(use extras numbers) ; Chicken w/ numbers ;(use-syntax (ice-9 syncase)) ; Guile ;; Set this to #f if the Scheme has no compnums at all, 'inexact if it only ;; supports inexact compnums or 'exact if it supports exact compnums. ;; (Gauche, Guile, SCM: inexact, Chicken w/o numbers: #f) (define compnum-type 'inexact) ;; Set this to #f if the Scheme has no fractional number support, ;; 'exact if it supports rational numbers and 'inexact if it converts fractions ;; to floating-point, inexact numbers (define fraction-type 'exact) ;; Fix these if your Scheme doesn't allow division by zero ;; For Chicken without the numbers egg, use fp/ instead of / (define the-nan (/ 0.0 0.0)) (define pos-inf (/ 1.0 0.0)) (define neg-inf (/ -1.0 0.0)) ; Scheme48, Racket, Gambit, Chicken w/o numbers, SCM ;(define (nan? x) (and (number? x) (not (= x x)))) (define total-errors 0) (define (check-string-against-values! str . possible-values) (let ((res (string->number str))) (let lp ((values possible-values)) (if (null? values) (begin (display "PARSE ERROR ") (write (cons str possible-values)) (display " => ") (write res) (newline) (set! total-errors (+ total-errors 1))) (let ((value (car values))) (if (not (or (and (not (string? value)) (equal? res value)) (and res (nan? res) (or (and value (nan? value)))))) (lp (cdr values)) (let ((re-str (and res (number->string res)))) (let lp2 ((values possible-values)) (if (null? values) (begin (display "SERIALIZATION ERROR ") (write (cons str possible-values)) (display " => ") (write re-str) (newline) (set! total-errors (+ total-errors 1))) (let ((value (car values))) (if (not (or (and res (string=? re-str str)) (and (not res) (not value)) (and res (string? value) (string=? re-str value)))) (lp2 (cdr values)) (begin (display "OK ") (write (cons str possible-values)) (newline))))))))))))) ;; Here comes a horrible nasty hack. It seems to work though ;) (define-syntax test-numbers (syntax-rules (compnums fractions) ((_ (compnums (types e1 ...) ...) rest ...) (begin (case compnum-type (types (test-numbers e1 ... "no-totals")) ...) (test-numbers rest ...))) ((_ (fractions (types e1 ...) ...) rest ...) (begin (case fraction-type (types (test-numbers e1 ... "no-totals")) ...) (test-numbers rest ...))) ((_ (str value ...) rest ...) (begin (check-string-against-values! str value ...) (test-numbers rest ...))) ((_ "no-totals") #f) ((_ x rest ...) (begin (newline) (display "-> ") (display x) (newline) (display "-----------------------------------------------------") (newline) (test-numbers rest ...))) ((_) (if (= 0 total-errors) (begin (newline) (display "-----> Everything OK, no errors!") (newline)) (begin (newline) (display "-----> TOTAL ERRORS: ") (display total-errors) (newline)))))) (test-numbers "Simple integers" ("1" 1) ("+1" 1 "1") ("-1" (- 1)) ("#i1" 1.0 "1.0" "1.") ("#I1" 1.0 "1.0" "1.") ("#i-1" (- 1.0) "-1.0" "-1.") ("-#i1" #f) ("+-1" #f) ("" #f) ("-" #f) ("+" #f) ("+-" #f) "Basic decimal notation" ("1.0" (exact->inexact 1) "1.") ("1." 1.0 "1.0" "1.") ("1.#" 1.0 1.5 "1.0" "1." "1.5") (".1" 0.1 "0.1" "100.0e-3") ("-.1" (- 0.1) "-0.1" "-100.0e-3") ;; Some Schemes don't allow negative zero. This is okay with the standard ("-.0" -0.0 "-0." "-0.0" "0.0" "0." ".0") ("-0." -0.0 "-.0" "-0.0" "0.0" "0." ".0") ("." #f) (".1." #f) ("..1" #f) ("1.." #f) ("#i1.0" 1.0 "1.0" "1.") ("#e1.0" 1 "1") ("#e-.0" 0 "0") ("#e-0." 0 "0") ("-#e.0" #f) "Decimal notation with padding" ("1#" 10.0 15.0 "10.0" "15.0" "10." "15.") ("#e1#" 10 15 "10" "15") ("#E1#" 10 15 "10" "15") ("#1" #f) ("#" #f) ("1#2" #f) ("1.#2" #f) (".#" #f) ("#.#" #f) ("#.1" #f) ("1#.2" #f) ("1#." 10.0 15.0 "10.0" "15.0" "10." "15.") "Decimal notation with suffix" ("1e2" 100.0 "100.0" "100.") ("1E2" 100.0 "100.0" "100.") ("1s2" 100.0 "100.0" "100.") ("1S2" 100.0 "100.0" "100.") ("1f2" 100.0 "100.0" "100.") ("1F2" 100.0 "100.0" "100.") ("1d2" 100.0 "100.0" "100.") ("1D2" 100.0 "100.0" "100.") ("1l2" 100.0 "100.0" "100.") ("1L2" 100.0 "100.0" "100.") ("1e2e3" #f) ("1e2s3" #f) ("1e2.0" #f) "Decimal notation with suffix and padding" ("1#e2" 1000.0 1500.0 "1000.0" "1500.0" "1000." "1500." "1.0e3" "15.0e2") ("1e2#" #f) "NaN, Inf" ("+nan.0" the-nan "+NaN.0") ("+NAN.0" the-nan "+nan.0" "+NaN.0") ("+nan.1" #f) ("+nan.01" #f) ("+inf.0" pos-inf "+Inf.0") ("+InF.0" pos-inf "+inf.0" "+Inf.0") ("-inf.0" neg-inf "-Inf.0") ("-iNF.0" neg-inf "-inf.0" "-Inf.0") ("+inf.01" #f) ("+inf.1" #f) ("-inf.01" #f) ("-inf.1" #f) ("+inf.0/1" #f) ("1/+inf.0" #f) ("+nan" #f) ("+inf" #f) ("-inf" #f) ("nan.0" #f) ("inf.0" #f) ;; Thanks to John Cowan for these ("#e+nan.0" #f) ("#e+inf.0" #f) ("#e-inf.0" #f) ("#i+nan.0" the-nan "+nan.0" "+NaN.0") ("#i+inf.0" pos-inf "+inf.0" "+Inf.0") ("#i-inf.0" neg-inf "-inf.0" "-Inf.0") "Fractions" (fractions ((exact) ("1/2" (/ 1 2)) ("#e1/2" (/ 1 2) "1/2") ("10/2" 5 "5") ("-1/2" (- (/ 1 2))) ;("10/0" #f) ("0/10" 0 "0") ("#e0/10" 0 "0") ("#e1#/2" 5 (/ 15 2) "5" "15/2") ("#e1/2#" (/ 1 20) "1/20") ("#i3/2" (/ 3.0 2.0) "1.5")) ((inexact) ("1/2" (/ 1 2) "0.5" ".5" "500.0e-3") ("0/10" 0.0 "0.0") ("10/2" 5.0 "5.0" "5.") ;; Unsure what "#e1/2" is supposed to do in Scheme w/o exact fractions ("#i10/2" 5.0 "5.0" "5.") ("-1/2" (- (/ 1 2)) "-0.5" "-.5" "-500.0e-3"))) (fractions ((inexact exact) ;("#i1/0" pos-inf "+inf.0" "+Inf.0") ;("#i-1/0" neg-inf "-inf.0" "-Inf.0") ;("#i0/0" the-nan "+nan.0" "+NaN.0") ;; This _could_ be valid in some Schemes (but isn't as pretty) ;("#i1/0" #f) ;("#i-1/0" #f) ;("#i0/0" #f) ("1/-2" #f) ("1.0/2" #f) ("1/2.0" #f) ("1/2e2" #f) ("1/2e2" #f) ("1#/2" 5.0 7.5 "5.0" "5." "7.5") ("1/2#" 0.05 "0.05" ".05" "50.0e-3") ("1#/#" #f) ("1/" #f) ("1/+" #f) ("+/1" #f) ("/1" #f) ("/" #f))) "Basic complex numbers (rectangular notation)" (compnums ((exact) ("1+2i" (make-rectangular 1 2)) ("1+2I" (make-rectangular 1 2) "1+2i") ("1-2i" (make-rectangular 1 -2)) ("-1+2i" (make-rectangular -1 2)) ("-1-2i" (make-rectangular -1 -2)) ("+i" (make-rectangular 0 1) "+1i" "0+i" "0+1i") ("0+i" (make-rectangular 0 1) "+i" "+1i" "0+1i") ("0+1i" (make-rectangular 0 1) "+i" "+1i" "0+i") ("-i" (make-rectangular 0 -1) "-1i" "0-i" "0-1i") ("0-i" (make-rectangular 0 -1) "-i" "-1i" "0-1i") ("0-1i" (make-rectangular 0 -1) "-i" "-1i" "0-i") ("+2i" (make-rectangular 0 2) "0+2i") ("-2i" (make-rectangular 0 -2) "-2i" "0-2i")) ((inexact) ("1+2i" (make-rectangular 1 2) "1.0+2.0i" "1.+2.i") ("1+2I" (make-rectangular 1 2) "1.0+2.0i" "1.+2.i") ("1-2i" (make-rectangular 1 -2) "1.0-2.0i" "1.-2.i") ("-1+2i" (make-rectangular -1 2) "-1.0+2.0i" "-1.+2.i") ("-1-2i" (make-rectangular -1 -2) "-1.0-2.0i" "-1.-2.i") ("+i" (make-rectangular 0 1) "+1.i" "+1.0i" "0.+1.i" "0.0+1.0i") ("0+i" (make-rectangular 0 1) "0+1i" "+1.i" "+1.0i" "0.+1.i" "0.0+1.0i") ("0+1i" (make-rectangular 0 1) "+1.i" "+1.0i" "0.+1.i" "0.0+1.0i") ("-i" (make-rectangular 0 -1) "-1.i" "-1.0i" "0.-1.i" "0.0-1.0i") ("0-i" (make-rectangular 0 -1) "-1.i" "-1.0i" "0.-1.i" "0.0-1.0i") ("0-1i" (make-rectangular 0 -1) "-1.i" "-1.0i" "0.-1.i" "0.0-1.0i") ("+2i" (make-rectangular 0 2) "+2.0i" "+2.i" "0.+2.i" "0.0+2.0i") ("-2i" (make-rectangular 0 -2) "-2.0i" "-2.i" "0.-2.i" "0.0-2.0i"))) (compnums ((exact inexact) ("1#+1#i" (make-rectangular 10.0 10.0) (make-rectangular 15.0 15.0) "10.0+10.0i" "10.+10.i" "15.0+15.0i" "15.+15.i"))) ("2i" #f) ("+-i" #f) ("i" #f) ("1+2i1" #f) ("1+2" #f) ("1#+#i" #f) (compnums ((exact inexact) "Decimal-notation complex numbers (rectangular notation)" ("1.0+2i" (make-rectangular 1.0 2) "1.0+2.0i" "1.0+2i" "1.+2i" "1.+2.i") ("1+2.0i" (make-rectangular 1 2.0) "1.0+2.0i" "1+2.0i" "1.+2.i" "1+2.i") ("1#.+1#.i" (make-rectangular 10.0 10.0) (make-rectangular 15.0 15.0) "10.0+10.0i" "10.+10.i" "15.0+15.0i" "15.+15.i") ("1e2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i") ("1s2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i") ("1.0+1e2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i") ("1.0+1s2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i") ("1#e2+1.0i" (make-rectangular 1000.0 1.0) (make-rectangular 1500.0 1.0) "1000.0+1.0i" "1000.+1.i" "1500.0+1.0i" "1500.+1.i" "1.0e3+1.0i" "15.0e2+1.0i") ("1.0+1#e2i" (make-rectangular 1.0 1000.0) (make-rectangular 1.0 1500.0) "1.0+1000.0i" "1.+1000.i" "1.0+1500.0i" "1.+1500.i" "1.0+1.0e3i" "1.0+15.0e2i") (".i" #f) ("+.i" #f) (".+i" #f))) (compnums ((exact) "Fractional complex numbers (rectangular notation)" ("1/2+3/4i" (make-rectangular (/ 1 2) (/ 3 4)))) ((inexact) "Fractional complex numbers (rectangular notation)" ("1/2+3/4i" (make-rectangular (/ 1 2) (/ 3 4)) "0.5+0.75i" ".5+.75i" "500.0e-3+750.0e-3i"))) (compnums ((exact inexact) "Mixed fractional/decimal notation complex numbers (rectangular notation)" ("1#/2+3/4i" (make-rectangular 5.0 (/ 3 4)) (make-rectangular 7.5 (/ 3 4)) "5.0+0.75i" "5.+.75i" "7.5+0.75i" "5.0+3/4i" "5.+3/4i" "7.5+3/4i" "5.0+750.0e-3i") ("0.5+3/4i" (make-rectangular 0.5 (/ 3 4)) "0.5+0.75i" ".5+.75i" "0.5+3/4i" ".5+3/4i" "500.0e-3+750.0e-3i") ("1.5+1#/4i" (make-rectangular 1.5 2.5) (make-rectangular 1.5 3.75) "1.5+2.5i" "1.5+3.75i") ("0.5+1/#i" #f) ("0.5+1/1#2i" #f) ("1/#+0.5i" #f) ("1/1#2+0.5i" #f) "Mixed notation with infinity (might fail on mixed exactness compnums)" ;; This is a nasty one. Switch to inexact *after* reading the first number. ;; Note that it's perfectly acceptable for a scheme with *mixed* exactness ;; in complex values to return #f here. TODO: How to parameterize this, we ;; *really* want to test that single-exactness compnums systems accept this. ;("1/0+1.2i" (make-rectangular pos-inf 1.2) "+inf.0+1.2i" "+Inf.0+1.2i") ;; Less nasty, most get this right. Same caveat as above re: mixed exactness ;("1.2+1/0i" (make-rectangular 1.2 pos-inf) "1.2+inf.0i" ;"1.2+Inf.0") )) (compnums ((exact inexact) "Complex NaN, Inf (rectangular notation)" ("+nan.0+nan.0i" (make-rectangular the-nan the-nan) "+NaN.0+NaN.0i") ("+inf.0+inf.0i" (make-rectangular pos-inf pos-inf) "+Inf.0+Inf.0i") ("-inf.0+inf.0i" (make-rectangular neg-inf pos-inf) "-Inf.0+Inf.0i") ("-inf.0-inf.0i" (make-rectangular neg-inf neg-inf) "-Inf.0-Inf.0i") ("+inf.0-inf.0i" (make-rectangular pos-inf neg-inf) "+Inf.0-Inf.0i") "Complex numbers (polar notation)" ;; TODO: Add some here. The problem is the representation ;; is hard to nail down when echoed back as rectangular ;; since they're floating point with many digits, and depend ;; on the precision of PI used internally. ("1@2i" #f) ("0.5@1/#" #f) ("0.5@1/1#2" #f) ("1/#@0.5" #f) ("1/1#2@0.5" #f) ("1@" #f) ("1#@#" #f) ("1/@" #f) ("@/1" #f) ("@1" #f) ("1@+" #f) ("+@1" #f) ("@" #f))) "Base prefixes" ("#x11" 17 "17") ("#X11" 17 "17") ("#d11" 11 "11") ("#D11" 11 "11") ("#o11" 9 "9") ("#O11" 9 "9") ("#b11" 3 "3") ("#B11" 3 "3") ("#da1" #f) ("#o8" #f) ("#b2" #f) ("#o7" 7 "7") ("#xa" 10 "10") ("#xA" 10 "10") ("#xf" 15 "15") ("#xg" #f) ("#x-10" -16 "-16") ("#d-10" -10 "-10") ("#o-10" -8 "-8") ("#b-10" -2 "-2") ("-#x10" #f) ("-#d10" #f) ("-#o10" #f) ("-#b10" #f) ("#x-" #f) ("#x" #f) ("#d" #f) ("#d-" #f) ("#d+" #f) ("#o" #f) ("#o-" #f) ("#b" #f) ("#b-" #f) ("#e" #f) ("#e-" #f) ("#i" #f) ("#i-" #f) "Combination of prefixes" ("#x#x11" #f) ("#x#b11" #f) ("#b#o11" #f) ("#e#x10" 16 "16") ("#i#x10" 16.0 "16.0" "16.") ("#e#e10" #f) ("#e#e#x10" #f) ("#E#e#X10" #f) ("#i#e#x10" #f) ("#e#x#e10" #f) ("#x#x#e10" #f) ("#x#e#x10" #f) "Base prefixes with padding" ("#x1#0" #f) ("#d1#0" #f) ("#o1#0" #f) ("#b1#0" #f) ("#x1#" 16.0 24.0 "16.0" "24.0" "16." "24.") ("#d1#" 10.0 15.0 "10.0" "15.0" "10." "15.") ("#o1#" 8.0 12.0 "8.0" "12.0" "8." "12.") ("#b1#" 2.0 3.0 "2.0" "3.0" "2." "3.") "(Attempted) decimal notation with base prefixes" ("#x1.0" #f) ("#d1.0" 1.0 "1.0" "1.") ("#o1.0" #f) ("#b1.0" #f) ("#x1.#" #f) ("#d1.#" 1.0 1.5 "1.0" "1.5" "1.") ("#o1.#" #f) ("#b1.#" #f) ("#x1." #f) ("#d1." 1.0 "1.0" "1.") ("#o1." #f) ("#b1." #f) ("#x.1" #f) ("#d.1" 0.1 "0.1" ".1" "100.0e-3") ("#o.1" #f) ("#b.1" #f) ("#x1e2" 482 "482") ("#d1e2" 100.0 "100.0" "100.") ("#o1e2" #f) ("#b1e2" #f) "Fractions with prefixes" (fractions ((inexact) ("#x10/2" 8.0 "8.0" "8.") ("#x11/2" 8.5 "8.5") ("#d11/2" 5.5 "5.5") ("#o11/2" 4.5 "4.5") ("#b11/10" 1.5 "1.5")) ((exact) ("#x10/2" 8 "8") ("#x11/2" (/ 17 2) "17/2") ("#d11/2" (/ 11 2) "11/2") ("#o11/2" (/ 9 2) "9/2") ("#b11/10" (/ 3 2) "3/2"))) (fractions ((inexact exact) ("#b11/2" #f) ("#x10/#o10" #f) ("10/#o10" #f) ("#x1#/2" 8.0 12.0 "8.0" "8." "12.0" "12.") ("#d1#/2" 5.0 7.5 "5.0" "5." "7.5") ("#o1#/2" 4.0 6.0 "4.0" "4." "6.0" "6.") ("#b1#/2" #f) ("#b1#/10" 1.0 1.5 "1.0" "1." "1.5"))) (compnums ((exact inexact) "Complex numbers with prefixes" ("#x1#+1#i" (make-rectangular 16.0 16.0) (make-rectangular 24.0 24.0) "16.0+16.0i" "16.+16.i" "24.0+24.0i" "24.+24.i") ("#x1.0+1.0i" #f) ("#d1.0+1.0i" (make-rectangular 1.0 1.0) "1.0+1.0i" "1.+1.i") ("#o1.0+1.0i" #f) ("#b1.0+1.0i" #f) ("#x10+#o10i" #f) ("10+#o10i" #f) ("#x1@#x1" #f) ("1@#x1" #f))) (compnums ((exact) ("#x10+11i" (make-rectangular 16 17) "16+17i") ("#d10+11i" (make-rectangular 10 11) "10+11i") ("#o10+11i" (make-rectangular 8 9) "8+9i") ("#b10+11i" (make-rectangular 2 3) "2+3i") ("#e1.0+1.0i" (make-rectangular 1 1) "1+1i" "1+i") ("#i1.0+1.0i" (make-rectangular 1.0 1.0) "1.0+1.0i" "1.+1.i")) ((inexact) ("#x10+11i" (make-rectangular 16 17) "16.0+17.0i" "16.+17.i") ("#d10+11i" (make-rectangular 10 11) "10.0+11.0i" "10.+11.i") ("#o10+11i" (make-rectangular 8 9) "8.0+9.0i" "8.+9.i") ("#b10+11i" (make-rectangular 2 3) "2.0+3.0i" "2.+3.i"))) ) --=-=-= Content-Disposition: attachment; filename=results.txt Content-Description: results ;;; note: source file /home/ian/Downloads/string-conversion.scm ;;; newer than compiled /home/ian/.cache/guile/ccache/2.0-LE-4-2.0/home/ian/Downloads/string-conversion.scm.go ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 ;;; or pass the --no-auto-compile argument to disable. ;;; compiling /home/ian/Downloads/string-conversion.scm ;;; compiled /home/ian/.cache/guile/ccache/2.0-LE-4-2.0/home/ian/Downloads/string-conversion.scm.go -> Simple integers ----------------------------------------------------- OK ("1" 1) OK ("+1" 1 "1") OK ("-1" -1) OK ("#i1" 1.0 "1.0" "1.") OK ("#I1" 1.0 "1.0" "1.") OK ("#i-1" -1.0 "-1.0" "-1.") OK ("-#i1" #f) OK ("+-1" #f) OK ("" #f) OK ("-" #f) OK ("+" #f) OK ("+-" #f) -> Basic decimal notation ----------------------------------------------------- OK ("1.0" 1.0 "1.") OK ("1." 1.0 "1.0" "1.") OK ("1.#" 1.0 1.5 "1.0" "1." "1.5") OK (".1" 0.1 "0.1" "100.0e-3") OK ("-.1" -0.1 "-0.1" "-100.0e-3") OK ("-.0" -0.0 "-0." "-0.0" "0.0" "0." ".0") OK ("-0." -0.0 "-.0" "-0.0" "0.0" "0." ".0") OK ("." #f) OK (".1." #f) OK ("..1" #f) OK ("1.." #f) OK ("#i1.0" 1.0 "1.0" "1.") OK ("#e1.0" 1 "1") OK ("#e-.0" 0 "0") OK ("#e-0." 0 "0") OK ("-#e.0" #f) -> Decimal notation with padding ----------------------------------------------------- OK ("1#" 10.0 15.0 "10.0" "15.0" "10." "15.") OK ("#e1#" 10 15 "10" "15") OK ("#E1#" 10 15 "10" "15") OK ("#1" #f) OK ("#" #f) OK ("1#2" #f) OK ("1.#2" #f) OK (".#" #f) OK ("#.#" #f) OK ("#.1" #f) OK ("1#.2" #f) OK ("1#." 10.0 15.0 "10.0" "15.0" "10." "15.") -> Decimal notation with suffix ----------------------------------------------------- OK ("1e2" 100.0 "100.0" "100.") OK ("1E2" 100.0 "100.0" "100.") OK ("1s2" 100.0 "100.0" "100.") OK ("1S2" 100.0 "100.0" "100.") OK ("1f2" 100.0 "100.0" "100.") OK ("1F2" 100.0 "100.0" "100.") OK ("1d2" 100.0 "100.0" "100.") OK ("1D2" 100.0 "100.0" "100.") OK ("1l2" 100.0 "100.0" "100.") OK ("1L2" 100.0 "100.0" "100.") OK ("1e2e3" #f) OK ("1e2s3" #f) OK ("1e2.0" #f) -> Decimal notation with suffix and padding ----------------------------------------------------- OK ("1#e2" 1000.0 1500.0 "1000.0" "1500.0" "1000." "1500." "1.0e3" "15.0e2") OK ("1e2#" #f) -> NaN, Inf ----------------------------------------------------- OK ("+nan.0" +nan.0 "+NaN.0") PARSE ERROR ("+NAN.0" +nan.0 "+nan.0" "+NaN.0") => #f PARSE ERROR ("+nan.1" #f) => +nan.0 PARSE ERROR ("+nan.01" #f) => +nan.0 OK ("+inf.0" +inf.0 "+Inf.0") PARSE ERROR ("+InF.0" +inf.0 "+inf.0" "+Inf.0") => #f OK ("-inf.0" -inf.0 "-Inf.0") PARSE ERROR ("-iNF.0" -inf.0 "-inf.0" "-Inf.0") => #f OK ("+inf.01" #f) OK ("+inf.1" #f) OK ("-inf.01" #f) OK ("-inf.1" #f) OK ("+inf.0/1" #f) OK ("1/+inf.0" #f) OK ("+nan" #f) OK ("+inf" #f) OK ("-inf" #f) PARSE ERROR ("nan.0" #f) => +nan.0 PARSE ERROR ("inf.0" #f) => +inf.0 PARSE ERROR ("#e+nan.0" #f) => +nan.0 PARSE ERROR ("#e+inf.0" #f) => +inf.0 PARSE ERROR ("#e-inf.0" #f) => -inf.0 OK ("#i+nan.0" +nan.0 "+nan.0" "+NaN.0") OK ("#i+inf.0" +inf.0 "+inf.0" "+Inf.0") OK ("#i-inf.0" -inf.0 "-inf.0" "-Inf.0") -> Fractions ----------------------------------------------------- OK ("1/2" 1/2) OK ("#e1/2" 1/2 "1/2") OK ("10/2" 5 "5") OK ("-1/2" -1/2) OK ("0/10" 0 "0") OK ("#e0/10" 0 "0") OK ("#e1#/2" 5 15/2 "5" "15/2") OK ("#e1/2#" 1/20 "1/20") OK ("#i3/2" 1.5 "1.5") OK ("1/-2" #f) OK ("1.0/2" #f) OK ("1/2.0" #f) OK ("1/2e2" #f) OK ("1/2e2" #f) OK ("1#/2" 5.0 7.5 "5.0" "5." "7.5") OK ("1/2#" 0.05 "0.05" ".05" "50.0e-3") OK ("1#/#" #f) OK ("1/" #f) OK ("1/+" #f) OK ("+/1" #f) OK ("/1" #f) OK ("/" #f) -> Basic complex numbers (rectangular notation) ----------------------------------------------------- OK ("1+2i" 1.0+2.0i "1.0+2.0i" "1.+2.i") OK ("1+2I" 1.0+2.0i "1.0+2.0i" "1.+2.i") OK ("1-2i" 1.0-2.0i "1.0-2.0i" "1.-2.i") OK ("-1+2i" -1.0+2.0i "-1.0+2.0i" "-1.+2.i") OK ("-1-2i" -1.0-2.0i "-1.0-2.0i" "-1.-2.i") OK ("+i" 0.0+1.0i "+1.i" "+1.0i" "0.+1.i" "0.0+1.0i") OK ("0+i" 0.0+1.0i "0+1i" "+1.i" "+1.0i" "0.+1.i" "0.0+1.0i") OK ("0+1i" 0.0+1.0i "+1.i" "+1.0i" "0.+1.i" "0.0+1.0i") OK ("-i" 0.0-1.0i "-1.i" "-1.0i" "0.-1.i" "0.0-1.0i") OK ("0-i" 0.0-1.0i "-1.i" "-1.0i" "0.-1.i" "0.0-1.0i") OK ("0-1i" 0.0-1.0i "-1.i" "-1.0i" "0.-1.i" "0.0-1.0i") OK ("+2i" 0.0+2.0i "+2.0i" "+2.i" "0.+2.i" "0.0+2.0i") OK ("-2i" 0.0-2.0i "-2.0i" "-2.i" "0.-2.i" "0.0-2.0i") OK ("1#+1#i" 10.0+10.0i 15.0+15.0i "10.0+10.0i" "10.+10.i" "15.0+15.0i" "15.+15.i") OK ("2i" #f) OK ("+-i" #f) OK ("i" #f) OK ("1+2i1" #f) OK ("1+2" #f) OK ("1#+#i" #f) -> Decimal-notation complex numbers (rectangular notation) ----------------------------------------------------- OK ("1.0+2i" 1.0+2.0i "1.0+2.0i" "1.0+2i" "1.+2i" "1.+2.i") OK ("1+2.0i" 1.0+2.0i "1.0+2.0i" "1+2.0i" "1.+2.i" "1+2.i") OK ("1#.+1#.i" 10.0+10.0i 15.0+15.0i "10.0+10.0i" "10.+10.i" "15.0+15.0i" "15.+15.i") OK ("1e2+1.0i" 100.0+1.0i "100.0+1.0i" "100.+1.i") OK ("1s2+1.0i" 100.0+1.0i "100.0+1.0i" "100.+1.i") OK ("1.0+1e2i" 1.0+100.0i "1.0+100.0i" "1.+100.i") OK ("1.0+1s2i" 1.0+100.0i "1.0+100.0i" "1.+100.i") OK ("1#e2+1.0i" 1000.0+1.0i 1500.0+1.0i "1000.0+1.0i" "1000.+1.i" "1500.0+1.0i" "1500.+1.i" "1.0e3+1.0i" "15.0e2+1.0i") OK ("1.0+1#e2i" 1.0+1000.0i 1.0+1500.0i "1.0+1000.0i" "1.+1000.i" "1.0+1500.0i" "1.+1500.i" "1.0+1.0e3i" "1.0+15.0e2i") OK (".i" #f) OK ("+.i" #f) OK (".+i" #f) -> Fractional complex numbers (rectangular notation) ----------------------------------------------------- OK ("1/2+3/4i" 0.5+0.75i "0.5+0.75i" ".5+.75i" "500.0e-3+750.0e-3i") -> Mixed fractional/decimal notation complex numbers (rectangular notation) ----------------------------------------------------- OK ("1#/2+3/4i" 5.0+0.75i 7.5+0.75i "5.0+0.75i" "5.+.75i" "7.5+0.75i" "5.0+3/4i" "5.+3/4i" "7.5+3/4i" "5.0+750.0e-3i") OK ("0.5+3/4i" 0.5+0.75i "0.5+0.75i" ".5+.75i" "0.5+3/4i" ".5+3/4i" "500.0e-3+750.0e-3i") OK ("1.5+1#/4i" 1.5+2.5i 1.5+3.75i "1.5+2.5i" "1.5+3.75i") OK ("0.5+1/#i" #f) OK ("0.5+1/1#2i" #f) OK ("1/#+0.5i" #f) OK ("1/1#2+0.5i" #f) -> Mixed notation with infinity (might fail on mixed exactness compnums) ----------------------------------------------------- -> Complex NaN, Inf (rectangular notation) ----------------------------------------------------- OK ("+nan.0+nan.0i" +nan.0+nan.0i "+NaN.0+NaN.0i") OK ("+inf.0+inf.0i" +inf.0+inf.0i "+Inf.0+Inf.0i") OK ("-inf.0+inf.0i" -inf.0+inf.0i "-Inf.0+Inf.0i") OK ("-inf.0-inf.0i" -inf.0-inf.0i "-Inf.0-Inf.0i") OK ("+inf.0-inf.0i" +inf.0-inf.0i "+Inf.0-Inf.0i") -> Complex numbers (polar notation) ----------------------------------------------------- OK ("1@2i" #f) OK ("0.5@1/#" #f) OK ("0.5@1/1#2" #f) OK ("1/#@0.5" #f) OK ("1/1#2@0.5" #f) OK ("1@" #f) OK ("1#@#" #f) OK ("1/@" #f) OK ("@/1" #f) OK ("@1" #f) OK ("1@+" #f) OK ("+@1" #f) OK ("@" #f) -> Base prefixes ----------------------------------------------------- OK ("#x11" 17 "17") OK ("#X11" 17 "17") OK ("#d11" 11 "11") OK ("#D11" 11 "11") OK ("#o11" 9 "9") OK ("#O11" 9 "9") OK ("#b11" 3 "3") OK ("#B11" 3 "3") OK ("#da1" #f) OK ("#o8" #f) OK ("#b2" #f) OK ("#o7" 7 "7") OK ("#xa" 10 "10") OK ("#xA" 10 "10") OK ("#xf" 15 "15") OK ("#xg" #f) OK ("#x-10" -16 "-16") OK ("#d-10" -10 "-10") OK ("#o-10" -8 "-8") OK ("#b-10" -2 "-2") OK ("-#x10" #f) OK ("-#d10" #f) OK ("-#o10" #f) OK ("-#b10" #f) OK ("#x-" #f) OK ("#x" #f) OK ("#d" #f) OK ("#d-" #f) OK ("#d+" #f) OK ("#o" #f) OK ("#o-" #f) OK ("#b" #f) OK ("#b-" #f) OK ("#e" #f) OK ("#e-" #f) OK ("#i" #f) OK ("#i-" #f) -> Combination of prefixes ----------------------------------------------------- OK ("#x#x11" #f) OK ("#x#b11" #f) OK ("#b#o11" #f) OK ("#e#x10" 16 "16") OK ("#i#x10" 16.0 "16.0" "16.") OK ("#e#e10" #f) OK ("#e#e#x10" #f) OK ("#E#e#X10" #f) OK ("#i#e#x10" #f) OK ("#e#x#e10" #f) OK ("#x#x#e10" #f) OK ("#x#e#x10" #f) -> Base prefixes with padding ----------------------------------------------------- OK ("#x1#0" #f) OK ("#d1#0" #f) OK ("#o1#0" #f) OK ("#b1#0" #f) OK ("#x1#" 16.0 24.0 "16.0" "24.0" "16." "24.") OK ("#d1#" 10.0 15.0 "10.0" "15.0" "10." "15.") OK ("#o1#" 8.0 12.0 "8.0" "12.0" "8." "12.") OK ("#b1#" 2.0 3.0 "2.0" "3.0" "2." "3.") -> (Attempted) decimal notation with base prefixes ----------------------------------------------------- OK ("#x1.0" #f) OK ("#d1.0" 1.0 "1.0" "1.") OK ("#o1.0" #f) OK ("#b1.0" #f) OK ("#x1.#" #f) OK ("#d1.#" 1.0 1.5 "1.0" "1.5" "1.") OK ("#o1.#" #f) OK ("#b1.#" #f) OK ("#x1." #f) OK ("#d1." 1.0 "1.0" "1.") OK ("#o1." #f) OK ("#b1." #f) OK ("#x.1" #f) OK ("#d.1" 0.1 "0.1" ".1" "100.0e-3") OK ("#o.1" #f) OK ("#b.1" #f) OK ("#x1e2" 482 "482") OK ("#d1e2" 100.0 "100.0" "100.") OK ("#o1e2" #f) OK ("#b1e2" #f) -> Fractions with prefixes ----------------------------------------------------- OK ("#x10/2" 8 "8") OK ("#x11/2" 17/2 "17/2") OK ("#d11/2" 11/2 "11/2") OK ("#o11/2" 9/2 "9/2") OK ("#b11/10" 3/2 "3/2") OK ("#b11/2" #f) OK ("#x10/#o10" #f) OK ("10/#o10" #f) OK ("#x1#/2" 8.0 12.0 "8.0" "8." "12.0" "12.") OK ("#d1#/2" 5.0 7.5 "5.0" "5." "7.5") OK ("#o1#/2" 4.0 6.0 "4.0" "4." "6.0" "6.") OK ("#b1#/2" #f) OK ("#b1#/10" 1.0 1.5 "1.0" "1." "1.5") -> Complex numbers with prefixes ----------------------------------------------------- OK ("#x1#+1#i" 16.0+16.0i 24.0+24.0i "16.0+16.0i" "16.+16.i" "24.0+24.0i" "24.+24.i") OK ("#x1.0+1.0i" #f) OK ("#d1.0+1.0i" 1.0+1.0i "1.0+1.0i" "1.+1.i") OK ("#o1.0+1.0i" #f) OK ("#b1.0+1.0i" #f) OK ("#x10+#o10i" #f) OK ("10+#o10i" #f) OK ("#x1@#x1" #f) OK ("1@#x1" #f) OK ("#x10+11i" 16.0+17.0i "16.0+17.0i" "16.+17.i") OK ("#d10+11i" 10.0+11.0i "10.0+11.0i" "10.+11.i") OK ("#o10+11i" 8.0+9.0i "8.0+9.0i" "8.+9.i") OK ("#b10+11i" 2.0+3.0i "2.0+3.0i" "2.+3.i") -----> TOTAL ERRORS: 10 Some deprecated features have been used. Set the environment variable GUILE_WARN_DEPRECATED to "detailed" and rerun the program to get more information. Set it to "no" to suppress this message. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 13:54:20 2013 Received: (at 11887) by debbugs.gnu.org; 5 Mar 2013 18:54:20 +0000 Received: from localhost ([127.0.0.1]:32822 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCx0D-0000WS-PY for submit@debbugs.gnu.org; Tue, 05 Mar 2013 13:54:20 -0500 Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:38230 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCx00-0000Ve-DN for 11887@debbugs.gnu.org; Tue, 05 Mar 2013 13:54:04 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id A7F6FBF92; Tue, 5 Mar 2013 13:53:42 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=1q2AF6Hszokx Iv4ZUCW9LrTp8j8=; b=qlHkEMrh7QOxTLykhdgOX8n0VaWjH2Mgk5wBehMJelt2 V2v1WTJP7N9bp2ssrbdDbk8CJGFEYgXbRdIUvgL+4J4KcXjR+BknkBQpRVpk3iL4 +MKMcLIl7lQkeBCpRjfE2IoXF+ZJak5m5/Q137ERePSxfzWE2ImGPCdkAcnBiXY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=P+4vgP Cd7+2gTflIUvLmIlfbmWKUvvZCSdg4inkRi0Ormy3mYpSx8dEZfonGuoDfWa1rUQ A3vbWGNqwTT+at9d2qBzbVUfplsgokM51PAHWbmLREe122VsM8e9xbp1cZnCZl63 5Dj9W1a7wO66PCOIxUxOr1o/rJEHSVul6I5iU= Received: from a-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id A05BBBF91; Tue, 5 Mar 2013 13:53:42 -0500 (EST) Received: from badger (unknown [217.91.84.86]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 22F04BF90; Tue, 5 Mar 2013 13:53:42 -0500 (EST) From: Andy Wingo To: Ian Price Subject: Re: bug#11887: string->number edge cases References: <87sjd1qfs3.fsf@Kagami.home> Date: Tue, 05 Mar 2013 15:49:13 +0100 In-Reply-To: <87sjd1qfs3.fsf@Kagami.home> (Ian Price's message of "Mon, 09 Jul 2012 13:29:16 +0100") Message-ID: <87txopyk9i.fsf@pobox.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: FFE4975E-85C5-11E2-9CD8-59240E5B5709-02397024!a-pb-sasl-quonix.pobox.com X-Spam-Score: 1.8 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi Ian, On Mon 09 Jul 2012 14:29, Ian Price writes: > PARSE ERROR ("+InF.0" +inf.0 "+inf.0" "+Inf.0") => #f > PARSE ERROR ("-iNF.0" -inf.0 "-inf.0" "-Inf.0") => #f > PARSE ERROR ("+NAN.0" +nan.0 "+nan.0" "+NaN.0") => #f [...] Content analysis details: (1.8 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [208.72.237.25 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 1.6 DATE_IN_PAST_03_06 Date: is 3 to 6 hours before Received: date -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% [score: 0.4685] 0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid X-Debbugs-Envelope-To: 11887 Cc: Peter.Bex@xs4all.nl, 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: 1.0 (+) Hi Ian, On Mon 09 Jul 2012 14:29, Ian Price writes: > PARSE ERROR ("+InF.0" +inf.0 "+inf.0" "+Inf.0") =3D> #f > PARSE ERROR ("-iNF.0" -inf.0 "-inf.0" "-Inf.0") =3D> #f > PARSE ERROR ("+NAN.0" +nan.0 "+nan.0" "+NaN.0") =3D> #f These are not errors. +NAN.0 is not even not a number :) > PARSE ERROR ("+nan.1" #f) =3D> +nan.0 > PARSE ERROR ("+nan.01" #f) =3D> +nan.0 These are only supported because 2.0.0 was released with +nan.1 parsing as +nan.0. It signals a deprecation warning with a note to this effect. Guile from master should pass these particular tests. > PARSE ERROR ("nan.0" #f) =3D> +nan.0 > PARSE ERROR ("inf.0" #f) =3D> +inf.0 > PARSE ERROR ("#e+nan.0" #f) =3D> +nan.0 > PARSE ERROR ("#e+inf.0" #f) =3D> +inf.0 > PARSE ERROR ("#e-inf.0" #f) =3D> -inf.0 These are errors. > If the number contains a division by zero, we get a numerical overflow > error. > > scheme@(guile=E2=88=92user)> (string->number "3/0") > ERROR: In procedure string=E2=88=92>number: > ERROR: Throw to key `numerical=E2=88=92overflow' with args `("make=E2=88= =92ratio" "Numerical overflow" #f #f)'. This is also an error. We should plumb through some extra arg to mem2ureal, I guess, to check for a zero denominator. Andy --=20 http://wingolog.org/ From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 14:05:36 2013 Received: (at 11887) by debbugs.gnu.org; 5 Mar 2013 19:05:36 +0000 Received: from localhost ([127.0.0.1]:32891 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCxB9-0000rB-PO for submit@debbugs.gnu.org; Tue, 05 Mar 2013 14:05:36 -0500 Received: from world.peace.net ([96.39.62.75]:49223 ident=hope5) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCxB7-0000r3-11 for 11887@debbugs.gnu.org; Tue, 05 Mar 2013 14:05:34 -0500 Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UCxAe-0003Ev-92; Tue, 05 Mar 2013 14:05:04 -0500 From: Mark H Weaver To: Andy Wingo Subject: Re: bug#11887: string->number edge cases References: <87sjd1qfs3.fsf@Kagami.home> <87txopyk9i.fsf@pobox.com> Date: Tue, 05 Mar 2013 14:04:55 -0500 In-Reply-To: <87txopyk9i.fsf@pobox.com> (Andy Wingo's message of "Tue, 05 Mar 2013 15:49:13 +0100") Message-ID: <878v61ekh4.fsf@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.8 (/) X-Debbugs-Envelope-To: 11887 Cc: Peter.Bex@xs4all.nl, Ian Price , 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Andy Wingo writes: > On Mon 09 Jul 2012 14:29, Ian Price writes: > >> If the number contains a division by zero, we get a numerical overflow >> error. >> >> scheme@(guile=E2=88=92user)> (string->number "3/0") >> ERROR: In procedure string=E2=88=92>number: >> ERROR: Throw to key `numerical=E2=88=92overflow' with args `("make=E2=88= =92ratio" "Numerical overflow" #f #f)'. > > This is also an error. We should plumb through some extra arg to > mem2ureal, I guess, to check for a zero denominator. FYI, I produced a simple patch a while back to fix this (see below), but it had an interesting side effect: it caused the reader to read things like "3/0" and "4+3/0i" as symbols. More generally, anything for which 'scm_string_to_number' returns false is treated as a symbol by 'read'. I'm not sure how I feel about this. What do you think? Mark diff --git a/libguile/numbers.c b/libguile/numbers.c index 66c95db..9013f0c 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -5809,7 +5809,7 @@ mem2ureal (SCM mem, unsigned int *p_idx, return SCM_BOOL_F; =20 divisor =3D mem2uinteger (mem, &idx, radix, &implicit_x); - if (scm_is_false (divisor)) + if (scm_is_false (divisor) || scm_is_eq (divisor, SCM_INUM0)) return SCM_BOOL_F; =20 /* both are int/big here, I assume */ From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 14:22:51 2013 Received: (at 11887) by debbugs.gnu.org; 5 Mar 2013 19:22:51 +0000 Received: from localhost ([127.0.0.1]:32930 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCxRq-0001Gq-Ub for submit@debbugs.gnu.org; Tue, 05 Mar 2013 14:22:51 -0500 Received: from smtp-vbr6.xs4all.nl ([194.109.24.26]:1955) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCxDb-0000ud-TN for 11887@debbugs.gnu.org; Tue, 05 Mar 2013 14:08:09 -0500 Received: from frohike.xs4all.nl (frohike.xs4all.nl [80.101.127.174]) by smtp-vbr6.xs4all.nl (8.13.8/8.13.8) with ESMTP id r25J7deD035963; Tue, 5 Mar 2013 20:07:39 +0100 (CET) (envelope-from Peter.Bex@xs4all.nl) Received: by frohike.xs4all.nl (Postfix, from userid 1000) id 02F24F7E007; Tue, 5 Mar 2013 20:06:34 +0100 (CET) Date: Tue, 5 Mar 2013 20:06:33 +0100 From: Peter Bex To: Andy Wingo Subject: Re: bug#11887: string->number edge cases Message-ID: <20130305190633.GI4379@frohike.xs4all.nl> References: <87sjd1qfs3.fsf@Kagami.home> <87txopyk9i.fsf@pobox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87txopyk9i.fsf@pobox.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: by XS4ALL Virus Scanner X-Spam-Score: 0.2 (/) X-Debbugs-Envelope-To: 11887 X-Mailman-Approved-At: Tue, 05 Mar 2013 14:22:49 -0500 Cc: Ian Price , 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.5 (--) On Tue, Mar 05, 2013 at 03:49:13PM +0100, Andy Wingo wrote: > Hi Ian, > > On Mon 09 Jul 2012 14:29, Ian Price writes: > > > PARSE ERROR ("+InF.0" +inf.0 "+inf.0" "+Inf.0") => #f > > PARSE ERROR ("-iNF.0" -inf.0 "-inf.0" "-Inf.0") => #f > > PARSE ERROR ("+NAN.0" +nan.0 "+nan.0" "+NaN.0") => #f > > These are not errors. +NAN.0 is not even not a number :) I double-checked, but in the upcoming R7RS it is (see 7.1, paragraph 2 of draft 7). It looks like R6RS was case-sensitive in its numerical syntax and +NAN.0 is disallowed by it. Cheers, Peter -- http://www.more-magic.net From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 14:22:51 2013 Received: (at 11887) by debbugs.gnu.org; 5 Mar 2013 19:22:51 +0000 Received: from localhost ([127.0.0.1]:32932 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCxRr-0001Gs-98 for submit@debbugs.gnu.org; Tue, 05 Mar 2013 14:22:51 -0500 Received: from smtp-vbr11.xs4all.nl ([194.109.24.31]:3253) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCxLH-00016J-Ci for 11887@debbugs.gnu.org; Tue, 05 Mar 2013 14:16:05 -0500 Received: from frohike.xs4all.nl (frohike.xs4all.nl [80.101.127.174]) by smtp-vbr11.xs4all.nl (8.13.8/8.13.8) with ESMTP id r25JFVfu017125; Tue, 5 Mar 2013 20:15:31 +0100 (CET) (envelope-from Peter.Bex@xs4all.nl) Received: by frohike.xs4all.nl (Postfix, from userid 1000) id 4F8AAF7E007; Tue, 5 Mar 2013 20:14:26 +0100 (CET) Date: Tue, 5 Mar 2013 20:14:26 +0100 From: Peter Bex To: Mark H Weaver Subject: Re: bug#11887: string->number edge cases Message-ID: <20130305191426.GJ4379@frohike.xs4all.nl> References: <87sjd1qfs3.fsf@Kagami.home> <87txopyk9i.fsf@pobox.com> <878v61ekh4.fsf@tines.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878v61ekh4.fsf@tines.lan> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: by XS4ALL Virus Scanner X-Spam-Score: 0.2 (/) X-Debbugs-Envelope-To: 11887 X-Mailman-Approved-At: Tue, 05 Mar 2013 14:22:49 -0500 Cc: Andy Wingo , Ian Price , 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.5 (--) On Tue, Mar 05, 2013 at 02:04:55PM -0500, Mark H Weaver wrote: > FYI, I produced a simple patch a while back to fix this (see below), but > it had an interesting side effect: it caused the reader to read things > like "3/0" and "4+3/0i" as symbols. More generally, anything for which > 'scm_string_to_number' returns false is treated as a symbol by 'read'. I think this is simple and at least internally consistent. Several Schemes assume something like 1/0 is a symbol; Chicken does this as well, with the numbers egg loaded, so does Gambit. Raising an error is also acceptable. According to the lexical syntax 1/0 *is* a valid number, so you could argue that it *must* parse as a number, which is impossible so an error should occur. This is also related to how string->number deals with it; if it returns #f it is essentially saying "this is not valid numerical syntax" and should fail to parse as a number. Not raising an exception on (string->number "1/0) but raising an exception on (with-input-from-string "1/0" read) is a bit odd, I'd say. Cheers, Peter -- http://www.more-magic.net From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 15:33:50 2013 Received: (at submit) by debbugs.gnu.org; 5 Mar 2013 20:33:50 +0000 Received: from localhost ([127.0.0.1]:33018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCyYX-00042B-5S for submit@debbugs.gnu.org; Tue, 05 Mar 2013 15:33:49 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45598) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UCyYU-00041y-Ak for submit@debbugs.gnu.org; Tue, 05 Mar 2013 15:33:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCyY2-0001Gd-2F for submit@debbugs.gnu.org; Tue, 05 Mar 2013 15:33:19 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-103.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD,USER_IN_WHITELIST autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:50380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCyY2-0001GY-08 for submit@debbugs.gnu.org; Tue, 05 Mar 2013 15:33:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCyY0-0005Bd-UE for bug-guile@gnu.org; Tue, 05 Mar 2013 15:33:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCyY0-0001FR-03 for bug-guile@gnu.org; Tue, 05 Mar 2013 15:33:16 -0500 Received: from zhhdzmsp-smta18.bluewin.ch ([195.186.227.133]:56919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCyXz-0001FC-QH for bug-guile@gnu.org; Tue, 05 Mar 2013 15:33:15 -0500 Received: from [195.186.99.131] ([195.186.99.131:42128] helo=zhbdzmsp-smta13.bluewin.ch) by zhhdzmsp-smta18.bluewin.ch (envelope-from ) (ecelerity 2.2.3.47 r(39824M)) with ESMTP id 5C/D1-12532-88656315; Tue, 05 Mar 2013 20:33:13 +0000 Received: from [10.0.1.10] (83.78.18.51) by zhbdzmsp-smta13.bluewin.ch (8.5.142) (authenticated as dll@bluewin.ch) id 510086220398920D for bug-guile@gnu.org; Tue, 5 Mar 2013 20:33:12 +0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1085) Subject: bug#11887: string->number edge cases From: Daniel Llorens In-Reply-To: Date: Tue, 5 Mar 2013 21:33:11 +0100 Content-Transfer-Encoding: 7bit Message-Id: <2FCE97E1-EAFB-4623-B118-1C9D46C7805B@bluewin.ch> References: To: bug-guile@gnu.org X-Mailer: Apple Mail (2.1085) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) I think this isn't working as it should either. scheme@(guile-user)> +1i $1 = 0.0+1.0i scheme@(guile-user)> 1i ;;; : warning: possibly unbound variable `#{1i}#' ERROR: In procedure #: ERROR: In procedure module-lookup: Unbound variable: #{1i}# From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 06 11:56:18 2013 Received: (at 11887) by debbugs.gnu.org; 6 Mar 2013 16:56:18 +0000 Received: from localhost ([127.0.0.1]:34495 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDHdY-000316-Mp for submit@debbugs.gnu.org; Wed, 06 Mar 2013 11:56:17 -0500 Received: from world.peace.net ([96.39.62.75]:50385 ident=hope3) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDHdV-00030u-9U for 11887@debbugs.gnu.org; Wed, 06 Mar 2013 11:56:15 -0500 Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UDHcw-0006dj-D3; Wed, 06 Mar 2013 11:55:38 -0500 From: Mark H Weaver To: Daniel Llorens Subject: Re: bug#11887: string->number edge cases References: <2FCE97E1-EAFB-4623-B118-1C9D46C7805B@bluewin.ch> Date: Wed, 06 Mar 2013 11:55:30 -0500 In-Reply-To: <2FCE97E1-EAFB-4623-B118-1C9D46C7805B@bluewin.ch> (Daniel Llorens's message of "Tue, 5 Mar 2013 21:33:11 +0100") Message-ID: <876214bh8d.fsf@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.5 (/) X-Debbugs-Envelope-To: 11887 Cc: 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Daniel Llorens writes: > I think this isn't working as it should either. > > scheme@(guile-user)> +1i > $1 = 0.0+1.0i > scheme@(guile-user)> 1i > ;;; : warning: possibly unbound variable `#{1i}#' > ERROR: In procedure #: > ERROR: In procedure module-lookup: Unbound variable: #{1i}# No, this is correct. Scheme requires a sign before an imaginary part. See R5RS section 7.1.1 (Lexical structure). Thanks, Mark --8<---------------cut here---------------start------------->8--- -> | | | The following rules for , , , , , and should be replicated for R = 2, 8, 10, and 16. There are no rules for , , and , which means that numbers containing decimal points or exponents must be in decimal radix. -> -> | @ | + i | - i | + i | - i | + i | - i | + i | - i -> -> | / | -> | . + #* | + . * #* | + #+ . #* -> + #* -> | -> | + -> e | s | f | d | l -> | + | - -> | #i | #e -> #b -> #o -> | #d -> #x -> 0 | 1 -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 -> -> | a | b | c | d | e | f --8<---------------cut here---------------end--------------->8--- From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 06 12:12:35 2013 Received: (at 11887) by debbugs.gnu.org; 6 Mar 2013 17:12:35 +0000 Received: from localhost ([127.0.0.1]:34513 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDHtH-0003Pd-LO for submit@debbugs.gnu.org; Wed, 06 Mar 2013 12:12:35 -0500 Received: from zhbdzmsp-smta17.bluewin.ch ([195.186.99.133]:52599) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDHtB-0003PL-PF for 11887@debbugs.gnu.org; Wed, 06 Mar 2013 12:12:30 -0500 Received: from [195.186.227.130] ([195.186.227.130:56256] helo=zhhdzmsp-smta12.bluewin.ch) by zhbdzmsp-smta17.bluewin.ch (envelope-from ) (ecelerity 2.2.3.47 r(39824M)) with ESMTP id E3/C4-20489-8D877315; Wed, 06 Mar 2013 17:11:52 +0000 Received: from [172.16.96.17] (62.2.203.131) by zhhdzmsp-smta12.bluewin.ch (8.5.142) (authenticated as dll@bluewin.ch) id 510085B003876A9C; Wed, 6 Mar 2013 17:11:52 +0000 Subject: Re: bug#11887: string->number edge cases Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: text/plain; charset=us-ascii From: Daniel Llorens In-Reply-To: <876214bh8d.fsf@tines.lan> Date: Wed, 6 Mar 2013 18:11:51 +0100 Content-Transfer-Encoding: 7bit Message-Id: References: <2FCE97E1-EAFB-4623-B118-1C9D46C7805B@bluewin.ch> <876214bh8d.fsf@tines.lan> To: Mark H Weaver X-Mailer: Apple Mail (2.1085) X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 11887 Cc: 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.2 (---) On Mar 6, 2013, at 17:55, Mark H Weaver wrote: > Daniel Llorens writes: > >> I think this isn't working as it should either. >> >> scheme@(guile-user)> +1i >> $1 = 0.0+1.0i >> scheme@(guile-user)> 1i >> ;;; : warning: possibly unbound variable `#{1i}#' >> ERROR: In procedure #: >> ERROR: In procedure module-lookup: Unbound variable: #{1i}# > No, this is correct. Scheme requires a sign before an imaginary part. > See R5RS section 7.1.1 (Lexical structure). Thanks. R5RS is wrong then. A shame. From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 06 13:12:21 2013 Received: (at 11887) by debbugs.gnu.org; 6 Mar 2013 18:12:21 +0000 Received: from localhost ([127.0.0.1]:34631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDIp8-0004vx-Ne for submit@debbugs.gnu.org; Wed, 06 Mar 2013 13:12:21 -0500 Received: from world.peace.net ([96.39.62.75]:50492 ident=hope9) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDIp1-0004vk-MG for 11887@debbugs.gnu.org; Wed, 06 Mar 2013 13:12:17 -0500 Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UDIoT-0006vq-CD; Wed, 06 Mar 2013 13:11:37 -0500 From: Mark H Weaver To: Peter Bex Subject: Re: bug#11887: string->number edge cases References: <87sjd1qfs3.fsf@Kagami.home> <87txopyk9i.fsf@pobox.com> <878v61ekh4.fsf@tines.lan> <20130305191426.GJ4379@frohike.xs4all.nl> Date: Wed, 06 Mar 2013 13:11:26 -0500 In-Reply-To: <20130305191426.GJ4379@frohike.xs4all.nl> (Peter Bex's message of "Tue, 5 Mar 2013 20:14:26 +0100") Message-ID: <87vc949z5d.fsf@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11887 Cc: Andy Wingo , Ian Price , 11887@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Hi Peter, Peter Bex writes: > On Tue, Mar 05, 2013 at 02:04:55PM -0500, Mark H Weaver wrote: >> FYI, I produced a simple patch a while back to fix this (see below), but >> it had an interesting side effect: it caused the reader to read things >> like "3/0" and "4+3/0i" as symbols. More generally, anything for which >> 'scm_string_to_number' returns false is treated as a symbol by 'read'. > > I think this is simple and at least internally consistent. Several > Schemes assume something like 1/0 is a symbol; Chicken does this as > well, with the numbers egg loaded, so does Gambit. [...] > This is also related to how string->number deals with it; if it > returns #f it is essentially saying "this is not valid numerical syntax" > and should fail to parse as a number. Not raising an exception on > (string->number "1/0) but raising an exception on > (with-input-from-string "1/0" read) is a bit odd, I'd say. Thanks, this makes me feel somewhat better about it. I guess it's okay. > On Tue, Mar 05, 2013 at 03:49:13PM +0100, Andy Wingo wrote: > > Hi Ian, > > > > On Mon 09 Jul 2012 14:29, Ian Price writes: > > > > > PARSE ERROR ("+InF.0" +inf.0 "+inf.0" "+Inf.0") => #f > > > PARSE ERROR ("-iNF.0" -inf.0 "-inf.0" "-Inf.0") => #f > > > PARSE ERROR ("+NAN.0" +nan.0 "+nan.0" "+NaN.0") => #f > > > > These are not errors. +NAN.0 is not even not a number :) > > I double-checked, but in the upcoming R7RS it is (see 7.1, paragraph 2 of > draft 7). It looks like R6RS was case-sensitive in its numerical syntax > and +NAN.0 is disallowed by it. Thanks for looking this up. Given that it's allowed by the latest R7RS draft, I think we should allow these too. I've written a patch to fix these issues, and will send it in my next email. Regards, Mark From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 06 13:16:33 2013 Received: (at 11887) by debbugs.gnu.org; 6 Mar 2013 18:16:33 +0000 Received: from localhost ([127.0.0.1]:34637 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDItE-00052a-Ly for submit@debbugs.gnu.org; Wed, 06 Mar 2013 13:16:33 -0500 Received: from world.peace.net ([96.39.62.75]:50506 ident=hope2) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDIt8-00052K-CD for 11887@debbugs.gnu.org; Wed, 06 Mar 2013 13:16:31 -0500 Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UDIsX-0006xr-G8; Wed, 06 Mar 2013 13:15:49 -0500 From: Mark H Weaver To: 11887@debbugs.gnu.org Subject: [PATCH] Improve standards conformance of string->number (was Re: bug#11887: string->number edge cases) References: <87sjd1qfs3.fsf@Kagami.home> <87txopyk9i.fsf@pobox.com> <878v61ekh4.fsf@tines.lan> <20130305191426.GJ4379@frohike.xs4all.nl> Date: Wed, 06 Mar 2013 13:15:42 -0500 In-Reply-To: <20130305191426.GJ4379@frohike.xs4all.nl> (Peter Bex's message of "Tue, 5 Mar 2013 20:14:26 +0100") Message-ID: <87obew9yy9.fsf_-_@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11887 Cc: Andy Wingo , Ian Price X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) --=-=-= Content-Type: text/plain Here's a patch to fix these problems. Comments and suggestions welcome. Mark --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Improve-standards-conformance-of-string-number.patch Content-Description: [PATCH] Improve standards conformance of string->number >From a1926777b03445d397bb1069b325d243e765f84b Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 6 Mar 2013 12:52:39 -0500 Subject: [PATCH] Improve standards conformance of string->number. Fixes . * libguile/numbers.c (mem2ureal): New argument 'allow_inf_or_nan'. Accept infinities and NaNs only if 'allow_inf_or_nan' is true and "#e" is not present. Check for "inf.0" or "nan." case-insensitively. Do not accept rationals with zero divisors. (mem2complex): Pass new 'allow_inf_or_nan' argument to 'mem2ureal', which is set if and only if a explicit sign was present. * test-suite/tests/numbers.test ("string->number"): Add tests. --- libguile/numbers.c | 76 +++++++++++++++++++++++++++-------------- test-suite/tests/numbers.test | 12 ++++++- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/libguile/numbers.c b/libguile/numbers.c index 66c95db..f9538f5 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -5740,7 +5740,8 @@ mem2decimal_from_point (SCM result, SCM mem, static SCM mem2ureal (SCM mem, unsigned int *p_idx, - unsigned int radix, enum t_exactness forced_x) + unsigned int radix, enum t_exactness forced_x, + int allow_inf_or_nan) { unsigned int idx = *p_idx; SCM result; @@ -5753,30 +5754,53 @@ mem2ureal (SCM mem, unsigned int *p_idx, if (idx == len) return SCM_BOOL_F; - if (idx+5 <= len && !scm_i_string_strcmp (mem, idx, "inf.0")) - { - *p_idx = idx+5; - return scm_inf (); - } - - if (idx+4 < len && !scm_i_string_strcmp (mem, idx, "nan.")) - { - /* Cobble up the fractional part. We might want to set the - NaN's mantissa from it. */ - idx += 4; - if (!scm_is_eq (mem2uinteger (mem, &idx, 10, &implicit_x), SCM_INUM0)) - { + if (allow_inf_or_nan && forced_x != EXACT && idx+5 <= len) + switch (scm_i_string_ref (mem, idx)) + { + case 'i': case 'I': + switch (scm_i_string_ref (mem, idx + 1)) + { + case 'n': case 'N': + switch (scm_i_string_ref (mem, idx + 2)) + { + case 'f': case 'F': + if (scm_i_string_ref (mem, idx + 3) == '.' + && scm_i_string_ref (mem, idx + 4) == '0') + { + *p_idx = idx+5; + return scm_inf (); + } + } + } + case 'n': case 'N': + switch (scm_i_string_ref (mem, idx + 1)) + { + case 'a': case 'A': + switch (scm_i_string_ref (mem, idx + 2)) + { + case 'n': case 'N': + if (scm_i_string_ref (mem, idx + 3) == '.') + { + /* Cobble up the fractional part. We might want to + set the NaN's mantissa from it. */ + idx += 4; + if (!scm_is_eq (mem2uinteger (mem, &idx, 10, &implicit_x), + SCM_INUM0)) + { #if SCM_ENABLE_DEPRECATED == 1 - scm_c_issue_deprecation_warning - ("Non-zero suffixes to `+nan.' are deprecated. Use `+nan.0'."); + scm_c_issue_deprecation_warning + ("Non-zero suffixes to `+nan.' are deprecated. Use `+nan.0'."); #else - return SCM_BOOL_F; + return SCM_BOOL_F; #endif - } + } - *p_idx = idx; - return scm_nan (); - } + *p_idx = idx; + return scm_nan (); + } + } + } + } if (scm_i_string_ref (mem, idx) == '.') { @@ -5809,7 +5833,7 @@ mem2ureal (SCM mem, unsigned int *p_idx, return SCM_BOOL_F; divisor = mem2uinteger (mem, &idx, radix, &implicit_x); - if (scm_is_false (divisor)) + if (scm_is_false (divisor) || scm_is_eq (divisor, SCM_INUM0)) return SCM_BOOL_F; /* both are int/big here, I assume */ @@ -5885,7 +5909,7 @@ mem2complex (SCM mem, unsigned int idx, if (idx == len) return SCM_BOOL_F; - ureal = mem2ureal (mem, &idx, radix, forced_x); + ureal = mem2ureal (mem, &idx, radix, forced_x, sign != 0); if (scm_is_false (ureal)) { /* input must be either +i or -i */ @@ -5954,9 +5978,9 @@ mem2complex (SCM mem, unsigned int idx, sign = -1; } else - sign = 1; + sign = 0; - angle = mem2ureal (mem, &idx, radix, forced_x); + angle = mem2ureal (mem, &idx, radix, forced_x, sign != 0); if (scm_is_false (angle)) return SCM_BOOL_F; if (idx != len) @@ -5978,7 +6002,7 @@ mem2complex (SCM mem, unsigned int idx, else { int sign = (c == '+') ? 1 : -1; - SCM imag = mem2ureal (mem, &idx, radix, forced_x); + SCM imag = mem2ureal (mem, &idx, radix, forced_x, sign != 0); if (scm_is_false (imag)) imag = SCM_I_MAKINUM (sign); diff --git a/test-suite/tests/numbers.test b/test-suite/tests/numbers.test index 66aa01a..be378b7 100644 --- a/test-suite/tests/numbers.test +++ b/test-suite/tests/numbers.test @@ -1493,7 +1493,9 @@ "#o.2" "3.4q" "15.16e17q" "18.19e+q" ".q" ".17#18" "10q" "#b2" "#b3" "#b4" "#b5" "#b6" "#b7" "#b8" "#b9" "#ba" "#bb" "#bc" "#bd" "#be" "#bf" "#q" "#b#b1" "#o#o1" "#d#d1" "#x#x1" "#e#e1" - "#i#i1" "12@12+0i")) + "#i#i1" "12@12+0i" "3/0" "0/0" "4+3/0i" "4/0-3i" "2+0/0i" + "nan.0" "inf.0" "#e+nan.0" "#e+inf.0" "#e-inf.0" + "3@inf.0" "4@nan.0")) #t) (pass-if "valid number strings" @@ -1532,6 +1534,14 @@ ("1/1" 1) ("1/2" 1/2) ("-1/2" -1/2) ("1#/1" 10.0) ("10/1#" 1.0) ("1#/1#" 1.0) ("#e9/10" 9/10) ("#e10/1#" 1) ("#i6/8" 0.75) ("#i1/1" 1.0) + ;; Infinities and NaNs: + ("+inf.0" ,(inf)) ("-inf.0" ,(- (inf))) + ("+Inf.0" ,(inf)) ("-Inf.0" ,(- (inf))) + ("+InF.0" ,(inf)) ("-InF.0" ,(- (inf))) + ("+INF.0" ,(inf)) ("-INF.0" ,(- (inf))) + ("#i+InF.0" ,(inf)) ("#i-InF.0" ,(- (inf))) + ("+nan.0" ,(nan)) ("-nan.0" ,(nan)) + ("#i+nan.0" ,(nan)) ("#i-nan.0" ,(nan)) ;; Decimal numbers: ;; * ("1e2" 100.0) ("1E2" 100.0) ("1s2" 100.0) ("1S2" 100.0) -- 1.7.10.4 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 07 15:48:07 2013 Received: (at 11887-done) by debbugs.gnu.org; 7 Mar 2013 20:48:07 +0000 Received: from localhost ([127.0.0.1]:37100 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDhjS-0002ME-QX for submit@debbugs.gnu.org; Thu, 07 Mar 2013 15:48:06 -0500 Received: from world.peace.net ([96.39.62.75]:52004 ident=hope9) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDhjP-0002M4-SF for 11887-done@debbugs.gnu.org; Thu, 07 Mar 2013 15:48:04 -0500 Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UDhim-0003Yf-B1; Thu, 07 Mar 2013 15:47:24 -0500 From: Mark H Weaver To: 11887-done@debbugs.gnu.org Subject: Re: bug#11887: [PATCH] Improve standards conformance of string->number (was Re: bug#11887: string->number edge cases) References: <87sjd1qfs3.fsf@Kagami.home> <87txopyk9i.fsf@pobox.com> <878v61ekh4.fsf@tines.lan> <20130305191426.GJ4379@frohike.xs4all.nl> <87obew9yy9.fsf_-_@tines.lan> Date: Thu, 07 Mar 2013 15:47:17 -0500 In-Reply-To: <87obew9yy9.fsf_-_@tines.lan> (Mark H. Weaver's message of "Wed, 06 Mar 2013 13:15:42 -0500") Message-ID: <87zjyf544q.fsf@tines.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.8 (/) X-Debbugs-Envelope-To: 11887-done Cc: Ian Price X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) I wrote: > Here's a patch to fix these problems. Comments and suggestions welcome. I went ahead and pushed this to stable-2.0. I'm closing this bug. Thanks, Mark From unknown Tue Sep 09 11:59:51 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 05 Apr 2013 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator