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

查看:161
本文介绍了安静的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天全站免登陆