当前位置:网站首页>浮点数表示法(总结自CS61C和CMU CSAPP)
浮点数表示法(总结自CS61C和CMU CSAPP)
2022-06-24 07:31:00 【只是有点小怂】

总结自伯克利的CS61C2021秋季课程,Nick主讲和CMU2015年讲CS APP的课程,标题均是floating point,相比而言CMU讲得比较详细,我先看了一遍CS61C再看了一遍CMU的课程,点击floating point点击slides可以下载pdf(讲得很详细可以自己看一下,我挑了几张贴出来),课程主页https://inst.eecs.berkeley.edu/~cs61c/fa21/

P&H是课本章节,中文版是计算机组成与设计硬件软件接口RISCV

还有个浮点数网站可以玩一玩https://www.h-schmidt.net/FloatConverter/IEEE754.html

浮点数表示法是伯克利提出的,因为小数点是可以浮动的,降低了精度但是表示范围变大了(Can represent a very large range with roughly the same “precision”),而且希望和整数的补码表示法一致(32个0还是0),并且希望不用对浮点数进行比较就能排序(Make it possible to sort without needing to do floating-point comparisons)
float是单精度32位4字节,double是8字节双精度,先掌握float,float不能表示的就有+∞, -∞, Not-A-Number (NaN), exponent overflow, exponent underflow, +/- zero这么多种特殊情况,能表示的又分为normal format和denorm,最大可表示到 2 127 = 2 120 ∗ 2 7 = 128 ∗ ( 2 10 ) 12 = 128 ∗ 1 0 36 = 2 ∗ 1 0 38 2^{127}=2^{120}*2^7=128*(2^{10})^{12}=128*10^{36}=2*10^{38} 2127=2120∗27=128∗(210)12=128∗1036=2∗1038,根据 2 10 = 1 0 3 2^{10}=10^3 210=103换算得到

偏置计算方法bias = 2 ^ (k - 1) - 1,k 是指数位数,8位指数计算得到bias = 127(正数负数各站一半,bias gives us a balanced value),小数部分可以表示为fraction, F, mantissa, M, significand

先掌握normal format,即1.xxx

denorm format用于表示0附近的数,0.xxx,指数部分为0000_0000,此时小数部分不需要+1,然后指数部分E = 1 - Bias(这一部分CMU讲得比较好,为了实现两种表示方法的平滑过渡,可以用8位数字,指数部分k = 4偏置为7,小数部分为3位),老师当时评论those IEEE folks are really smart

overflow部分指数部分为1111_1111,首先是Inf然后是NaN,NAN通常是sqer(-1)或者0/0,NAN不能比较大小,+INF是1.0/0.0,-INF是-1.0/0.0,INF可以比较大小

浮点数中存在+/- 0,表示太小而不能表示的数字

总结一下

如何比较浮点数,先比较符号位再比较指数(无符号比较,使用偏置可以直接比较大小,如果使用补码不能直接比较大小),最后比较小数部分(指数部分比较重要用于区分数字分布,在数轴上可以看出)

CMU课程中得C代码可以写一下,看下是如何得到NAN和INF的,直接定义a = 1e20,CMU课程中老师讲得好,这些0和1其实不是真实的数字,只是我们看待问题的角度不同(大意)
边栏推荐
- 数据中台:数据中台技术架构详解
- Leetcode -- wrong set
- 【量化投资】离散傅里叶变换求数组周期
- 2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
- Ebanb B1 Bracelet brush firmware abnormal interrupt handling
- 【牛客】HJ1 字符串最后一个单词的长度
- Common emoticons
- Array opposite pointer series
- Floating error waiting for changelog lock
- Alibaba Senior Software Testing Engineer recommends testers to learn -- Introduction to security testing
猜你喜欢

陆奇:我现在最看好这四大技术趋势

开源之夏中选名单已公示,基础软件领域成为今年的热门申请
![[redis realize Secondary killing Business ①] Overview of Secondary killing Process | Basic Business Realization](/img/a3/9a50e83ece43904a3a622dcdb05b3c.png)
[redis realize Secondary killing Business ①] Overview of Secondary killing Process | Basic Business Realization

cookie加密 4 rpc方法确定cookie加密

Qingcloud based "real estate integration" cloud solution

Redis实现全局唯一ID

【LeetCode】387. 字符串中的第一个唯一字符
![[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle](/img/db/e581087e550a2e460f12047685c48f.png)
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle

2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3

What is SRE? A detailed explanation of SRE operation and maintenance system
随机推荐
【PyTorch基础教程30】DSSM双塔模型代码解析
OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集
KaFormer个人笔记整理
Mba-day25 best value problem - application problem
[noi Simulation Competition] send (tree DP)
深入了解 border
4275. Dijkstra序列
数组相向指针系列
基于QingCloud的 “房地一体” 云解决方案
How does the tunnel mobile inspection track robot monitor 24 hours to ensure the safety of tunnel construction?
Redis实现全局唯一ID
A tip to read on Medium for free
[noi simulation] pendulum (linear algebra, Du Jiao sieve)
Qingcloud based "real estate integration" cloud solution
520. 检测大写字母
linux(centos7.9)安装部署mysql-cluster 7.6
数据中台:中台架构及概述
eBanb B1手环刷固件异常中断处理
Lu Qi: I am most optimistic about these four major technology trends
Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR