abs

ABS for -0.0

First, it seems Common Lisp does not require support for -0.0. Support for IEEE 754 is not mandatory to begin with, and in the past, choices in this area were likely diverse. When IEEE 754 is supported, it is recommended that :ieee-floating-point be included in *features*.

Note that implementations like VAX LISP mentioned below seem to have slightly different implementations from IEEE 754.

VAX LISP[TM] V3.1
 Digital Equipment Corporation. 1989, 1990.
All Rights Reserved.

Lisp> *features*
(EDITOR UIS COMPILER DEBUGGER :VMS VMS :DEC DEC :COMMON COMMON :VAX VAX :VAXLISP)

Whether an implementation supports -0.0 can be determined by checking:

(eql -0.0 0.0)
→ nil

as stated in the specification.

  • CLHS: EQL
  • In implementations that do not support -0.0, -0.0 is read as 0.0, so checking the result of the following should allow us to verify if

    (abs -0.0L0)
    produces the correct output.

    (list -0.0L0 (abs -0.0L0))
    

    Implementations Supporting -0.0

    SBCL 1.4.8
    (-0.0d0 0.0d0) → ok
    CMUCL 21d
    (-0.0d0 0.0d0) → ok
    ABCL 1.7.0
    (-0.0d0 0.0d0) → ok
    ECL 21.2.1
    (-0.0l0 0.0l0) → ok
    MCL 3.0/5.2
    (-0.0d0 0.0d0) → ok
    LispWorks 7.1.3
    (-0.0d0 -0.0d0) → fail
    Lucid CL 4.1
    (-0.0d0 -0.0d0) → fail

    Implementations Not Supporting -0.0

    Eclipse CL 1.1
    (0.0d0 0.0d0)
    CLISP 2.49.92
    (0.0L0 0.0L0)
    Allegro CL 10.1
    (0.0d0 0.0d0)
    Corman Lisp 3.1
    (0.0d0 0.0d0)
    AKCL 1.619
    (0.0 0.0)
    GCL 2.6.12
    (0.0 0.0)
    Xerox CL
    (0.0 0.0)
    VAX LISP
    (0.0L0 0.0L0)

    As a result, only LispWorks and Lucid CL showed inconsistencies.


    Not entirely sure if the above results are considered inconsistent with the Common Lisp standard, but since abs of #C(-0.0 0) seems to be 0.0 in LispWorks as well, I suspect something peculiar is happening only in float processing cases.

    (eql (abs #C(-0.0 0)) (abs #C(0.0 0)))
    → T
    
    (eql (abs -0.0) (abs 0.0))
    → nil