How to use std::signaling_nan?

前端 未结 4 568
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 14:56

After looking at another question on SO (Using NaN in C++) I became curious about std::numeric_limits::signaling_NaN().

I could not get si

4条回答
  •  无人共我
    2021-01-12 15:32

    From TFM:

    cout << "The signaling NaN for type float is:  "
        << numeric_limits::signaling_NaN( )
        << endl;
    

    ->

    The signaling NaN for type float is: 1.#QNAN

    where the 'Q' stands for 'Quiet'. Dunno why it would return that, but that's why it doesn't throw an exception for you.

    Out of curiosity, does this work better?

    const double &real_snan( void )
    {
        static const long long snan = 0x7ff0000080000001LL;
        return *(double*)&snan;
    }
    

提交回复
热议问题