当前位置:网站首页>IEEE754标准中的4种舍入模式
IEEE754标准中的4种舍入模式
2022-06-11 22:32:00 【luoganttcc】
一、前言
最近在写一个基于IEEE754标准的浮点加法器,其中有一项要求就是要满足IEEE754标准的四种舍入模式。
我们在进行对阶或者右规格化的时候,阶数较小的操作数在进行右移的时候,会造成尾数部分的低位丢失,从而会造成误差。因此我们才需要根据需求,采取四种舍入模式中的一种对尾数进行舍入操作以减少误差。
二、IEEE754标准中的4种舍入模式
1、就近舍入:
即十进制下的四舍五入。但是也会出现以下几种情况:
- 多余数字是1001,它大于0.5,故最低位进1。
- 多余数字是0111,它小于0.5,则直接舍掉多余数字。
- 多余数字是1000,正好是等于0.5的特殊情况;那么此时最低位为0则舍掉多余位,最低位为1则进位1。
注意这里说明的数位都是指二进制数。因为这是尾数,所以在计算这些二进制和0.5的关系的时候,也即转为10进制的时候,我们用每一位的权重乘以2^(-i)然后求和即可。
2、朝0舍入:即朝数轴零点方向舍入,所以我们直接截尾即可。
3、朝正无穷舍入:对正数而言,多余位全为0则直接截尾,不全为0则向最低有效位进1;负数的话不管多余位是多少直接截尾即可。
4、朝负无穷舍入:对负数而言,多余位全为0则直接截尾,不全为0则向最低有效位进1;正数的话不管多余位是多少直接截尾即可。
三、举例
要求保留小数点后3位
1、就近舍入:
对于1.001_1001,舍入处理后为1.010(去掉多余的4位,加0.001)
对于1.001_0111,舍入处理后为1.001(去掉多余的4位)
对于-1.001_1000,舍入处理后为-1.010(去掉多余的4位,加0.001,因为此时最低位为1)
对于-1.010_1000,舍入处理后为-1.010(直接去掉多余的4位,因为此时最低位为0)
2、朝0舍入:
//正数直接截尾
对于1.001_1001,舍入处理后为1.001(直接去掉多余的4位)
对于1.001_0111,舍入处理后为1.001(直接去掉多余的4位)
//负数直接截尾
对于-1.001_1000,舍入处理后为-1.001(直接去掉多余的4位)
对于-1.010_1000,舍入处理后为-1.010(直接去掉多余的4位)
3、朝正无穷舍入:
//正数多余位不全为0进位1
对于1.001_1001,舍入处理后为1.010(去掉多余的4位,加0.001)
对于1.001_0111,舍入处理后为1.010(去掉多余的4位,加0.001)
//正数多余位全为0直接截尾
对于1.001_0000,舍入处理后为1.001(直接去掉多余的4位)
//负数直接截尾
对于-1.001_1010,舍入处理后为-1.001(直接去掉多余的4位)
4、朝负无穷舍入:
//正数直接截尾
对于1.001_1001,舍入处理后为1.001(直接去掉多余的4位)
对于1.001_0111,舍入处理后为1.001(直接去掉多余的4位)
//负数多余位全为0直接截尾
对于-1.001_0000,舍入处理后为-1.001(直接去掉多余的4位)
//负数多余位不全为0进位1
对于-1.001_1010,舍入处理后为-1.010(去掉多余的4位,加0.001)
边栏推荐
- 剑指offer数组题型总结篇
- 【Uniapp 原生插件】商米钱箱插件
- Php+mysql library management system (course design)
- 机器学习之Logistic回归简单实例
- Exercise 8-8 judging palindrome string (20 points)
- astra pro双目相机ros下启动笔记
- 926. flip string to monotonic increment
- 被忽略的技巧:位运算
- What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)
- [uniapp native plug-in] shangmi cashbox plug-in
猜你喜欢

Maze problem in C language

Lecture de l'article dense Visual SLAM for RGB - D Cameras

Inner join execution plan changed

0-1 knapsack problem of dynamic programming (detailed explanation + analysis + original code)

Matplotlib和tkinter学习笔记(一)
![[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials](/img/64/683a190d14406a9971edd79037cc97.jpg)
[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials

图的基本操作(C语言)

5.学城项目 支付宝支付

Introduction to MySQL transactions
![[Yu Yue education] Yancheng Normal University Advanced Algebra reference](/img/3f/cd7f6f420fb1d453acca9aa73665ba.jpg)
[Yu Yue education] Yancheng Normal University Advanced Algebra reference
随机推荐
Implementation of sequencelist sequence table
STM32 development note 113:ads1258 drive design - reading temperature value
Sword finger offer array question type summary
Why is the printer unable to print the test page
Exercise 11-3 calculate the longest string length (15 points)
Neglected technique: bit operation
Maze problem in C language
每日一题-1317. 将整数转换为两个无零整数的和
Unity中使用调用Shell的命令行
习题6-2 使用函数求特殊a串数列和 (20 分)
3.2 测试类的命名规则
Start notes under the Astro Pro binocular camera ROS
Bit operation in leetcode
[uniapp native plug-in] shangmi cashbox plug-in
SVN本地部署server和cleint 并用阿里云盘自动备份
Exercise 6-6 using a function to output an integer in reverse order (20 points)
5.学城项目 支付宝支付
3.3 naming rules of test modules
Exercise 9-6 statistics of student scores by grade (20 points)
启牛推荐开通的证券账户安全吗?靠谱吗