GNU bug report logs -
#11887
string->number edge cases
Previous Next
Full log
Message #11 received at 11887 <at> debbugs.gnu.org (full text, mbox):
Andy Wingo <wingo <at> pobox.com> writes:
> On Mon 09 Jul 2012 14:29, Ian Price <ianprice90 <at> 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 */
This bug report was last modified 12 years and 160 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.