...
Many math errors can be prevented by carefully bounds - checking the arguments before calling functions, and taking alternative action if the bounds are violated. In particular, the following functions should be bounds checked as follows:
...
However, for some functions it is not practical to use bounds - checking to prevent all errors. In the above pow
example, the bounds check does not prevent the pow(10., 1e6)
range error. In these cases detection must be used, either in addition to bounds checking or instead of bounds checking.
...
This code only performs bounds - checking on x
and y
. It prevents domain errors and some range errors, but does not prevent range errors where the result cannot be represented as a double
(see the Error Checking and Detection section below regarding ways to mitigate the effects of a range error).
...
It is best not to check for errors by comparing the returned value against HUGE_VAL
or 0
for several reasons:
- these These are in general valid (albeit unlikely) data values.
- making Making such tests requires detailed knowledge of the various error returns for each math function.
- there There are three different possibilities,
-HUGE_VAL
,0
, andHUGE_VAL
, and you must know which are possible in each case. - different Different versions of the library have differed in their error-return behavior.
...