* how to detect division by zero?
@ 2004-01-20 14:17 Rouben Rostamian
2004-01-20 15:40 ` Roland Orre
2004-02-13 9:04 ` Bernard Urban
0 siblings, 2 replies; 7+ messages in thread
From: Rouben Rostamian @ 2004-01-20 14:17 UTC (permalink / raw)
Hello Guile users!
How does one detect the result of a division by 0.0 in guile?
In guile 1.6.4 we have:
guile> (/ 1 0.)
+#.#
The usual tests are not informative:
guile> (number? (/ 1 0.))
#t
guile> (positive? (/ 1 0.))
#t
--
Rouben Rostamian
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to detect division by zero?
2004-01-20 14:17 how to detect division by zero? Rouben Rostamian
@ 2004-01-20 15:40 ` Roland Orre
2004-01-20 16:02 ` John W. Eaton
2004-01-20 22:07 ` Marius Vollmer
2004-02-13 9:04 ` Bernard Urban
1 sibling, 2 replies; 7+ messages in thread
From: Roland Orre @ 2004-01-20 15:40 UTC (permalink / raw)
Cc: guile-user
On Tue, 2004-01-20 at 15:17, Rouben Rostamian wrote:
> How does one detect the result of a division by 0.0 in guile?
You could define the values of the not_a_numbers and test with those.
In guile 1.7 symbols for these values are already predefined, so you
could use the following definitions to be future compatible. However,
I just found that (/ 0.0 0.0) can not be tested neither in 1.6 or 1.7.
(define +inf.0 (/ 1.0 0.0))
(define -inf.0 (/ -1.0 0.0))
(define +nan.0 (/ 0.0 0.0))
guile-user> (= +inf.0 (/ 100.0 0.0))
#t
guile-user> (= -inf.0 (/ -100.0 0.0))
#t
Of some reason does the followoing return false
guile-user> (= +nan.0 (/ 0.0 0.0))
/Roland
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to detect division by zero?
2004-01-20 15:40 ` Roland Orre
@ 2004-01-20 16:02 ` John W. Eaton
2004-01-20 16:16 ` Paul Jarc
2004-01-20 16:29 ` Roland Orre
2004-01-20 22:07 ` Marius Vollmer
1 sibling, 2 replies; 7+ messages in thread
From: John W. Eaton @ 2004-01-20 16:02 UTC (permalink / raw)
Cc: guile-user
On 20-Jan-2004, Roland Orre <orre@nada.kth.se> wrote:
| On Tue, 2004-01-20 at 15:17, Rouben Rostamian wrote:
| > How does one detect the result of a division by 0.0 in guile?
|
| You could define the values of the not_a_numbers and test with those.
| In guile 1.7 symbols for these values are already predefined, so you
| could use the following definitions to be future compatible. However,
| I just found that (/ 0.0 0.0) can not be tested neither in 1.6 or 1.7.
|
| (define +inf.0 (/ 1.0 0.0))
| (define -inf.0 (/ -1.0 0.0))
| (define +nan.0 (/ 0.0 0.0))
|
| guile-user> (= +inf.0 (/ 100.0 0.0))
| #t
| guile-user> (= -inf.0 (/ -100.0 0.0))
| #t
|
| Of some reason does the followoing return false
| guile-user> (= +nan.0 (/ 0.0 0.0))
NaN values never compare equal. To check for them, you need isnan. I
helped to write a patch for this some time ago. Doesn't guile 1.7 (or
some newer than 1.6 version) have isinf, isnan, and other IEEE
floating point functions and values built in?
jwe
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to detect division by zero?
2004-01-20 16:02 ` John W. Eaton
@ 2004-01-20 16:16 ` Paul Jarc
2004-01-20 16:29 ` Roland Orre
1 sibling, 0 replies; 7+ messages in thread
From: Paul Jarc @ 2004-01-20 16:16 UTC (permalink / raw)
Cc: guile-user, Roland Orre
"John W. Eaton" <jwe@bevo.che.wisc.edu> wrote:
> NaN values never compare equal. To check for them, you need isnan.
Does this work?
(define (nan? x) (not (= x x)))
paul
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to detect division by zero?
2004-01-20 16:02 ` John W. Eaton
2004-01-20 16:16 ` Paul Jarc
@ 2004-01-20 16:29 ` Roland Orre
1 sibling, 0 replies; 7+ messages in thread
From: Roland Orre @ 2004-01-20 16:29 UTC (permalink / raw)
Cc: guile-user
On Tue, 2004-01-20 at 17:02, John W. Eaton wrote:
> On 20-Jan-2004, Roland Orre <orre@nada.kth.se> wrote:
> NaN values never compare equal. To check for them, you need isnan. I
> helped to write a patch for this some time ago. Doesn't guile 1.7 (or
> some newer than 1.6 version) have isinf, isnan, and other IEEE
> floating point functions and values built in?
Yes, you are right. I had missed that. There are e.g. nan? and inf?
/Roland
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to detect division by zero?
2004-01-20 15:40 ` Roland Orre
2004-01-20 16:02 ` John W. Eaton
@ 2004-01-20 22:07 ` Marius Vollmer
1 sibling, 0 replies; 7+ messages in thread
From: Marius Vollmer @ 2004-01-20 22:07 UTC (permalink / raw)
Cc: guile-user
Roland Orre <orre@nada.kth.se> writes:
> Of some reason does the followoing return false
> guile-user> (= +nan.0 (/ 0.0 0.0))
In addition to nan? you can also use 'eqv?' for comparison:
guile> (eqv? +nan.0 (/ 0.0 0.0))
#t
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to detect division by zero?
2004-01-20 14:17 how to detect division by zero? Rouben Rostamian
2004-01-20 15:40 ` Roland Orre
@ 2004-02-13 9:04 ` Bernard Urban
1 sibling, 0 replies; 7+ messages in thread
From: Bernard Urban @ 2004-02-13 9:04 UTC (permalink / raw)
Cc: guile-user
"Rouben Rostamian" <rostamian@umbc.edu> writes:
> Hello Guile users!
>
> How does one detect the result of a division by 0.0 in guile?
>
> In guile 1.6.4 we have:
>
> guile> (/ 1 0.)
> +#.#
>
> The usual tests are not informative:
>
> guile> (number? (/ 1 0.))
> #t
>
> guile> (positive? (/ 1 0.))
> #t
>
I read recently on this list that
there is some explicit test available for infinity or nan in 1.7.
I take the opportunity to pinpoint a bug in 1.6.4:
guile
guile> (version)
"1.6.4"
guile> (/ 0)
+#.#
guile> (/ 1 0)
standard input:3:1: In procedure / in expression (/ 1 0):
standard input:3:1: Numerical overflow
ABORT: (numerical-overflow)
Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
guile>
In one case, the code in numbers.c for scm_divide computes the hardware
generated positive infinity, in the other an explicit call to
scm_num_overflow is made after testing the divisor value.
--
Bernard Urban
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-02-13 9:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-20 14:17 how to detect division by zero? Rouben Rostamian
2004-01-20 15:40 ` Roland Orre
2004-01-20 16:02 ` John W. Eaton
2004-01-20 16:16 ` Paul Jarc
2004-01-20 16:29 ` Roland Orre
2004-01-20 22:07 ` Marius Vollmer
2004-02-13 9:04 ` Bernard Urban
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).