简体   繁体   English

将IEEE754转换为自定义浮点表示

[英]Converting IEEE754 to custom floating point representation

Just looking for suggestions, how should the IEEE754 single precision floating point representation ie the following: 仅寻找建议, IEEE754单精度浮点表示应如何,即以下内容:

-1 sign ∗ 2 exponent-127 ∗ 1.mantissa 2 -1 ∗ 2 指数-127 ∗ 1.尾数2

where the hidden bit worth is 1.0 , be accurately and efficiently converted to a custom floating point representation format like the following: 其中隐藏位的价值为1.0 ,可以准确有效地转换为自定义浮点表示格式,如下所示:

-1 sign ∗ 2 exponent-128 ∗ 0.1mantissa 2 -1 ∗ 2 指数 -128 ∗ 0.1尾数2

where the hidden bit worth is 0.5 隐藏的价值为0.5

I do not intend to delegate the work to someone to do this work for me but mostly looking for suggestions on how to do it in the right and most accurate way. 我无意将工作委托给某人来为我完成这项工作,而是主要是寻求有关如何以正确且最准确的方式进行工作的建议。

The bits that represent some value x in the first scheme represent x /4 in the second scheme. 在第一种方案中代表某个值x的位在第二种方案中代表x / 4。 So, clearly, to represent x in the second scheme, one normally increases the exponent by two. 因此,很显然,为了在第二种方案中表示x ,通常将指数增加2。 Then there are just the abnormal cases to deal with: 然后,只有异常情况需要处理:

  • If the exponent is 255, the object is infinity or NaN. 如果指数为255,则对象为无穷大或NaN。 Return it unchanged. 退回原样。
  • If the exponent is 253 or 254, it cannot be increased by two, so the result is infinity. 如果指数是253或254,则不能将其增加2,因此结果是无穷大。
  • If the exponent is 0, the number is subnormal. 如果指数为0,则该数字为次正规数。 If two high bits of the significand field are 00, simply shift the significand left two bits. 如果有效位字段的两个高位为00,则只需将有效位左移两位。 Otherwise, if the bits are 01, shift the significand left two bits (discarding the shifted-out bits) and set the exponent to 1. Otherwise, shift the significand left one bit and set the exponent to 2. 否则,如果位为01,则将有效位左移两位(丢弃移出的位)并将指数设置为1。否则,将有效位左移一位并将指数设置为2。
  • Otherwise, add two the exponent. 否则,将两个指数相加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM