编程语言可以存储的最大数字 [英] Largest number a programming language can store

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

问题描述

我们使用变量来存储编程中的短语,数字等内容。我想知道所有编程语言及其变量,变量可以存储的最大数量是多少?



如果程序员需要存储更大的数字怎么办?比最大数量的变量可以存储?

解决方案

没有绝对限制: BigInteger结构 [ ^ ]


我假设你在谈论整数。

'标准'整数类型可以根据它们的大小代表'最大'数字,即2 ^ size -1。

所以你有,通常:

大小(位)最大数量
8 255
16 65535
32 4294967295
64 184 46744073709551615
...



但是,有些语言提供大整数数据类型(其他语言可能有出于同样的目的),理论上没有限制(例如,参见 Stack Overflow 问题: BigInteger是否有上限? [ ^ ])。



Quote:

如果程序员需要存储的数字大于可以存储的最大数量的变量怎么办?

如果可能,他/她定义自己的数据类型以应对数字(或做出一些假设来简化问题并'减少'这样的数字)。当然,与数据类型一起,程序员必须实现他需要执行的所有操作。


We use variables to store things like phrases, numbers in programming. And I want to know among all the programming languages and its variables, what is the largest number a variable can store ?

And What if programmer needs to store a larger number than the largest number of the variable can store ?

解决方案

There is no absolute limit: BigInteger structure[^]


I am assuming you are talking about integers.
'Standard' integer types could represent 'largest' numbers according to their size, namely 2^size-1.
So you have, typically:

size (bits)     largest number
       8                   255
      16                 65535 
      32            4294967295
      64  18446744073709551615
      ...


However, some languages provides big integer data types (other languages could have libraries for the same purpose), 'theoretically not bounded' (see, for instance, this Stack Overflow question: Is there an upper bound to BigInteger?[^]).

Quote:

And What if programmer needs to store a larger number than the largest number of the variable can store ?

If possible, he/she defines its own datatype to cope with the number (or make some assumptions for simplify the problem and 'reduce' such number). Of course, together with the datatype the programmer has to implement all the operation he need to perform with it.


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

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