Division by zero does not throw SIGFPE

南笙酒味 提交于 2019-11-29 05:38:14

For floating point numbers you can change this behavior by setting up FPU control word. Take a look here

You only get a signal if you perform an integer division by zero. For floating point numbers division by zero is well defined.

This is actually explained rather well in the Wikipedia article.

You don't get a signal because the default behavior on most machines is to pollute your data with NaNs (not-a-number) and infinities. You have to enable floating point exceptions, and how you do that is machine specific. Look at the system header fenv.h, if you have one. The function fesettrapenable enables catching floating point exceptions on many machines.

Unfortunately, there is no standard function to turn floating point exceptions handling on.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!