[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] mathematical oddities
From: |
Peter Bex |
Subject: |
Re: [Chicken-users] mathematical oddities |
Date: |
Thu, 15 Jul 2010 17:35:22 +0200 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Jul 15, 2010 at 08:40:50AM -0400, John Cowan wrote:
> Peter Bex scripsit:
>
> > Chicken has made a choice to raise an error. I think that's a
> > respectable decision. I use Javascript at work quite a bit and
> > the infinities are quite often a source of bugs; you get some error
> > later on when you try to use the infinity, instead of at the point the
> > infinity is produced. I much prefer to be alerted right away that I'm
> > trying to perform an undefined operation like division by zero.
>
> The reason to return +0.inf from (/ 3.0 0.0) is that 0.0 is not a
> mathematical zero: rather, it refers to any number r where -DBL_MIN <
> r < DBL_MIN (DBL_MIN is defined in the C header <float.h>). Dividing by
> exact 0, on the other hand, clearly should throw an exception.
I forgot about that. Of course, rounding and representation issues make
things even more "interesting".
> I'm not sure what you mean by getting an error when dealing with infinity
> in JavaScript. Are you confusing infinity with NaN?
No, but NaN does have many of the same problems (in deferring errors to
later points in time). I was thinking about my current project at work
where I have to draw graphs on a canvas. Occasionally I divide something
by some other value and use the result as a location on the canvas.
This causes problems when the result of the division is NaN or Infinity.
Of course this is wrong, but I'd prefer to get an error when I do the
division, and not when I am trying to draw the calculated result (which
is several lines and function calls later). That would make debugging a
lot easier. Oh well.
> In addition, JavaScript forces you to use inexact arithmetic even
> where exact arithmetic makes more sense; Scheme doesn't.
Indeed. I guess this is where my reasoning falls on its face with JS,
at least, considering your earlier point about 0.0 not being exactly 0.
Cheers,
Peter
--
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
is especially attractive, not only because it can be economically
and scientifically rewarding, but also because it can be an aesthetic
experience much like composing poetry or music."
-- Donald Knuth