C++ 浮点数的存储与精度
先看个例子(如下),我们看下int、float、double在内存的二进制表示
#include<stdio.h> #include <stdlib.h> #include <string.h> #include<cstdlib> bool isLittleEndian() { int x = 1; return *((char*) (&x)) == 1; } template<class T> void printBinary(T d) { char* p = (char*)&d; int sz = sizeof(T); // bytes char* buff = new char[sz * 8 + 1]; buff[sz * 8] = '