ieee754

https://www.zhihu.com/question/21711083

 

https://www.jianshu.com/p/cb377fd1a295

 

 

#include <iostream>
#include "string"
using namespace std;
#include "math.h"

/*IEEE754
31 30..23 22..0
S | E + 127 | M 1.*
-0.75 -> bf400000
float 1 | 8 | 23
double 1 | 11| 52
*/



int cmain() {
unsigned int a1 = 0xff900000;
float a2 = *(float *)&a1;
a2 = INFINITY;
int ar = isfinite(a2);
int sb = signbit(a2);
int rb = fpclassify(a2);
int rc = isnormal(a2);
printf("%f\n", a2);
float d = -0.75;
int *p = (int *)&d;
printf("%x\n", *p);
auto s = std::to_string(9.8);
printf("%03.3lf\n", 9.87876);
printf("%8d\n", 123456);
std::cout << s << std::endl;
return 0;
}

 

 

 

 

https://blog.csdn.net/linuxheik/article/details/78497649

int32_t float2int(double d){
union {double f; int32_t i;} u = {d};
u.f += 6755399441055744.0; //0x1.8p52; // 1.5 * 2^52
return u.i;
}
posted @ 2021-07-22 16:01  zJanly  阅读(160)  评论(0)    收藏  举报