[racket-dev] Subnormal numbers?
Normally I only read messages of this list. Now I feel I have to reply. I
have seen various floating point systems. Some of them would immediately
force an abort when forming an overflow or underflow. Others would abort
only after referring to underflowed or overflowed floating point (with
trouble to find out where the underflow or overflow was produced) The
systems that would not immediately abort when producing an underflow or
overflow, provided functions allowing to check for under- or overflow
without aborting. I am talking about fortran here. I think DrRacket does a
good job. You can check results to be inexact zero or nan or inf. When
implementing a calculation that might produce underflow or overflow, it is,
according to my meaning, the responsability of the programmer to take care
of these cases. Scheme, and in particular DrScheme, does provide all tools
for this kind of precaution. For example you can capture a division by exact
zero. You can also detect division by inexact zero, just by checking that
the result is not infinity (or nan when dividing zero by zero). When dealing
with algorithms that may have these problems, it is the task of the
programmer to deal with them. I don't think there is any computational
system that could service all programmers as they are inclined to expect. A
programmer who is intensionaly using ploating points (id est inexact reals,
internally in fact represented by quasi exact rational numbers) should be
aware of the limitations of the numerical system. In some cases it may be
desirable to have exact representations for all square roots (as in parts of
group theory) This is possible, but as a programmer you cannot demand that
your language provides these tools without your own effort (although they
may be available in a planet contribution) If you need it you may have to
implement it by yourself.
Although for me the distinction betweeen exact and inexact seems rather
clear, may be the documentation should provide some more information on this
subjext. A good thing is that inexactness is contaguous. For example, when
giving data to a program and these data may be inexact (e.g. as obtained by
a measurement), make sure that each numerical datum has a period.
Greetings, Jos
-----Original Message-----
From: dev-bounces at racket-lang.org [mailto:dev-bounces at racket-lang.org] On
Behalf Of Neil Toronto
Sent: martes, 29 de noviembre de 2011 20:39
To: dev at racket-lang.org
Subject: Re: [racket-dev] Subnormal numbers?
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->bit-field
bit-field->flonum
flonum->ordinal ; number of flonums away from 0 (+ or -)
ordinal->flonum
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
_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/dev