bug in logarithm()

Jeff Johnston jjohnstn@redhat.com
Thu Oct 18 00:22:00 GMT 2007


Martin Koeppe wrote:
>
>
> Hi Jeff,
>
> On Wed, 17 Oct 2007, Jeff Johnston wrote:
>
>>> I just found a bug (or at least a discrepancy between doc and src) 
>>> in newlib's libm, files mathfp/s_logarithm.c and mathfp/sf_logarithm.c:
>>>
>>> There the docs at the beginning of the files say, log(0) returns 
>>> -Inf, what the gawk test suite would also expect btw, but clearly 
>>> the implementation doesn't return -Inf, but NaN instead.
>>>
>>> Martin
>> A fix has been made.  Thanks.
>
> the fix isn't quite right. log(-1) should still return nan. In 
> particular log(x) should return:
>
> x==nan or x<0.0 : errno=EDOM,   return nan
>
> x==0.0 :          errno=ERANGE, return -inf
>
> x>0.0 :           return log(x)
>
>
Oops, that was sloppy of me.  I have fixed the functions to be 
consistent with the libm/math directory log functions and with glibc.  
The one difference from your chart above is that nan does not set 
errno.  This is consistent with SUSV2 (optional) and C99 (unmentioned).  
I also added support for inf where inf is returned and again no error set.

-- Jeff J.
> Martin



More information about the Newlib mailing list