浮点型NaN有效载荷有什么用途? [英] What uses do floating point NaN payloads have?

查看:145
本文介绍了浮点型NaN有效载荷有什么用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道IEEE 754定义NaN具有以下按位表示:


  • 符号位可以是 0 1

  • 指数字段包含所有 1
  • 尾数的某些位用于指定它是否是一个安静的NaN或信号NaN
  • 尾数不能全部是 0 位,因为该位模式被保留用于表示无穷大

  • 尾数的其余位形成有效载荷


当计算的输入是NaN时,有效载荷被传播(如同整个NaN一样)到浮点计算的结果,尽管我没有了解这种传播的细节或标准是否规定了如何完成。谁设置了原始有效载荷?如果我添加两个具有不同有效载荷的NaN,会发生什么?



但是最重要的是:我以前从来没有见过NaN的有效载荷。这个有效载荷字段有什么用途?

解决方案

当IEEE754和NaN被开发时,这被认为是一个好主意。实际上我已经看到它用来存储NaN创建的原因。

今天,我不会在可移植代码中使用它,原因有几个。你有多确定这个有效载荷能够存活下来,例如一个任务?如果你指定x = y,那你有多确定x和Na有相同的有效载荷?你有多确定它能算算吗?如果a或b是NaN,那么op b应该是一个NaN,或者两个NaN中的一个,如果它们都是NaN的话。当然是这样吗?我不会愿意赌它。

I know that IEEE 754 defines NaNs to have the following bitwise representation:

  • The sign bit can be either 0 or 1
  • The exponent field contains all 1 bits
  • Some bits of the mantissa are used to specify whether it's a quiet NaN or signalling NaN
  • The mantissa cannot be all 0 bits because that bit pattern is reserved for representing infinity
  • The remaining bits of the mantissa form a payload

The payload is propagated (as is the NaN as a whole) to the result of a floating point calculation when the input of the calculation is NaN, though I have no knowledge of the details of this propagation or whether the standard specifies how this is done. Who sets the original payload? What happens if I add two NaNs with different payloads?

But most importantly: I've never seen NaN payloads used before. What uses does this payload field have?

解决方案

It was thought to be a good idea whenIEEE754 and NaN's were developed. I have actually seen it used to store the reason why a NaN was created.

Today, I wouldn't use it in portable code for several reasons. How sure are you that this payload will survive for example an assignment? If you assign x = y, how sure are you that x has the same NaN payload as y? And how sure are you that it will survive arithmetic? If a or b is an NaN, then a op b is supposed to be the one NaN, or one of the two NaNs if they are both NaN. Sure that this is the case? I wouldn't be willing to bet on it.

这篇关于浮点型NaN有效载荷有什么用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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