pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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(使用線程逐塊處理文件)
主站蜘蛛池模板: 三效蒸发器_多效蒸发器价格_四效三效蒸发器厂家-青岛康景辉 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | 儋州在线-儋州招聘找工作、找房子、找对象,儋州综合生活信息门户! | 生鲜配送系统-蔬菜食材配送管理系统-连锁餐饮订货配送软件-挪挪生鲜供应链管理软件 | 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | TwistDx恒温扩增-RAA等温-Jackson抗体-默瑞(上海)生物科技有限公司 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 「阿尔法设计官网」工业设计_产品设计_产品外观设计 深圳工业设计公司 | 烟台游艇培训,威海游艇培训-烟台市邮轮游艇行业协会 | 天津中都白癜风医院_天津白癜风医院_天津治疗白癜风 | 西安标准厂房_陕西工业厂房_西咸新区独栋厂房_长信科技产业园官方网站 | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | 防爆大气采样器-防爆粉尘采样器-金属粉尘及其化合物采样器-首页|盐城银河科技有限公司 | 微量水分测定仪_厂家_卡尔费休微量水分测定仪-淄博库仑 | 安全光栅|射频导纳物位开关|音叉料位计|雷达液位计|两级跑偏开关|双向拉绳开关-山东卓信机械有限公司 | 直线模组_滚珠丝杆滑台_模组滑台厂家_万里疆科技 | 冷却塔风机厂家_静音冷却塔风机_冷却塔电机维修更换维修-广东特菱节能空调设备有限公司 | 代做标书-代写标书-专业标书文件编辑-「深圳卓越创兴公司」 | 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 商用绞肉机-熟肉切片机-冻肉切丁机-猪肉开条机 - 广州市正盈机械设备有限公司 | 设定时间记录电子秤-自动累计储存电子秤-昆山巨天仪器设备有限公司 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 色油机-色母机-失重|称重式混料机-称重机-米重机-拌料机-[东莞同锐机械]精密计量科技制造商 | 仓储笼_仓储货架_南京货架_仓储货架厂家_南京货架价格低-南京一品仓储设备制造公司 | 浙江上沪阀门有限公司| 涿州网站建设_网站设计_网站制作_做网站_固安良言多米网络公司 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 上海办公室装修,写字楼装修—启鸣装饰设计工程有限公司 | 北京办公室装修,办公室设计,写字楼装修-北京金视觉装饰工程公司 北京成考网-北京成人高考网 | 工装定制/做厂家/公司_工装订做/制价格/费用-北京圣达信工装 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 广州展览制作|展台制作工厂|展览设计制作|展览展示制作|搭建制作公司 | 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | 酒水灌装机-白酒灌装机-酒精果酒酱油醋灌装设备_青州惠联灌装机械 | 大功率金属激光焊接机价格_不锈钢汽车配件|光纤自动激光焊接机设备-东莞市正信激光科技有限公司 定制奶茶纸杯_定制豆浆杯_广东纸杯厂_[绿保佳]一家专业生产纸杯碗的厂家 | 广西资质代办_建筑资质代办_南宁资质代办理_新办、增项、升级-正明集团 | 波纹补偿器_不锈钢波纹补偿器_巩义市润达管道设备制造有限公司 | 智能楼宇-楼宇自控系统-楼宇智能化-楼宇自动化-三水智能化 |