how can I extract the mantissa of a double

前端 未结 4 1154
执笔经年
执笔经年 2020-12-01 16:37

I would like to store in a variable the mantisssa of a double

I have post a code to get the binary representation of a double : click here

What should I chan

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 17:37

    The code here is a bit dangerous in terms of portability, but here it is...

    #include 
    
    float myFloat = 100;
    int32_t mantissa1 =
        reinterpret_cast(myFloat) & (((int32_t)1 << 24) - 1);
    
    double myDouble = 100;
    int64_t mantissa2 =
        reinterpret_cast(myDouble) & (((int64_t)1 << 53) - 1);
    

提交回复
热议问题