[racket-dev] Subnormal numbers?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Tue Nov 29 14:39:13 EST 2011

I can't answer the question about underflow. But if you don't mind 
installing a nightly build of Racket, you get the (currently 
undocumented) module `unstable/flonum', which exports these:

     flonum->ordinal    ; number of flonums away from 0 (+ or -)
     flstep        ; the flonum n steps away (by ordering fl<)
     flnext        ; next largest flonum (by ordering fl<)
     flprev        ; next smallest flonum (by ordering fl<)
     -max.0        ; negative flonum with greatest non-infinite magnitude
     -min.0        ; negative flonum with smallest nonzero magnitude
     +min.0        ; positive flonum with smallest nonzero magnitude
     +max.0        ; positive flonum with greatest non-infinite magnitude

Also, the `plot' module in the nightly build deals just fine with 
intervals that are too small to represent using flonums. For example, to 
illustrate floating-point discretization and the density of flonums at 
different ranges:

#lang racket

(require plot unstable/flonum)

(plot (function (λ (x) (inexact->exact (sin x)))
                 (flstep 0.0 -10) (flstep 0.0 10)))

(- (flonum->ordinal 1.0) (flonum->ordinal 0.0))
(- (flonum->ordinal 2.0) (flonum->ordinal 1.0))
(- (flonum->ordinal 3.0) (flonum->ordinal 2.0))
(- (flonum->ordinal +max.0) (flonum->ordinal 1.0))

(parameterize ([plot-x-ticks  (log-ticks #:base 2)])
   (plot (function (compose flonum->ordinal exact->inexact) 1.0 8.0)))

Neil T

On 11/29/2011 09:32 AM, J. Ian Johnson wrote:
> I'm currently proctoring the freshmen's lab on inexact numbers and was curious how to denote subnormal numbers in Racket.
> Turns out that's not possible, since there is no underflow. Why does Racket follow the old standard of representing underflow with inexact zero?
> I imagine changing it now would break a lot of code, but I'm just curious.
> -Ian
> _________________________________________________
>    For list-related administrative tasks:
>    http://lists.racket-lang.org/listinfo/dev

Posted on the dev mailing list.