Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » FP exception vs NaN
Re: Capture division by zero [message #55357 is a reply to message #55316] |
Mon, 02 November 2020 10:31   |
 |
mirek
Messages: 14256 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Thu, 29 October 2020 14:19mirek wrote on Wed, 28 October 2020 14:04I am also pretty interested what will you do when you get exception in eigen. I am not that advanced in math, but I am pretty sure that e.g. matrix inversion can produce a lot of divide by zero for degenerate matrix and I am also pretty sure that eigen follows NaN model like every other mature library (if for nothing else, then for performance reasons).
Are you going to compute determinant before each call to inversion?
Mirek
I am well aware of operations that could be bad conditioned . I use a lot matrix inversion.
In fact STEM4U includes some tools to handle infinite precision numbers (well, but as expected, very inefficiently)
If you ask me if I prefer to search for NaNs after every matrix algebra operation, or catching an exception, I will choose the second.
Now actually catching the exception as part of program logic in release mode (as oppposed to just stopping on NaN in debug), that is completely different thing! I could agree that would be a good solution, except for one nasty tiny detail: you cannot officially catch FP exceptions in C++ (see e.g. https://stackoverflow.com/questions/38221471/how-to-convert- sigfpe-into-a-c-exception). It might be possible on specific platforms / compilers, but I would think twice before making your code reliant on it
All you can realistically do in the handler is to set some per-thread and/or global "fp-error" flag. That frankly does sound quite similar to NaN...
All that said, activating FP exception might have its uses, e.g. when you are getting NaN out of calculation for unknown reasons and you want to track it down.
I just do not think that it is the only valid way. And in my humble experience, insisting that your code never produces NaNs creates much more mess than it solves.
Mirek
[Updated on: Mon, 02 November 2020 10:45] Report message to a moderator
|
|
|
 |
|
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:43:51 CEST 2025
Total time taken to generate the page: 0.01254 seconds
|