Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » FP exception vs NaN
Re: Capture division by zero [message #55275 is a reply to message #55273] |
Tue, 27 October 2020 09:23   |
 |
mirek
Messages: 14256 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Fri, 16 October 2020 09:15I would like to capture floating point errors.
For now in case of error the program execution follows, but you can find in the doubles, things like INF or NAN.
This behaviour is very conservative for my apps, and I'd prefer in some situations to capture these situations stopping the execution.
I have tried it unsuccessfully using:
- signal(SIGFPE, ...)
- _controlfp_s()
- _set_se_translator()
Any help will be acknowledged!
PD. Somebody could say "just check that all data is adequate before using it in division, sqrt, ...". That's true, but difficult and cumbersome in some situations using uncontrolled data sources where sometimes even doing lots of "if" to check the consistency of data, that's not enough.
Ah, that explains it. So you have like 2 weeks of experience with this issue 
I was all hurray 3 years ago into catching all FP exceptions and avoiding all NaNs. Not so sure today....
Just consider this: Historically, FP exceptions were default and always active, divide by zero or negative sqr always stopped the code just like dereferencing NULL. Then IEEE basically replaced this behaviour with NaNs as default. Maybe they knew something? 
If you want a very simple contraexample where NaN is definitely better, look at this:
https://www.codeproject.com/Articles/1074135/Evaluating-expr ession-with-descend-parser-and-Uplu
Mirek
|
|
|
 |
|
FP exception vs NaN
By: koldo on Mon, 26 October 2020 21:08
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 09:23
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 11:09
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 11:16
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 11:38
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 11:40
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 11:36
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 17:18
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 18:52
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 19:19
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 19:25
|
 |
|
Re: Capture division by zero
By: Klugier on Tue, 27 October 2020 20:35
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 20:47
|
 |
|
Re: Capture division by zero
By: koldo on Wed, 28 October 2020 09:29
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 20:50
|
 |
|
Re: Capture division by zero
By: koldo on Wed, 28 October 2020 09:24
|
 |
|
Re: Capture division by zero
By: mirek on Wed, 28 October 2020 13:51
|
 |
|
Re: Capture division by zero
By: mirek on Wed, 28 October 2020 14:04
|
 |
|
Re: Capture division by zero
By: koldo on Thu, 29 October 2020 14:19
|
 |
|
Re: Capture division by zero
By: mirek on Mon, 02 November 2020 10:31
|
 |
|
Re: Capture division by zero
By: koldo on Mon, 02 November 2020 18:07
|
Goto Forum:
Current Time: Wed Apr 30 00:45:41 CEST 2025
Total time taken to generate the page: 0.00920 seconds
|