This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Floating Point Exception in Integer Math?


Jeffrey Walton <noloader@gmail.com> 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]