Messages in this thread | | | Date | Thu, 30 Oct 2003 07:53:19 -0500 (EST) | From | "Richard B. Johnson" <> | Subject | RE: Question on SIGFPE |
| |
On Thu, 30 Oct 2003, Sreeram Kumar Ravinoothala wrote:
> Hi, > I tried this. It says that the address is 0. And also I saw that > it doesn't fall into any of the si_codes of SIGFPE. > > Regards > Sreeram >
First, to see if it's an access violation (#GP) or an actual FPE, set the FPU unit to ignore /0 errors. You do it like this:
--------------- /* * Note FPU control only exists per process. Therefore, you have * to set up the FPU before you use it in any program. */ #include <i386/fpu_control.h>
#define FPU_MASK (_FPU_MASK_IM |\ _FPU_MASK_DM |\ _FPU_MASK_ZM |\ _FPU_MASK_OM |\ _FPU_MASK_UM |\ _FPU_MASK_PM)
void fpu() { // __setfpucw(_FPU_DEFAULT & ~FPU_MASK); __setfpucw(_FPU_DEFAULT); }
main() { double zero=0.0; double one=1.0; fpu();
one /=zero; } --------------
With the above code, you can divide by zero with no problem. If you unmask, using the FPU_MASK, you get the divide by zero error.
If your program now "functions", you have a real divide by zero error that may be related to "real-world" data, that was not caught during your initial testing.
If your program still fails, the error is really caused by the FPU attempting to access memory you don't own. Note that all floating-pount numbers exist as memory oprands in Intel stuff. So you could have an out-of-bounds access or, perhaps, a stack- overflow.
Cheers, Dick Johnson Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips). Note 96.31% of all statistics are fiction.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |