guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Numerical comparisons and NaNs


From: Mark H Weaver
Subject: Numerical comparisons and NaNs
Date: Sun, 11 Aug 2013 16:24:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

> commit af95414f1dcbacf7fd5311a3ee89a799b20fd17b
> Author: Andy Wingo <address@hidden>
> Date:   Sun Aug 11 16:42:06 2013 +0200
>
>     Various RTL VM and calling convention tweaks
>     
>     * libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Allow for
>       five-word instructions, and for new instruction word types.
>     
>     * libguile/vm-engine.c (RETURN_ONE_VALUE): Instead of returning the
>       value in the fixed part of the call frame, return it in the same place
>       multiple-value returns go: from slot 1.
>       (BR_ARITHMETIC): Allow arithmetic tests to be negated.
[...]
>       (br-if-=, br-if-<, br-if-<=): Allow these instructions to be
>       negatable.
>       (br-if->, br-if->=): Remove.  Probably a bad idea, given NaN.

It's okay to remove those instructions, but inverting the boolean result
is not the right way.  The right way is to swap the arguments.

In other words, you want this:

   (define (>  x y) (<  y x))
   (define (>= x y) (<= y x))

not this:

   (define (>  x y) (not (<= x y)))   ; INCORRECT
   (define (>= x y) (not (<  x y)))   ; INCORRECT

The reason is because of NaN handling, as you suspected.  The
comparisons (< <= > >=) must return #f when either argument is a NaN.
This property is preserved by swapping arguments, but not by inverting
the result.

      Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]