简体   繁体   English

C#中浮点数和double数据类型的实际范围是什么?

[英]What are the actual ranges of floating point and double data types in C#?

I'm learning C# and trying to get a logical visual representation of the actual range of data types in C#. 我正在学习C#,并试图获得C#中数据类型实际范围的逻辑可视表示。

I have moved through the integers and am now up to float and double data types. 我已经遍历整数,现在可以使用浮点数和双精度数据类型。

  1. 8 bits (1 byte), sbyte, -128 to 127. 8位(1字节),字节,-128至127。
  2. 8 bits (1 byte), byte, 0 to 255. 8位(1字节),字节,0至255。
  3. 16 bits (2 bytes), short, -32,768 to 32,767. 16位(2字节),短,-32,768至32,767。
  4. 16 bits (2 bytes), ushort, 0 to 65535. 16位(2个字节),ushort,0至65535。
  5. 32 bits (4 bytes), int, -2,147,483,648 to 2,147,483,647. 32位(4字节)int -2,147,483,648至2,147,483,647。
  6. 32 bits (4 bytes), uint, 0 to 4,294,967,295. 32位(4字节),uint,0至4,294,967,295。
  7. 64 bits (8 bytes), long, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 64位(8字节),长-9,223,372,036,854,775,808至9,223,372,036,854,775,807
  8. 64 bits (8 bytes), ulong, 0 to 18,446,744,073,709,551,615. 64位(8字节),ulong,0至18,446,744,073,709,551,615。

Here are the references to float and double data types sizes at msdn: 以下是msdn上对float和double数据类型大小的引用:

Float: http://msdn.microsoft.com/en-us/library/b1e65aza(v=vs.110).aspx 浮动: http//msdn.microsoft.com/zh-CN/library/b1e65aza( v = vs.110).aspx

在此处输入图片说明

Double: http://msdn.microsoft.com/en-us/library/678hzkk9.aspx 双: http : //msdn.microsoft.com/en-us/library/678hzkk9.aspx

在此处输入图片说明

So, trying to keep with the convention of specifiying the actual range of numbers as in the numbered list above, what do these two ranges actually represent? 因此,尝试按照上面编号列表中指定数字的实际范围的惯例,这两个范围实际上代表什么?

The ranges are actually –infinity to +infinity. 范围实际上是–无限到+无限。

The largest finite float is 340282346638528859811704183484516925440. This is 2 128 –2 128–24 . 最大的有限 float是340282346638528859811704183484516925440。这是2 128 –2 128–24

The largest finite double is 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368. This is 2 1024 –2 1024–53 . 最大的有限 double是179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.这是2 1024 -2 一零二四年至1053年

The ranges are represented in "exponential format" for conciseness. 为简洁起见,范围以“指数格式”表示。 For example, +1.7e+308 means 17 followed by 307 zeros: 例如,+ 1.7e + 308表示17,后跟307个零:

1,700,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 1,700,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000

So the exponential format is preferred for such large numbers. 因此,指数格式适用于如此大的数字。 And the same goes for extremely small numbers. 对于极小的数字也是如此。

Also, take a look at this reading by Jon Skeet. 另外,请看乔恩·斯基特(Jon Skeet)的读物

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM