And I don't understand why it occurs in this case (and I don't particularly like it, either).
Here's the code
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% cat nan-test.scm (declare (standard-bindings) (extended-bindings) (block) ;; (not safe) (not constant-fold))
(define infinity (fl/ 1.0 0.0)) (define nan1 (fl- infinity infinity)) (define nan2 (fl/ 0. 0.)) (pp (eqv? nan1 nan2))
And here's the compile command, and the run commands:
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% gsc -keep-c -expansion nan-test.scm Expansion:
(define infinity (if (and ('#<procedure #2 ##flonum?> 0.) ('#<procedure #2 ##flonum?> 1.)) ('#<procedure #3 ##fl/> 1. 0.) ('#<procedure #4 fl/> 1. 0.)))
(define nan1 (if (and ('#<procedure #2 ##flonum?> infinity) ('#<procedure #2 ##flonum?> infinity)) ('#<procedure #5 ##fl-> infinity infinity) ('#<procedure #6 fl-> infinity infinity)))
(define nan2 (if (and ('#<procedure #2 ##flonum?> 0.) ('#<procedure #2 ##flonum?> 0.)) ('#<procedure #3 ##fl/> 0. 0.) ('#<procedure #4 fl/> 0. 0.)))
(pp (or ('#<procedure #7 ##eq?> nan1 nan2) (and ('#<procedure #8 ##subtyped?> nan1) (and ('#<procedure #8 ##subtyped?> nan2) (and ('#<procedure #9 ##fx=> ('#<procedure #10 ##subtype> nan1) ('#<procedure #10 ##subtype> nan2)) ('#<procedure #11 eqv?> nan1 nan2))))))
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% gsi nan-test #f [Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% gsi nan-test.scm #t
Afficher les réponses par date
On 12/2/11 4:59 PM, Bradley Lucier wrote:
And I don't understand why it occurs in this case (and I don't particularly like it, either).
Here's the code
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% cat nan-test.scm (declare (standard-bindings) (extended-bindings) (block) ;; (not safe) (not constant-fold))
(define infinity (fl/ 1.0 0.0)) (define nan1 (fl- infinity infinity)) (define nan2 (fl/ 0. 0.)) (pp (eqv? nan1 nan2))
And here's the compile command, and the run commands:
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% gsc -keep-c -expansion nan-test.scm Expansion:
(define infinity (if (and ('#<procedure #2 ##flonum?> 0.) ('#<procedure #2 ##flonum?> 1.)) ('#<procedure #3 ##fl/> 1. 0.) ('#<procedure #4 fl/> 1. 0.)))
(define nan1 (if (and ('#<procedure #2 ##flonum?> infinity) ('#<procedure #2 ##flonum?> infinity)) ('#<procedure #5 ##fl-> infinity infinity) ('#<procedure #6 fl-> infinity infinity)))
(define nan2 (if (and ('#<procedure #2 ##flonum?> 0.) ('#<procedure #2 ##flonum?> 0.)) ('#<procedure #3 ##fl/> 0. 0.) ('#<procedure #4 fl/> 0. 0.)))
(pp (or ('#<procedure #7 ##eq?> nan1 nan2) (and ('#<procedure #8 ##subtyped?> nan1) (and ('#<procedure #8 ##subtyped?> nan2) (and ('#<procedure #9 ##fx=> ('#<procedure #10 ##subtype> nan1) ('#<procedure #10 ##subtype> nan2)) ('#<procedure #11 eqv?> nan1 nan2))))))
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% gsi nan-test #f [Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% gsi nan-test.scm #t
I suspect that: ('#<procedure #7 ##eq?> nan1 nan2) ('#<procedure #11 eqv?> nan1 nan2)
are not actually sufficiently mutually exclusive and make the whole expression sensitive to order of evaluation.
I think that expansion is wrong. IIRC, IEEE754 specifies that NaNs are unordered. Consequently, I think that both (nan1 == nan2) and (nan1 != nan2) must return false.
-a
On Fri, 2011-12-02 at 19:01 -0800, Andrew Lentvorski wrote:
I think that expansion is wrong. IIRC, IEEE754 specifies that NaNs are unordered. Consequently, I think that both (nan1 == nan2) and (nan1 != nan2) must return false.
That's true in C, and in Gambit
(= nan1 nan2) => #f
because it conforms to IEEE floating-point equality.
But eqv? compares floating-point numbers bitwise in Gambit, and I agree with that behavior.
Brad
Here's a more refined test:
heine:~/Desktop> cat nan-test.scm (declare (standard-bindings) (extended-bindings) (block) (not safe) (not constant-fold))
(define infinity (fl/ 1.0 0.0)) (define nan1 (fl- infinity infinity)) (define nan2 (fl/ 0. 0.)) (pp (list (##flonum.->inexact-exponential-format nan1) (##flonum.->inexact-exponential-format nan2))) (pp (list (##subtyped? nan1) (##subtyped? nan2) (fx= (##subtype nan1) (##subtype nan2)) (let () (declare (not inline-primitives)) (eqv? nan1 nan2)))) (pp (eqv? nan1 nan2)) heine:~/Desktop> gsc -expansion nan-test Expansion:
(define infinity ('#<procedure #2 ##fl/> 1. 0.))
(define nan1 ('#<procedure #3 ##fl-> infinity infinity))
(define nan2 ('#<procedure #2 ##fl/> 0. 0.))
(pp ('#<procedure #4 ##list> (##flonum.->inexact-exponential-format nan1) (##flonum.->inexact-exponential-format nan2)))
(pp ('#<procedure #4 ##list> ('#<procedure #5 ##subtyped?> nan1) ('#<procedure #5 ##subtyped?> nan2) ('#<procedure #6 ##fx=> ('#<procedure #7 ##subtype> nan1) ('#<procedure #7 ##subtype> nan2)) ('#<procedure #8 eqv?> nan1 nan2)))
(pp (or ('#<procedure #9 ##eq?> nan1 nan2) (and ('#<procedure #5 ##subtyped?> nan1) (and ('#<procedure #5 ##subtyped?> nan2) (and ('#<procedure #6 ##fx=> ('#<procedure #7 ##subtype> nan1) ('#<procedure #7 ##subtype> nan2)) ('#<procedure #8 eqv?> nan1 nan2)))))) heine:~/Desktop> gsi nan-test (#(+nan.0 1023 -1) #(+nan.0 1023 1)) (#t #t #t #f) #f heine:~/Desktop> gsi nan-test.scm (#(+nan.0 1023 -1) #(+nan.0 1023 -1)) (#t #t #t #t) #t
I have no idea what's going on.
Brad
heine:~/Desktop> uname -a Linux heine 3.0.0-13-generic #22-Ubuntu SMP Wed Nov 2 13:27:26 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux heine:~/Desktop> gsi -v v4.6.2 20110519175028 x86_64-unknown-linux-gnu "./configure /usr/local/Gambit-C/share/config.site /usr/local/Gambit-C/etc/config.site"
Marc:
I filed a gcc bug report, you can follow what happens at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51446
if you like.
Brad