unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Andy Wingo <wingo@pobox.com>
Cc: Ian Price <ianprice90@googlemail.com>,
	Peter.Bex@xs4all.nl, 11887@debbugs.gnu.org
Subject: bug#11887: string->number edge cases
Date: Tue, 05 Mar 2013 14:04:55 -0500	[thread overview]
Message-ID: <878v61ekh4.fsf@tines.lan> (raw)
In-Reply-To: <87txopyk9i.fsf@pobox.com> (Andy Wingo's message of "Tue, 05 Mar 2013 15:49:13 +0100")

Andy Wingo <wingo@pobox.com> writes:

> On Mon 09 Jul 2012 14:29, Ian Price <ianprice90@googlemail.com> writes:
>
>> 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)'.
>
> 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;
 
 	  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 */





  reply	other threads:[~2013-03-05 19:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-09 12:29 bug#11887: string->number edge cases Ian Price
2013-03-05 14:49 ` Andy Wingo
2013-03-05 19:04   ` Mark H Weaver [this message]
2013-03-05 19:14     ` Peter Bex
2013-03-06 18:11       ` Mark H Weaver
2013-03-06 18:15       ` bug#11887: [PATCH] Improve standards conformance of string->number (was Re: bug#11887: string->number edge cases) Mark H Weaver
2013-03-07 20:47         ` Mark H Weaver
2013-03-05 19:06   ` bug#11887: string->number edge cases Peter Bex
     [not found] <mailman.1167569.1362509701.854.bug-guile@gnu.org>
2013-03-05 20:33 ` Daniel Llorens
2013-03-06 16:55   ` Mark H Weaver
2013-03-06 17:11     ` Daniel Llorens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878v61ekh4.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=11887@debbugs.gnu.org \
    --cc=Peter.Bex@xs4all.nl \
    --cc=ianprice90@googlemail.com \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).