I have a simple C program that computes (1e200)^2, which should cause a floating-point overflow exception since the largest double
is 1e308 or so.
double square(double x){
return x*x;
}
int main(){
double x = 1e200;
double y= square(x);
}
My questions are:
(1) How can you capture the exception via a command line, in such a way that when running the program, the exception can be printed out to the terminal?
(2) How can you capture the exception through injecting additional statements that print out the floating-point exception signal during program execution? For the sake of generality, I would prefer not to use y==inf
to achieve this goal.
Thanks.