[PATCH] Don't do double divide in powf.

Jon Beniston jon@beniston.com
Tue Dec 12 17:25:00 GMT 2017


>>> --- a/newlib/libm/math/wf_pow.c
>>> +++ b/newlib/libm/math/wf_pow.c
>>> @@ -108,7 +108,7 @@
>>>   		    if (_LIB_VERSION == _SVID_)
>>>   		        exc.retval = 0.0;
>>>   		    else
>>> -		        exc.retval = 0.0/0.0;	/* X/Open allow NaN */
>>> +		        exc.retval = nan("");	/* X/Open allow NaN */
>> As far as I can see, that still pulls in an unnecessary function call, 
>> nan().
>>
>> What about using NAN?  That's basically __builtin_nanf("") and usually 
>> resolves without function call on any platform.
>No to either of the above.  The 0/0 construct is to cause a floating point "invalid" 
>exception, which the functions do not do.  (The divide has to be done 
>at runtime to cause the exception.)  The double divide 
>can be made float by changing it to 0.0F/0.0F.

That doesn't always work though, particularly with s/w floating point libs.

Could it be abstracted to a target specific function/macro to raise an invalid exception / return a NaN?

There's quite a few other functions that use the technique.

Cheers,
Jon



More information about the Newlib mailing list