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

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

问题描述

可以存储在 IEEE 754 double 类型中且不丢失精度的最大无浮点"整数是多少?

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

推荐答案

在不丢失精度的情况下可以存储在 double 中的最大/最大整数与 double 的最大可能值相同.也就是说,DBL_MAX 或大约 1.8 × 10308(如果您的双精度数是 IEEE 754 64 位双精度数).它是一个整数.它被准确地表现出来.你还想要什么?

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?

继续,问我最大的整数是多少,这样它和所有较小的整数都可以存储在 IEEE 64 位双精度中而不会丢失精度.IEEE 64 位双精度数有 52 位尾数,所以我认为它是 253:

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 无法存储,因为开头的 1 和结尾的 1 中间有太多的零.
  • 可以存储小于 253 的任何值,其中 52 位明确存储在尾数中,然后指数实际上为您提供另一个.
  • 253 显然可以存储,因为它是 2 的小幂.
  • 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.

或者另一种看待它的方式:一旦去除了指数的偏差,并忽略与问题无关的符号位,double 存储的值是 2 的幂,加上一个 52 位整数乘以 2指数 - 52.因此,使用指数 52,您可以存储从 252 到 253 − 1 的所有值.然后使用指数 53,您可以在 253 之后存储的下一个数字是 253 + 1 × 253 − 52.所以精度损失首先发生在 253 + 1.

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.

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

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