読者です 読者をやめる 読者になる 読者になる

検証用テストコード (C++)

#include <cmath>
#include <iostream>

void Test1();
void Test2();

int main()
{
#if !defined(WIN64)
    _control87( _PC_53, _MCW_PC );
#endif

    Test1();
    Test2();

    return 0;
}

void Test1()
{
    const __int64 l1 = 0x7fe0000000000000;
    double d1 = * reinterpret_cast<const double*>( &l1 );
    double d2 = * reinterpret_cast<const double*>( &l1 );

    d1 += d2;
    d1 -= d2;

    if( _fpclass( d1 ) != _FPCLASS_PINF )
    {
        std::cout << "[a] strictfp semantics violation" << std::endl;
    }
}

void Test2()
{
    const __int64 l1 = 0x0008008000000000;
    const __int64 l2 = 0x3ff0000000000001;
    const __int64 l3 = 0x000fffffffffffff;
    const __int64 l4 = 0x3fefffffffffffff;

    const double d1 = * reinterpret_cast<const double*>( &l1 );
    const double d2 = * reinterpret_cast<const double*>( &l2 );
    const double d3 = * reinterpret_cast<const double*>( &l3 );
    const double d4 = * reinterpret_cast<const double*>( &l4 );

    const double ret1 = d1 * d2;
    const double ret2 = d3 / d4;
    __int64 dr1 = * reinterpret_cast<const __int64*>( &ret1 );
    __int64 dr2 = * reinterpret_cast<const __int64*>( &ret2 );
    
    if( ( dr1 & 0x1 ) != 1 )
    {
        std::cout << "[b] strictfp semantics violation" << std::endl;
    }
    if( ( dr2 & 0x1 ) != 1 )
    {
        std::cout << "[c] strictfp semantics violation" << std::endl;
    }
}