当前位置:网站首页>Four rounding modes in IEEE754 standard
Four rounding modes in IEEE754 standard
2022-06-11 22:37:00 【luoganttcc】
One 、 Preface
Recently, I was writing a project based on IEEE754 standard Of floating-point adder , One of the requirements is to meet IEEE754 standard Four rounding modes of .
When we normalize order or right , The operands with smaller order are shifted to the right , It will cause the lower bits of the mantissa to be lost , This will cause errors . That's why we need to meet our needs , One of the four rounding modes is used to round the mantissa to reduce the error .
Two 、IEEE754 Standard 4 Rounding mode
1、 Nearest rounding :
Namely ten Base number Under the rounding . But there are also the following situations :
- The extra number is 1001, It is greater than 0.5, Therefore, the lowest position goes into 1.
- The extra number is 0111, It's smaller than 0.5, Then discard the extra numbers directly .
- The extra number is 1000, Is exactly equal to 0.5 In special circumstances ; Then the lowest order is 0 Then we give up the extra places , The lowest is 1 Then carry 1.
Note that the digits here are binary numbers . Because this is the mantissa , So we are calculating these binary sums 0.5 In a relationship , That is to say 10 When in base , We multiply the weight of each bit by 2^(-i) Then sum up .
2、 the 0 Round off : That is, round to the zero point of the number axis , So let's just cut the tail .
3、 Round to infinity : For positive numbers , All the extra bits are 0 Then cut the tail directly , Not all for 0 Then carry... To the least significant bit 1; Negative numbers, no matter how many extra bits, can be truncated directly .
4、 Round to negative infinity : For negative numbers , All the extra bits are 0 Then cut the tail directly , Not all for 0 Then carry... To the least significant bit 1; If it is a positive number, you can truncate it directly regardless of the number of extra bits .
3、 ... and 、 give an example
After the decimal point is required 3 position
1、 Nearest rounding :
about 1.001_1001, After rounding, it is 1.010( Get rid of the excess 4 position , Add 0.001)
about 1.001_0111, After rounding, it is 1.001( Get rid of the excess 4 position )
about -1.001_1000, After rounding, it is -1.010( Get rid of the excess 4 position , Add 0.001, Because the lowest order is 1)
about -1.010_1000, After rounding, it is -1.010( Just get rid of the excess 4 position , Because the lowest order is 0)
2、 the 0 Round off :
// Positive numbers are truncated directly
about 1.001_1001, After rounding, it is 1.001( Just get rid of the excess 4 position )
about 1.001_0111, After rounding, it is 1.001( Just get rid of the excess 4 position )
// Negative numbers are truncated directly
about -1.001_1000, After rounding, it is -1.001( Just get rid of the excess 4 position )
about -1.010_1000, After rounding, it is -1.010( Just get rid of the excess 4 position )
3、 Round to infinity :
// The extra bits of a positive number are not all 0 carry 1
about 1.001_1001, After rounding, it is 1.010( Get rid of the excess 4 position , Add 0.001)
about 1.001_0111, After rounding, it is 1.010( Get rid of the excess 4 position , Add 0.001)
// All the extra bits of a positive number are 0 Straight tailing
about 1.001_0000, After rounding, it is 1.001( Just get rid of the excess 4 position )
// Negative numbers are truncated directly
about -1.001_1010, After rounding, it is -1.001( Just get rid of the excess 4 position )
4、 Round to negative infinity :
// Positive numbers are truncated directly
about 1.001_1001, After rounding, it is 1.001( Just get rid of the excess 4 position )
about 1.001_0111, After rounding, it is 1.001( Just get rid of the excess 4 position )
// All the extra bits of negative numbers are 0 Straight tailing
about -1.001_0000, After rounding, it is -1.001( Just get rid of the excess 4 position )
// The extra bits of negative numbers are not all 0 carry 1
about -1.001_1010, After rounding, it is -1.010( Get rid of the excess 4 position , Add 0.001)
边栏推荐
猜你喜欢

Tkinter study notes (III)

FastAPI 5 - 常用请求及 postman、curl 使用(parameters,x-www-form-urlencoded, raw)

5. Xuecheng project Alipay payment
Gcache of goframe memory cache

Regular execution of shell scripts in crontab

A simple example of linear regression in machine learning

移动端——swipe特效之图片时间轴
![[Yu Yue education] calculus of Zhejiang University in autumn and winter 2021 (I) reference materials](/img/0a/58df3fd771d58c66245397d131fa53.png)
[Yu Yue education] calculus of Zhejiang University in autumn and winter 2021 (I) reference materials

Simple example of logistic regression for machine learning

遇到表格,手动翻页太麻烦?我教你写脚本,一页展示所有数据
随机推荐
MATLAB点云处理(二十四):点云中值滤波(pcmedian)
Analysis of the implementation principle of an open source markdown to rich text editor
向线程池提交任务
Study notes of mattlotlib and Tkinter (I)
Learn to crawl for a month and earn 6000 a month? Don't be fooled. The teacher told you the truth about the reptile
启牛商学院送华泰账户安不安全?真的吗
Php+mysql library management system (course design)
The device is in use when win10 ejects USB
STM32开发笔记113:ADS1258驱动设计——读取温度值
How to adjust the font blur of win10
Three years of college should be like this
Exercise 9-1 time conversion (15 points)
Stack栈的实现
IEEE浮点数尾数向偶舍入-四舍六入五成双
Matplotlib和tkinter学习笔记(一)
Getting started with message queuing MQ
3.3 naming rules of test modules
Exercise 11-2 find week (15 points)
Message queue MySQL table that stores message data
STM32开发笔记112:ADS1258驱动设计——读寄存器