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

Martin Storsjö martin at martin.st
Tue Jul 27 16:59:11 CDT 2021


On Tue, 27 Jul 2021, Piotr Caban wrote:

>> 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:
>>>
>>> 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).

Yes, but ui, with the sign bit cleared, is also written back to x right 
after clearing the sign bit, with e.g. x = *(float*)&ui;

But we can store the sign bit separately and reapply it at the end. But 
I'll give it a shot at writing it that way.

// Martin


More information about the wine-devel mailing list