inexact->exact
Jim White
jim@pagesmiths.com
Fri Nov 8 12:15:00 GMT 2002
Jim White wrote:
> Marco Vezzoli wrote:
>> jim@pagesmiths.com wrote:
>>>> ...
>>>> call to log (0.0)
>>>> return from log => #i-1/0
>>>
>>> That is the correct result. The logarithm of zero is not a number.
>>
>> You are right, I simply copied the routine and the examples the author
>> gived which included tests with zeroes. Maybe the scheme implementations
>> where the routine was written are more permissive (or simply wrong) with
>> the log arguments.
>
> As far as a the specification goes, since the result of (log 0) is not
> defined, there isn't any way to be wrong. Other implementations are
> probably doing what Java does, which is to return a negative infinity
> float. So actually I should have said it is undefined for Scheme (and
> CL) specifications because IEEE does define -infinity as a number.
>
> Same goes for inexact->exact's use of an exception for an invalid
> number. Friendlier though would be to return infinity (negative or
> positive depending on the numerator's sign) rather than an exception at
> that point.
Whoops. I just checked out how infinities are handled, and Kawa's
gnu.math is actually doing everything quite nicely.
(log 0) -> #i-1/0
Which is negative infinity (inexact).
(inexact->exact (log 0)) -> -1/0
Which is negative infinity (exact).
The failure is actually due to the computation in sci where it is
multiplying negative infinity (-1/0) by zero.
(* 0 (log 0)) -> #i0/0
#i0/0 is the display for floating NaN.
I believe that is the correct result for IEEE fp.
Jim
More information about the Kawa
mailing list