浮点数表示

246 阅读1分钟

标准浮点格式

浮点数V = (-1) ^ s * (2 ^ E) * M

浮点类型 符号位 阶码 尾数
单精度 1 8 23
双精度 1 11 52

用16进制表示双精度浮点数1

  • 偏置bias = 2^(11 - 1) - 1 = 1023
  • 阶码E = e - bias
  • 尾数M = 1 + f 直接赋值
double a;
a = 0x1;

溢出赋值

typedef struct {
    int arr[2];
    double b;
}node;

node n;
n.arr[2] = 0x0;
n.arr[3] = 0x3FF00000; # E = 0 = e - bias = 2^10 - 1 - (2^10 - 1) M = 1 + 0