- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个巨大的项目(不是我构建的),允许具有 Infinity
和 NaN
值。虽然这是允许的,但这是不可取的。我read这些值是由此类操作生成的:
1/0 = ∞
log (0) = -∞
sqrt (-1) = NaN
除此之外,当达到它们时,应该抛出 FP 异常
。
如果我的项目允许使用 NaN
和 Infinity
进行操作,我认为 SIGFPE
会在某个地方处理,但我搜索了整个项目但找不到它。
还有其他方法可以禁用此异常吗?我的目标是能够检测到此类值的第一次出现。
编辑:我使用的是 Windows,我打算启用该信号,但在启用之前,我想了解它是否被禁用。
最佳答案
我认为您不会遇到您所谈论的问题。默认情况下,不会引发 FP 异常。从 Windows documentation :
By default, the system has all FP exceptions turned off. Therefore, computations result in NAN or INFINITY, rather than an exception. Before you can trap floating-point (FP) exceptions using structured exception handling, you must call the
_controlfp_s
C run-time library function to turn on all possible FP exceptions. To trap only particular exceptions, use only the flags that correspond to the exceptions to be trapped. Note that any handler for FP errors should call_clearfp
as its first FP instruction. This function clears floating-point exceptions.
GCC 也是如此,其中 documentation说:
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception [...]). Your program can check the status word to find out which exceptions happened.
要在 Windows 环境中启用异常(这将停止程序的执行),您可以尝试类似的操作
#include <float.h>
int main() {
_clearfp();
unsigned int current_word = 0;
_controlfp_s(¤t_word, ~_EM_ZERODIVIDE, _MCW_EM);
double div = 0.;
double f = 1. / div;
}
对于非阻塞解决方案,请尝试使用 fenv.h
,如所述 here在 cppreference.com 上。
关于c - 使用 Infinity 和 NaN 禁用异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53225506/
如果我们看一下 C 语言的委员会草案:n1570尤其是关于复杂数学函数行为的 Annex G,我们可以看到复指数在无穷大处具有以下行为: cexp(+infinity+I*infinity)=+/-i
有人可以向我解释一下这是如何工作的吗?在查找最高数方法中,每个数字都大于 -Infinity。为什么它取最高数?与最小数字查找器相同,它如何选择最小数字,所有数字都小于 Infinity。 //fin
我想测试无穷大是否等于Java中的无穷大: Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY 当结果证明是真的时,我感到很惊讶。我的问题是两个无
我正在研究 JavaScript 的数字类型系统。 我正在使用 Chrome,当我为一个数字文字计算 15-- 时,我得到了一个 ReferenceError,因为递减一个常量是没有意义的。 当我按预
如果 Infinity === Infinity >> true 和 typeOf Infinity >> "number" 那是为什么 Infinity / Infinity >>NaN 而不是 1
问题很简单: Infinity == Infinity >> true Infinity == 1/0 >> true Infinity == Infinity == 1/0 >> false 为什么
据我所知,在数学中 Infinity 和 NaN 都是模糊值。众所周知: console.log(NaN == NaN); //-> false 同时 console.log(Infinity==In
我正在尝试创建一个选择查询,并过滤一个等于“无穷大”和“-无穷大”的日期时间字段: SELECT * FROM mytable WHERE dt = OR dt = 我该怎么做? 最佳答案 SEL
在一种情况下,我们必须在 Postgres 数据库中存储 +infinity 和 -infinity 的值? 应该考虑什么是合适的值? 如果没有,请提出最合适的替代方案。 最佳答案 您实际上可以将 +
这个问题在这里已经有了答案: Why is pow(-infinity, positive non-integer) +infinity? (1 个回答) 关闭4年前。 我尝试了两种不同的方法在 Ja
C99 附件 F(IEEE 浮点支持)是这样说的: pow(−∞, y) returns +∞ for y > 0 and not an odd integer. 但是,比方说,(−∞)0.5 实际上
在数学中,2 个无穷大既不等于,也不大于或小于 then。那么是什么给了? 在 irb 中,Float::INFINITY == Float::INFINITY(在 ruby 1.9.3 中测试)
文字未呈现在应用程序的主页上,这是我遇到问题的地方。我是新手,因此是新手。希望有人可以提供一些见解,或者根据我遇到的错误调整代码。 为了进一步说明,当我启动“ flutter ”时将显示此页面。将显示
为什么会这样: 1 === 1;// true 0 === -0;// true 1/0 === 1/-0;// false 原因: 1/0=Infinite; 1/-0=-Infinite; 问题:
我一直在试验冒泡排序代码,因为我最近开始了解 C 代码。但是,我无法将 NAN 输入到代码中,以便在构建和运行它时打印出来。我在使用 INFINITY AND -INFINITY 时遇到了同样的问题。
我使用 ANSI C89(不是 C++),我想生成 NaN、-Infinity 和 +Infinity。 有没有标准的方法(例如标准宏)?或者是否有任何独立于平台和编译器的方法来生成这些数字? flo
VB6 似乎并没有让将 +infinity、-infinity 和 NaN 存储到双变量中那么容易。如果可以的话,这会有所帮助,这样我就可以在复数的上下文中与这些值进行比较。如何? 最佳答案 一些不同
使这两个函数对于值 infinity 和 -infinity 表现不同的原因可能是什么。有没有人发现这种不一致有用? parseInt(Infinity); // NaN parseFloat(Inf
npc_objects = {}; TURKEYLENGTH = (Math.max.apply(Math, Object.keys(npc_objects))) + 1; console.log
我正在尝试制作一个程序,用莱布尼兹方程作为 pi 日的属性来估计 pi,但是控制台没有打印出我想要的估计 pi 值,而是无限次打印“无穷大”,直到我终止执行。我非常非常困惑,需要帮助!代码: im
我是一名优秀的程序员,十分优秀!