IEEE 754:究竟它是如何工作的? [英] IEEE 754: How exactly does it work?

查看:100
本文介绍了IEEE 754:究竟它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下code的行为因为它使用C?

Why does the following code behave as it does in C?

float x = 2147483647; //2^31
printf("%f\n", x); //Outputs 2147483648

下面是我的思维过程:

2147483647 =   0      1001 1101      1111 1111 1111 1111 1111 111

   (0.11111111111111111111111)base2 = (1-(0.5)^23)base10
=> (1.11111111111111111111111)base2 = (1 + 1-(0.5)^23)base10 = (1.99999988)base10

因此​​,对IEEE转换754记号回十进制: 1.99999988 * 2 ^ 30 = 2147483520

所以从技术上来说,C程序必须打印出来2147483520,对吧?

So technically, the C program must have printed out 2147483520, right?

推荐答案

的价值进行重新presented是2147483647,可重新psented这样$ P $接下来的两个值是2147483520和2147483648

The value to be represented would be 2147483647. the next two values which can be represented this way are 2147483520 and 2147483648.

由于后者更靠近unre presentable理想的,它被使用:在浮点,值得圆形,不截断

As the latter is closer to the unrepresentable "ideal one", it gets used: in floating point, the values get rounded, not truncated.

这篇关于IEEE 754:究竟它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆