Re: Floating Point Exception in Integer Math?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeffrey Walton <noloader@xxxxxxxxx> writes:

> I'm testing signed int32 operations (division, modular reduction, and
> overflow), and came across a floating point exception:
>
> 	int32_t aa = INT32_MIN;
> 	int32_t bb = -1;
> 	int32_t rr = aa % bb;
>
> 	cout << rr << " = " << aa << " % " << bb << endl;
>
> There's not much to the command line: `g++ sitest.cpp -o sitest.exe`.
> I was kind of surprised GCC [silently] moved from the integer domain
> to the floating point domain.
>
> Is this expected behavior?

Yes.

The kernel will raise a SIGFPE signal for the case you show, and also
for integer division by zero.  No actual floating point operations are
occurring, it's just how the kernel reports the problem.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux