最大的整数可以存储在一个双倍 [英] biggest integer that can be stored in a double

查看:119
本文介绍了最大的整数可以存储在一个双倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

可以存储在IEEE 754双重类型中最大的无浮动整数是什么? p>可以存储在双精度中而不会损失精度的最大/最大的整数与双精度值的最大值相同。也就是说, DBL_MAX 或约1.8 ×  10 308 (如果您的双倍是IEEE 754 64位双倍)。这是一个整数它正好代表。你还想要什么?



继续,问我最大的整数是什么,这样它可以存储和所有较小的整数 IEEE 64位双精度,而不会失去精度。 IEEE 64位双倍数字尾数为52位,所以我认为它是2 53




  • 2 < sup> 53 + 1不能存储,因为在开始的1和最后的1在它们之间有太多的零。

  • 可以存储小于2 53 的任何东西,52位显式存储在尾数中,然后有效的指数给你另一个。

  • 2 53 显然可以存储,因为它的功率是2。


$或者另一种观察方式:一旦偏离了指数,并忽略了与该问题无关的符号位,双倍存储的值是2的幂,加上52 -bit整数乘以2 exponent  -   52 。所以用指数52可以将所有的值从2 52 到2 53   -   1。然后使用指数53,可以在2 53 之后存储的下一个数字是2 53 + 1 ×  2 53 - 52 。所以精度损失首先发生在2 53 + 1。


What is the biggest "no-floating" integer that can be stored in an IEEE 754 double type without losing precision ?

解决方案

The biggest/largest integer that can be stored in a double without losing precision is the same as the largest possible value of a double. That is, DBL_MAX or approximately 1.8 × 10308 (if your double is an IEEE 754 64-bit double). It's an integer. It's represented exactly. What more do you want?

Go on, ask me what the largest integer is, such that it and all smaller integers can be stored in IEEE 64-bit doubles without losing precision. An IEEE 64-bit double has 52 bits of mantissa, so I think it's 253:

  • 253 + 1 cannot be stored, because the 1 at the start and the 1 at the end have too many zeros in between.
  • Anything less than 253 can be stored, with 52 bits explicitly stored in the mantissa, and then the exponent in effect giving you another one.
  • 253 obviously can be stored, since it's a small power of 2.

Or another way of looking at it: once the bias has been taken off the exponent, and ignoring the sign bit as irrelevant to the question, the value stored by a double is a power of 2, plus a 52-bit integer multiplied by 2exponent − 52. So with exponent 52 you can store all values from 252 through to 253 − 1. Then with exponent 53, the next number you can store after 253 is 253 + 1 × 253 − 52. So loss of precision first occurs with 253 + 1.

这篇关于最大的整数可以存储在一个双倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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