如何添加和减去16位浮点半精度数字? [英] How to add and subtract 16 bit floating point half precision numbers?

查看:141
本文介绍了如何添加和减去16位浮点半精度数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加和减去16位浮点半精度数字?

How do I add and subtract 16 bit floating point half precision numbers?

说我需要加或减:

1 10000 0000000000

1 10000 0000000000

1 01111 1111100000

1 01111 1111100000

2的补码形式.

推荐答案

假设您使用的是与IEEE单/双精度类似的非规范化表示形式,只需计算符号=(-1)^ S,尾数为1如果E!= 0则为.M,如果E == 0则为0.M,并且指数= E-2 ^(n-1),则对这些自然表示进行运算,然后转换回16位格式.

Assuming you are using a denormalized representation similar to that of IEEE single/double precision, just compute the sign = (-1)^S, the mantissa as 1.M if E != 0 and 0.M if E == 0, and the exponent = E - 2^(n-1), operate on these natural representations, and convert back to the 16-bit format.

sign1 = -1 尾数1 = 1.0 指数1 = 1

sign1 = -1 mantissa1 = 1.0 exponent1 = 1

sign2 = -1 尾数2 = 1.11111 exponent2 = 0

sign2 = -1 mantissa2 = 1.11111 exponent2 = 0

总和: 符号= -1 尾数= 1.111111 指数= 1

sum: sign = -1 mantissa = 1.111111 exponent = 1

表示形式:1 10000 1111110000

Representation: 1 10000 1111110000

自然地,这假设对指数进行过多编码.

Naturally, this assumes excess encoding of the exponent.

这篇关于如何添加和减去16位浮点半精度数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆