问题标签 [floating-point-exceptions]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
385 浏览

c# - _controlfp 不会阻止 DivideByZeroException

我用 C# 写了以下几行

Main 方法首先设置控制字。显然我希望 DivideByZeroExceptions 被屏蔽。

执行 _controlfp 后,我希望除以零会返回 NaN。但var b = 5 / a会引发异常。

我如何才能真正防止我的流程引发 DivideByZeroExceptions?

0 投票
1 回答
197 浏览

c++ - 排序函数为大量输入 0 提供浮点异常

我为这个问题写了一个代码:

给定一个非负整数列表,将它们排列成最大的数。

例如,给定 [3, 30, 34, 5, 9],最大的形成数是 9534330。

注意:结果可能非常大,所以需要返回字符串而不是整数。

基本上我在这段代码中试图实现的是首先在最重要的数字上使用基数排序逻辑,然后按照降序排列它。后来我正在做第二个最重要的数字,依此类推。我std::sort()通过传递对的向量来使用函数,其中第一个是值,第二个是索引。以下是我的代码:

largestNumber(..)是我的函数,它返回所需的字符串。现在,此代码适用于我可以尝试的大多数非零输入。但是当输入是一个长的 0 向量时,类似于:

[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ]

它给出了浮点异常。

我已经尝试找到解决方案,但还没有找到。我是cpp的初学者,任何帮助都会很棒。

0 投票
1 回答
451 浏览

floating-point - SSE/AVX 浮点转换异常

假设 SSE 寄存器包含一个或多个不能表示为 32 位 int 的压缩值(例如Infor NaN),并且调用了 convert-to-int ,例如_mm_cvtpd_epi32/ cvtpd2dq

  1. 是否安全,即行为是否已定义?
  2. 它会破坏控制流,还是仅仅举起一个标志?
  3. 如果定义,转换的结果是什么?
0 投票
1 回答
505 浏览

assembly - 汇编 - 收到浮点异常

我正在尝试编写一个计算下载时间的程序,但我一直在输出时收到“浮点异常”错误。感谢任何帮助,因为我已经尝试调试此代码很长一段时间,但根本无法识别问题。在做了一些研究之后,我认为问题在于除法发生的位置,因为商无法放入 eax 寄存器中,但据我所知。

谢谢

0 投票
1 回答
156 浏览

vigenere - Vigenere.c CS50 浮点异常(核心转储)

我正在研究哈佛 CS50 的 Vigenere 练习(以防你注意到我使用的是字符串而不是 str)。

当我在关键字中使用“a”时,我的程序给了我一个浮点异常错误。

它实际上给了我那个错误

  • 当我单独使用“a”时,
  • 当我在一个更大的词中使用“a”时,它只会给我错误的输出。
  • 对于任何其他类型的关键字,该程序都可以正常工作。

我已经进行了一百万次测试。为什么要这样做?我看不到我在哪里除以 0。关键字的长度始终至少为 1。这可能是一个超级简单的错误,但我已经做了大约 10 个小时,我几乎记不住我的名字。

0 投票
2 回答
3994 浏览

c - How to solve undefined reference to functions in fenv.h when using uclibc?

I'm trying to test some of the functions in fenv.h, however, when I compile the below function ld fails with undefined reference to 'feclearexcept' and undefined reference to 'fetestexcept'. I'm running hardened gentoo compiled against uclibc, and I suspect that this is at least somewhat related

fenv.h is in /usr/include. There are static and dynamic libraries (libm.a, libm.so) in /usr/lib. I am compiling with gcc -o test test.c -lm; does anyone have any ideas why the linker can't find the relevant functions. It seems like nothing in fenv.h has a corresponding library.

UPDATE: this decade old blog post seems to suggest that fenv is not supported by uclibc. I cannot determine if this is the case still, but if it were is there anything to be done. http://uclibc.10924.n7.nabble.com/missing-fenv-h-for-qemu-td2703.html

0 投票
0 回答
203 浏览

linux - 对 4 个数字进行加权平均时出现浮点异常 (SIGFPE)

我正在Linux 上使用NASM创建一个汇编语言程序。我正在尝试对 4 个数字进行加权平均,其中输入的第 4 个数字的权重是其他数字的两倍。如果我使用数字 30、40、50、60,我将加权平均值计算为 (30+40+50+60+60)/5。我的代码是:

如果我输入这些数字,我会产生这个异常:

是什么导致我的程序显示浮点异常(SIGFPE),我该如何解决?

0 投票
1 回答
229 浏览

windows-7 - 导致浮点异常“1.#IO”的原因

我正在调试一个在许多 Fortran 文件中进行许多计算的模拟。我习惯于看到一些浮点异常(-1.#QNB 或 1.#QNAN),这些错误涉及除以零或超出浮点数最大大小的操作。我假设 -1.#IO 表示无效操作,但我不确定在数学上是什么导致这种情况,而不是 QNB、QNAN 或 QINF。

什么会导致异常-1.#IO?

0 投票
4 回答
527 浏览

c - 迭代数组元素时获取“浮点异常(核心转储)”

我正在尝试获取前 10 个素数,但在编译时出现浮点异常(核心转储)错误。

}

0 投票
1 回答
67 浏览

c++ - floating point exception when finding intersection

consider this code:

(full code http://pastebin.com/M6G40F4M)

this code causes a floating point exception on lines 3&4 (and 13&14 in the larger code snippet). My question is why does this happen, and what would be the correct way to find where two lines intersect. I know these errors usually occur when dividing by zero but I am not sure where I am doing that and how it could be prevented.