小编Han*_*Kan的帖子

Linux gcc(5.4.0)中的浮点数是否符合IEEE754规则?

我的编程环境是gcc版本5.4.0 20160609(Ubuntu 5.4.0-6ubuntu1~16.04.4)

我的代码如下:

#include <stdio.h>

typedef unsigned char *byte_pointer;

void show_bytes(byte_pointer start, int len){
  int i;
  for (i = 0; i<len; i++)
    printf(" %.2x", start[i]);
  printf("\n");
}

void show_float(float x){
  show_bytes((byte_pointer)&x, sizeof(float));
}

int main(){
  int y = 0xffffff;
  float f = y;
  show_float(f);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

并且机器给出了结果: 00 00 00 e0

根据IEEE 754,我认为这是不对的; 但我不知道为什么.虽然Windows 2013中的VS 2013中的相同代码给出了正确的答案:ff ff 7f 4b

gcc 5.4.0不采用IEEE 754吗?或者我的代码中有问题吗?

c linux floating-point gcc ieee-754

3
推荐指数
1
解决办法
315
查看次数

标签 统计

c ×1

floating-point ×1

gcc ×1

ieee-754 ×1

linux ×1