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

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

问题描述

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

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

  • 符号位可以是 01
  • 指数字段包含所有1
  • 尾数的某些位用于指定它是安静 NaN 还是信号 NaN
  • 尾数不能全部为 0 位,因为该位模式保留用于表示无穷大
  • 尾数的剩余位构成有效载荷
  • 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

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

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?

但最重要的是:我以前从未见过使用过 NaN 有效载荷.这个payload字段有什么用?

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

推荐答案

在开发 IEEE754 和 NaN 的时候被认为是一个好主意.我实际上已经看到它用于存储创建 NaN 的原因.

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

今天,出于几个原因,我不会在可移植代码中使用它.你有多确定这个有效载荷会在例如分配中存活下来?如果您指定 x = y,您有多确定 x 与 y 具有相同的 NaN 有效负载?你有多确定它会在算术中存活下来?如果 a 或 b 是 NaN,则 a op b 应该是一个 NaN,或者如果它们都是 NaN,则应该是两个 NaN 之一.确定是这样吗?我不会愿意打赌.

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天全站免登陆