[gambit-list] Different results in interpreted and compiled code
Andrew Lentvorski
bsder at allcaps.org
Fri Dec 2 22:01:42 EST 2011
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
More information about the Gambit-list
mailing list