From: Techentin, R. W. <tec...@ma...> - 2005-10-04 12:36:51
|
Arjen Markus wrote: > > In general what should happen if a mathematical function is > to be evaluated for a set of argument for which it is not defined? > > In this case, the bug is that there is a division by zero and > this is reported as such, rather than as a clearer message > that the coefficient of variation is not defined if the mean > of the data is zero. > > My question: > - Should the function return such a (clearer) message or > - Should it return an empty string (not an error) thereby > leaving it to the caller to handle the _undefined_ > situation I would vote for the error, but a more descriptive error. In this case, mean!=0 is much like a precondition. This function won't work unless the assertion is true. The caller can choose to pre-check this condition or catch errors, or do nothing, and get the error. If you don't generate an error, and silently return "", then the typical application program will just have an error some time later in a numeric comparison or expression. And that will be -really- cryptic. Bob -- Bob Techentin tec...@ma... Mayo Foundation (507) 538-5495 200 First St. SW FAX (507) 284-9171 Rochester MN, 55901 USA http://www.mayo.edu/sppdg/ |