久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

大小相同時,浮點數和整數數據類型有什么區別

What is the difference between the float and integer data type when the size is the same?(大小相同時,浮點數和整數數據類型有什么區別?)
本文介紹了大小相同時,浮點數和整數數據類型有什么區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

大小相同時浮點數和整數數據類型有什么區別?

What the difference between the float and integer data type when size is same?

推薦答案

  • float 存儲浮點值,即可能有小數位的值
  • int 只存儲整數值,即整數
    • float stores floating-point values, that is, values that have potential decimal places
    • int only stores integral values, that is, whole numbers
    • 因此,雖然兩者都是 32 位寬,但它們的使用(和表示)卻大不相同.您不能將 3.141 存儲在整數中,但可以存儲在 float 中.

      So while both are 32 bits wide, their use (and representation) is quite different. You cannot store 3.141 in an integer, but you can in a float.

      進一步剖析它們:

      在整數中,所有位用于存儲數值.這是(在 Java 和許多計算機中)在所謂的 two's 補碼 中完成的.這基本上意味著您可以將 −231 的值表示為 231 − 1.

      In an integer, all bits are used to store the number value. This is (in Java and many computers too) done in the so-called two's complement. This basically means that you can represent the values of −231 to 231 − 1.

      在浮點數中,這 32 位分為三個不同的部分:符號位、指數和尾數.它們的布局如下:

      In a float, those 32 bits are divided between three distinct parts: The sign bit, the exponent and the mantissa. They are laid out as follows:

      S EEEEEEEE MMMMMMMMMMMMMMMMMMMMMMM
      

      有一個位可以確定數字是負數還是非負數(零既不是正數也不是負數,但符號位設置為零).然后有 8 位指數和 23 位尾數.為了從中獲得有用的數字,(大致)執行以下計算:

      There is a single bit that determines whether the number is negative or non-negative (zero is neither positive nor negative, but has the sign bit set to zero). Then there are eight bits of an exponent and 23 bits of mantissa. To get a useful number from that, (roughly) the following calculation is performed:

      M × 2E

      (還有更多內容,但對于本次討論來說應該足夠了)

      (There is more to it, but this should suffice for the purpose of this discussion)

      尾數本質上不過是一個 24 位整數.這將乘以 2 的指數部分的冪,大致是在 &-128 和 127 之間的數字.

      The mantissa is in essence not much more than a 24-bit integer number. This gets multiplied by 2 to the power of the exponent part, which, roughly, is a number between −128 and 127.

      因此,您可以準確地表示所有適合 24 位整數的數字,但數字范圍也更大,因為更大的指數允許更大的值.例如,float 的最大值約為 3.4 × 1038int 只允許最大為 2.1 × 109 的值.

      Therefore you can accurately represent all numbers that would fit in a 24-bit integer but the numeric range is also much greater as larger exponents allow for larger values. For example, the maximum value for a float is around 3.4 × 1038 whereas int only allows values up to 2.1 × 109.

      但這也意味著,由于 32 位只有 4.2 × 109 種不同的狀態(這些狀態都用于表示 int 可以存儲的值),所以在float 數字范圍的較大端,數字間隔更寬(因為唯一的 float 數字不能多于唯一的 int 數字).那么,您不能準確地表示某些數字.例如,數字 2 × 1012float 中的表示形式為 1,999,999,991,808.這可能 接近 到 2,000,000,000,000,但并不準確.同樣,將 1 添加到該數字不會改變它,因為 1 太小而無法影響 float 在那里使用的較大比例.

      But that also means, since 32 bits only have 4.2 × 109 different states (which are all used to represent the values int can store), that at the larger end of float's numeric range the numbers are spaced wider apart (since there cannot be more unique float numbers than there are unique int numbers). You cannot represent some numbers exactly, then. For example, the number 2 × 1012 has a representation in float of 1,999,999,991,808. That might be close to 2,000,000,000,000 but it's not exact. Likewise, adding 1 to that number does not change it because 1 is too small to make a difference in the larger scales float is using there.

      同樣,您也可以在 float 中表示非常小的數字(介于 0 和 1 之間),但無論數字是非常大還是非常小,float 只能精度約為 6 或 7 位十進制數字.如果您的數字很大,則這些數字位于數字的開頭(例如 4.51534 × 1035,即 451534 后跟 30 個零 - 而 float 無法分辨關于這 30 位數字實際上是零還是其他任何有用的信息),對于非常小的數字(例如 3.14159 × 10−27),它們位于數字的遠端,遠遠超出起始數字0.0000...

      Similarly, you can also represent very small numbers (between 0 and 1) in a float but regardless of whether the numbers are very large or very small, float only has a precision of around 6 or 7 decimal digits. If you have large numbers those digits are at the start of the number (e.g. 4.51534 × 1035, which is nothing more than 451534 follows by 30 zeroes – and float cannot tell anything useful about whether those 30 digits are actually zeroes or something else), for very small numbers (e.g. 3.14159 × 10−27) they are at the far end of the number, way beyond the starting digits of 0.0000...

      這篇關于大小相同時,浮點數和整數數據類型有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美精品二区 | 欧美亚洲国产成人 | 欧美中文字幕在线观看 | 日韩亚洲欧美一区 | 一色一黄视频 | 免费a网站 | 精品国产一区二区三区久久久蜜月 | 日韩电影在线 | 草草草久久久 | 精产国产伦理一二三区 | 精品九九 | 69精品久久久久久 | 日韩三级 | 久久亚洲国产精品日日av夜夜 | 日韩精品一二三 | 黄色亚洲 | 91综合网 | 亚洲久久一区 | 97视频人人澡人人爽 | 免费国产视频 | 一区二区三区中文字幕 | 亚洲美女一区二区三区 | 美女张开腿露出尿口 | 天堂中文资源在线 | 精品视频免费 | 成人精品国产 | av天天澡天天爽天天av | 性精品| 99re热精品视频 | 逼逼网 | 毛片一级电影 | 日本爱爱视频 | 国产在线观看免费 | 色偷偷噜噜噜亚洲男人 | 丁香一区二区 | 韩日av在线| 一区二区福利视频 | 亚洲午夜三级 | 美女天堂在线 | 午夜视频一区 | 精品一区二区三区在线视频 |