[PATCH v2] msvcrt: Make the cosh/sinh/tanh functions NAN preserving

Piotr Caban piotr.caban at gmail.com
Tue Jul 27 06:57:53 CDT 2021

> On 27 Jul 2021, at 00:01, Martin Storsjö <martin at martin.st> wrote:
> On Fri, 16 Jul 2021, Piotr Caban wrote:
>> Hi Martin,
>> On 7/16/21 2:05 PM, Martin Storsjo wrote:
>>> @@ -1139,6 +1139,9 @@ float CDECL coshf( float x )
>>>      UINT32 ui = *(UINT32*)&x;
>>>      float t;
>>>  +    if (isnan(x))
>>> +        return x;
>>> +
>> A quick test shows that ucrtbase returns something like:
>> if (isnan(x)) {
>>   *(DWORD*)&x |= 0x400000;
>>   return x;
>> }
>> Probably it will make sense to move the code to integrate better with musl implementation. Instead of checking for nan with isnan function it can be done here:
>> /* |x| > log(FLT_MAX) or nan */
>> if (ui > 0x7f800000)
>>   *(DWORD*)&t = *(DWORD*)&x | 0x400000;
>> else
>>   t = __expo2f(x, 1.0f);
>> return t;
> Hmm, yes, except all of these functions start out by masking out the sign bit of the input value, so if integrating the nan case at the end of the function, the sign bit is lost. (My own existing tests for nan preservation happen to be tests that only check whether the sign bit is preserved, nothing else.)
> The extra explicit upfront isnan() tests at the top aren't exactly nice though... Or should we just OR in the original sign bit too, at this point?
If this is a general question, then yes, is some cases it might be needed to add sign bit. In this case it’s already preserved because x is used (not ui that has the sign bit cleared).


More information about the wine-devel mailing list