简体   繁体   English

Javascript - 科学记数法受限制的最大数量是多少?

[英]Javascript - What is the maximum number in scientific notation restricted by?

In JavaScript, I was curious to find out what was the maximum possible number representable in scientific notation without getting "Infinity" as a result, so I wrote a little program and found out it's this one: 在JavaScript中,我很想知道科学记数法中可能出现的最大可能数是多少而没有得到“无限”,所以我写了一个小程序,发现它就是这个:

17976931348623158079372897140530341507993413271003782693617377898044496829276475094664901797758720709633028641669288791094655554785194040263065748867150582068190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779

which can be abbreviated to 1.7976931348623157e+308. 其缩写为1.7976931348623157e + 308。

My question is, what makes this specific number the maximum possible in JavaScript? 我的问题是,是什么使这个特定数字成为JavaScript的最大数量? Is it hardware-dependent (maybe maximum one on 64 bit?) or language-specific? 它是依赖于硬件的(可能是64位上的最大值?)还是特定于语言的? Why exactly is 308 the maximum usable power of 10? 为什么308的最大可用功率为10?

And also, how different is it in other languages? 而且,在其他语言中有多么不同?

Short answer: 简短回答:
Double precision float. 双精度浮球。 Due to how the double data-type is defined. 由于如何定义双数据类型。

Long answer: 答案很长:

All floating point numbers (double is a double-precision float) are written as a product of two values, the mantissa and the exponent. 所有浮点数(double是双精度浮点数)都写成两个值的乘积,即尾数和指数。 In principle, this works similar to how numbers are written in scientific notation: for the number 1.34 * 10^24, the mantissa is 1.34 and the exponent is 24. 原则上,这与数字以科学记数法编写的方式类似:对于数字1.34 * 10 ^ 24,尾数为1.34,指数为24。

https://en.wikipedia.org/wiki/Double-precision_floating-point_format https://en.wikipedia.org/wiki/Double-precision_floating-point_format

Number.MAX_VALUE

The value of Number.MAX_VALUE is the largest positive finite value of the Number type, which is approximately 1.7976931348623157e+308. Number.MAX_VALUE的值是Number类型的最大正有限值,大约是1.7976931348623157e + 308。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: fafalselse, [[Configurable]]: false } . 此属性具有属性{ [[Writable]]: false, [[Enumerable]]: fafalselse, [[Configurable]]: false }

http://ecma262-5.com/ELS5_HTML.htm#Section_8.5 http://ecma262-5.com/ELS5_HTML.htm#Section_8.5

What differs for floats (and doubles) is that you split the total bytes that hold the number into two parts, one for the mantissa and one for the exponent. 浮点数(和双精度数)的不同之处在于,将包含数字的总字节数分为两部分,一部分用于尾数,一部分用于指数。 双精度二进制浮点格式:binary64

That gives you an exponent of 10 bits, and one sign bit for the exponent, so that would give you a number from -1023 to +1024. 这给出了一个10位的指数,以及指数的一个符号位,这样就可以得到-1023到+1024之间的数字。

However, the base of the exponent is not 10, but 2. The way the floating point number exponent is stored uses 8 bits (for floats) or 11 bits (for doubles), meaning you get exponent values of -127 to +128 (float) or -1023 to +1024 (double). 但是,指数的基数不是10,而是2.存储浮点数指数的方式使用8位(对于浮点数)或11位(对于双精度数),这意味着得到的指数值为-127到+128(浮动)或-1023到+1024(双)。

And 2^1024 gives us a value of 1.797693134862315907729305190789 * 10^308, which is the largest exponent of a double precision float. 而2 ^ 1024给出的值为1.797693134862315907729305190789 * 10 ^ 308,这是双精度浮点数的最大指数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 科学符号手机号码-Excel Javascript - Scientific notation mobile number - Excel Javascript JavaScript中数字的科学计数法 - Scientific notation for numbers in JavaScript 我们如何将Javascript中的科学计数法转换为数字 - How do we convert scientific notation to number in Javascript Javascript:防止 parseFloat 将大数转换为科学计数法 - Javascript: prevent parseFloat from converting large number to scientific notation javascript 转换科学计数法,如何确定 10 次方后的数字 - javascript converting scientific notation, how to determine the number after power of 10 如果不用科学记数法显示,JavaScript编号有多小? - How small can a JavaScript number be without displaying in scientific notation? 如何将包含科学记数法的字符串转换为正确的 Javascript 数字格式 - How to convert a String containing Scientific Notation to correct Javascript number format 在JavaScript中使用科学记数法的陷阱 - Pitfalls with using scientific notation in JavaScript 如何在javascript中将大的负科学记数字转换为十进制记号字符串? - How to convert big negative scientific notation number into decimal notation string in javascript? Angularjs避免使用数字滤波器的科学记数法 - Angularjs avoid scientific notation for number filter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM