安静 NaN 和信号 NaN 有什么区别? [英] What is the difference between quiet NaN and signaling NaN?

查看:34
本文介绍了安静 NaN 和信号 NaN 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关浮点的信息,并且我知道 NaN 可能是由运算产生的.但我不明白这些到底是什么概念.它们有什么区别?

I have read about floating-point and I understand that NaN could result from operations. But I can't understand what these are concepts exactly. What is the difference between them?

在 C++ 编程过程中可以产生哪一个?作为程序员,我可以编写一个导致 sNaN 的程序吗?

Which one can be produced during C++ programming? As a programmer, could I write a program that causes an sNaN?

推荐答案

当操作导致安静的 NaN 时,在程序检查结果并看到 NaN 之前,没有任何迹象表明有任何异常.也就是说,如果浮点是在软件中实现的,那么在没有来自浮点单元 (FPU) 或库的任何信号的情况下继续计算.一个信号 NaN 将产生一个信号,通常以来自 FPU 的异常的形式.是否抛出异常取决于FPU的状态.

When an operation results in a quiet NaN, there is no indication that anything is unusual until the program checks the result and sees a NaN. That is, computation continues without any signal from the floating point unit (FPU) or library if floating-point is implemented in software. A signalling NaN will produce a signal, usually in the form of exception from the FPU. Whether the exception is thrown depends on the state of the FPU.

C++11 添加了一些语言对浮点环境的控制 并提供 创建和测试 NaN 的标准化方法.但是,控件是否实现没有很好的标准化,浮点异常通常不会像标准 C++ 异常那样被捕获.

C++11 adds a few language controls over the floating-point environment and provides standardized ways to create and test for NaNs. However, whether the controls are implemented is not well standardized and floating-point exceptions are not typically caught the same way as standard C++ exceptions.

在 POSIX/Unix 系统中,浮点异常通常使用 SIGFPE.

In POSIX/Unix systems, floating point exceptions are typically caught using a handler for SIGFPE.

这篇关于安静 NaN 和信号 NaN 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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