On Thu, Nov 7, 2013 at 7:26 PM, Joseph S. Myers <jos...@codesourcery.com> wrote:
> On Thu, 7 Nov 2013, Uros Bizjak wrote:
>
>> Please note that following code form fenv.c won't generate overflow
>> exception on x87:
>>
>>   if (excepts & FP_EX_OVERFLOW)
>>     {
>>       volatile float max = __FLT_MAX__;
>>       r = max * max;
>>     }
>
> r being volatile is intended to ensure that the result does get stored
> back to memory, and so in particular that a result computed with excess
> precision gets converted back to float and the exception is raised.

--cut here--
#define _GNU_SOURCE
#include <fenv.h>

int main(void) {
    feenableexcept(FE_INVALID   |
                   FE_DIVBYZERO |
                   FE_OVERFLOW  |
                   FE_UNDERFLOW);

    volatile float a = __FLT_MAX__, b = __FLT_MAX__;
    volatile float c = a*b;

    return 0;
}
--cut here--

[uros@localhost test]$ gcc -lm -g fpex.c
[uros@localhost test]$ ./a.out
Floating point exception (core dumped)
[uros@localhost test]$ gcc -lm -g -m32 fpex.c
[uros@localhost test]$ ./a.out
[uros@localhost test]$

Uros.

Reply via email to