chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] mathematical oddities


From: Shawn Rutledge
Subject: [Chicken-users] mathematical oddities
Date: Wed, 14 Jul 2010 23:04:38 -0700

Sorry for resurrecting such an old thread but I also noticed division
by zero doesn't return infinity, and I sortof wish it did, or that it
could be an option.

On Mon, Jun 19, 2006 at 11:53 PM, felix winkelmann <address@hidden> wrote:
> On 6/20/06, Thomas Chust <address@hidden> wrote:
>>
>> Maybe something like that could be included in the library for
>> completeness' sake. Or we should create an IEEE arithmetic egg (are there
>> more functions than / in CHICKEN that are not IEEE compliant?). But I
>> would really vote against modifying the behaviour of /.
>>
>
> Additionally, you can of course do
>
> (condition-case (/ 1 0) (exn (exn arithmetic) "doh!"))

Can you detect the actual divide-by-zero error though as opposed to
just a general arithmetic error?

I'm messing around with finding the angles between vectors (trying to
simplify a sequence of connected line segments when it's possible to
replace them with fewer and longer ones, within a tolerance).
Fortunately atan takes two numbers so division by zero won't come up
in that case.  (Otherwise if you try to take the slope of a line
segment you'll get infinity sometimes, and that should be normal, not
an error.)  Then I was testing modulo and found this:

#;1> (remainder 7.3 1.2)
0.100000000000001
#;2> (quotient 7.3 1.2)
6.0
#;3> (/ 7.3 1.2)
6.08333333333333
#;4> (- (/ 7.3 1.2) (quotient 7.3 1.2))
0.083333333333333

#;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...

There's a nice comparison of scheme impl's with regard to calculations
involving infinity here:

http://people.csail.mit.edu/jaffer/III/RAWI



reply via email to

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