From cc55df1cd94966a7726b122ef9530fdf9e436d32 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Tue, 7 Oct 1997 04:19:46 +0000 Subject: [PATCH] Fixed so that "1/pivot" is rejected as a number, rather than dividing by zero. Change: divide only if there is at least one denominator digit. This is not a good fix, but I need it now for some existing code. The parser ought to be restructured not to compute the real part until it is known that the imaginary part is valid, e.g. (string->number "1/2+3") => #F (string->number "1/0+3") => error (string->number "1/0-transition") => error There is a similar problem with exponent calculation: (string->number "1e9999e1") => error (string->number "1e99999999e1") => `hangs' in bignum primitives Of course, the difficulty with these non-numbers is probably the reason behind R4RS's restriction on valid identifiers. That is pretty feeble, since I don't recall R4RS saying that STRING->NUMBER is allowed to signal an error. Note that the current code would work fine in a lazy language, so a few DELAYs and FORCEs might be the most elegant fix (and OK effciency since FORCE is now compiled.) --- v7/src/runtime/numpar.scm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/v7/src/runtime/numpar.scm b/v7/src/runtime/numpar.scm index f2f7d5d85..64d065ba5 100644 --- a/v7/src/runtime/numpar.scm +++ b/v7/src/runtime/numpar.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: numpar.scm,v 14.14 1997/07/20 06:38:55 cph Exp $ +$Id: numpar.scm,v 14.15 1997/10/07 04:19:46 adams Exp $ Copyright (c) 1989-97 Massachusetts Institute of Technology @@ -137,9 +137,8 @@ MIT in each case. |# (let ((char (string-ref string start)) (start+1 (fix:+ start 1))) (cond ((char=? #\/ char) - (and (fix:< start+1 end) - (parse-denominator-1 string start+1 end - integer exactness radix sign))) + (parse-denominator-1 string start+1 end + integer exactness radix sign)) ((char=? #\. char) (and (fix:= radix 10) (if sharp? @@ -185,11 +184,12 @@ MIT in each case. |# (lambda (denominator exactness sign) (finish-rational numerator denominator exactness sign)))) (parse-digits string start end 0 exactness radix - (lambda (start integer exactness sharp?) + (lambda (start* integer exactness sharp?) sharp? - (parse-complex string start end - (finish integer exactness sign) - exactness radix sign))))) + (and (> start* start) ; >0 denominator digits + (parse-complex string start end + (finish integer exactness sign) + exactness radix sign)))))) (define (parse-decimal-1 string start end exactness sign) ;; State: radix is 10, leading dot seen. -- 2.25.1