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

Martin Storsjö martin at martin.st
Mon Jul 26 17:01:19 CDT 2021


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?

// Martin




More information about the wine-devel mailing list