chicken-users
[Top][All Lists]
Advanced

[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 09:38:07 +0200
User-agent: Mutt/1.4.2.3i

On Wed, Jul 14, 2010 at 11:04:38PM -0700, Shawn Rutledge wrote:
> #;7> (use numbers)
> ; loading /usr/lib64/chicken/5/numbers.import.so ...
> ; loading /usr/lib64/chicken/5/numbers.so ...
> #;8> (abs (- (/ 7.3 -1.2) (quotient 7.3 -1.2)))
> 
> Error: (quotient) bad argument type - not an integer: 7.3
> 
> Seems like at least a couple of bugs there: why does loading numbers
> break floating-point stuff that worked before, and, why doesn't modulo
> return the actual remainder?  Or I'm missing some reason why this
> should be considered correct...

quotient, modulo and remainder are the basic integral division operations.
They are simply not defined for reals.  I guess Chicken allows quotient
for flonums because it falls back to using flonums when a number could
not be stored in a fixnum because of overflows.  Chicken divides the
numbers and then extracts the integral and fractional parts using modf,
giving you what I would call unintuitive results like

 (quotient 3 0.5) => 6.0

I don't think it's a bug to allow only integers in these operations when
bignum support is enabled.  It is much more likely to be a mistake than
intended behaviour to call these functions with flonum args.

> There's a nice comparison of scheme impl's with regard to calculations
> involving infinity here:
> 
> http://people.csail.mit.edu/jaffer/III/RAWI

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.

But I guess this is a controversial point we could argue about infinitely :)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]