This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see Zero in WG2's repo for R7RS-large.

Zero

cowan
2012-05-17 04:04:11
9history
source

This page talks about how implementations handle various aspects of zero. Thanks to Alexey Radul for the ideas here; the research is mine.

Exact division by zero

Racket, MIT, Gambit, Chicken, Bigloo, Scheme48/scsh, Chibi, Guile, SISC, Chez, Ikarus/Vicare, Larceny, Ypsilon, Mosh, IronScheme, NexJ, STklos, Shoe, Scheme 7, BDC, XLisp, Rep, Schemik, Elk, UMB, SigScheme, SXM, Sizzle, Spark, Dfsch, Inlab, VSCM report an error.

Gauche, SCM, KSi, VX return inexact infinity.

Kawa returns exact infinity.

Scheme 9, Femtolisp return an incorrect result.

Inexact division by exact zero

Racket, Gambit, Chicken, scsh, Chibi, Guile, Shoe, Scheme 7, BDC, XLisp, Rep, Schemik, Elk, SXM, Sizzle, Spark, Dfsch, Inlab, VSCM report an error.

Gauche, Bigloo, Scheme48, Kawa, SISC, SCM, Chez, Ikarus/Vicare, Larceny, Ypsilon, Mosh, IronScheme, NexJ, STklos, UMB, VX return inexact infinity.

MIT reports an error unless floating traps are ignored, in which case it returns inexact infinity.

SigScheme, Dream, Oaklisp, Owl Lisp do not support inexact numbers.

KSi, Scheme 9, Femtolisp return an incorrect result.

Division by inexact zero

Plain Chicken, scsh, Shoe, TinyScheme, XLisp, Rep, Schemik, Scheme 7, SXM, Sizzle, Dfsch, Inlab, VSCM report an error.

Racket, Gauche, MIT, Gambit, Chicken with the numbers egg, Bigloo, Scheme48, Guile, Kawa, SISC, Chibi, SCM, Chez, SCM, Ikarus/Vicare, Larceny, Ypsilon, Mosh, IronScheme, NexJ, STklos, BDC, Elk, UMB, VX, Spark, Femtolisp return inexact infinity.

SigScheme, Dream, Oaklisp, Owl Lisp do not support inexact numbers.

KSi, Scheme 9 return an incorrect result.

Inexact multiplication by exact zero

Racket, MIT, Gambit, Chez, Ypsilon, TinyScheme, XLisp, Elk, SXM, Sizzle, Spark, Inlab return exact 0.

Gauche, Chicken, Bigloo, Scheme48/scsh, Guile, Kawa, SISC, Chibi, SCM, Ikarus/Vicare, Larceny, Mosh, IronScheme, NexJ, STklos, KSi, Shoe, Scheme 9, Scheme 7, BDC, Rep, Schemik, UMB, VX, Femtolisp, Dfsch, VSCM return inexact 0.0.

SigScheme, Dream, Oaklisp, Owl Lisp do not support inexact numbers.

Complex numbers with 0.0 imaginary part.

Gauche, MIT, Chicken with the numbers egg, Scheme48/scsh, Kawa, SISC, SCM, STklos, KSi, Scheme 7, UMB, Spark, Dfsch, VSCM consider 3.0+0.0i to be a real number.

Racket, Gambit, Guile, Chibi, Chez, Vicare, Larceny, Ypsilon, Mosh, IronScheme do not.

Bigloo, Ikarus, NexJ, SigScheme, Shoe, TinyScheme, Dream, Scheme 9, BDC, XLisp, Rep, Schemik, Elk, VX, Oaklisp, SXM, Sizzle, Femtolisp, Inlab, Owl Lisp do not implement non-real numbers.

Negative zero

I did a test of:

(let* ((minf (* 1.0e200 -1.0e200)) (mzero (/ 1.0 minf))) (list minf mzero (eqv? mzero 0.0)))

Gauche, Chicken, Bigloo, Scheme48/scsh, SISC, Chibi, SCM, Ikarus, Ypsilon, Mosh, IronScheme, NexJ, STklos, Shoe, TinyScheme, RScheme, Scheme 7, BDC, XLisp, Schemik, Elk, UMB, VX return some variant of (-inf.0 -0.0 #t).

Racket, Gambit, Guile, Kawa, Chez, Vicare, Larceny, Rep return some variant of (-inf.0 -0.0 #f).

I wasn't able to generate -0.0 on MIT, KSi, SigScheme, Scheme 9, Dream, Oaklisp, Owl Lisp.

Inexact zero raised to a negative real power

This situation involves the log of 0, and R6RS and R7RS permit implementations to either raise an exception or return an arbitrary number.

+inf.0 Racket, Gauche, Gambit, Chicken, Bigloo, scsh, Kawa, Chibi, SCM, Chez, Ypsilon, Mosh, NexJ, STklos, XLisp, Rep, UMB, SXM, Spark, Dfsch, Inlab return inf.0.

Guile, Larceny, Scheme 9 return +nan.0.

SISC, IronScheme return 0.0.

Elk returns 0.

Sizzle returns its smallest representable integer (-232).

MIT (ignoring floating point traps), Scheme48, KSi, Scheme 7 raise an exception.

SigScheme, Dream, Oaklisp, Owl Lisp do not support inexact numbers.

TinyScheme, Schemik, Femtolisp, BDC either don't provide expt or don't provide log.

Inexact zero raised to a complex power whose real part is negative

Racket, Gauche, Gambit, Chicken with the numbers egg, Kawa, Chibi, Ypsilon, Spark return +nan.0+nan.0i.

Guile returns +inf.0+nan.0i.

SISC, Chez, Vicare, IronScheme return 0.0.

SCM, Dfsch return +inf.0.

Larceny returns +nan.0.

MIT (ignoring floating point traps), Scheme48/scsh, STklos, UMB raise an exception.

Mosh returns its implementation-specific "undefined" value.

Plain Chicken, Bigloo, Ikarus, NexJ, SigScheme, Shoe, TinyScheme, Scheme 9, Dream, RScheme, BDC, XLisp, Rep, Schemik, Elk, VX, Oaklisp, Femtolisp, Inlab, Owl Lisp do not support non-real numbers.