当前位置:网站首页>浮点数表示法(总结自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其实不是真实的数字,只是我们看待问题的角度不同(大意)
边栏推荐
- 基于QingCloud的地理信息企业研发云解决方案
- 基于单片机开发的酒精浓度测试仪方案
- 基于QingCloud的 “房地一体” 云解决方案
- 双指针模拟
- Liunx change the port number of vsftpd
- SLAM14讲中Sophus包的安装问题
- 用VNC Viewer的方式远程连接无需显示屏的树莓派
- Solving linear equations with MATLAB ax=b
- Alibaba Senior Software Testing Engineer recommends testers to learn -- Introduction to security testing
- MySQL | 视图《康师傅MySQL从入门到高级》笔记
猜你喜欢

MySQL | 存储《康师傅MySQL从入门到高级》笔记

A tip to read on Medium for free

Digital cloud released the 2022 white paper on digital operation of global consumers in the beauty industry: global growth solves marketing problems

Linux (centos7.9) installation and deployment of MySQL Cluster 7.6

Opencv maximum filtering (not limited to images)

What is graph neural network? Figure what is the use of neural networks?

Telnet port login method with user name for liunx server

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

JS to find and update the specified value in the object through the key

China chip Unicorn Corporation
随机推荐
MySQL | store notes of Master Kong MySQL from introduction to advanced
tcpdump抓包实现过程
【MySQL从入门到精通】【高级篇】(一)字符集的修改与底层原理
Ordinary people have no education background. Can they earn more than 10000 yuan a month by Self-taught programming?
双指针模拟
"I can't understand Sudoku, so I choose to play Sudoku."
4275. Dijkstra序列
2138. 将字符串拆分为若干长度为 k 的组
The form image uploaded in chorme cannot view the binary image information of the request body
Data middle office: middle office practice and summary
开源之夏中选名单已公示,基础软件领域成为今年的热门申请
【牛客】HJ1 字符串最后一个单词的长度
玄铁E906移植----番外0:玄铁C906仿真环境搭建
What is SRE? A detailed explanation of SRE operation and maintenance system
Fast and slow pointer series
[redis realize Secondary killing Business ①] Overview of Secondary killing Process | Basic Business Realization
Database migration from PostgreSQL to MySQL
MySQL | view notes on Master Kong MySQL from introduction to advanced
KaFormer个人笔记整理
China chip Unicorn Corporation