[Gnucash-changes] r13248 - gnucash/trunk/src/calculation - Fix
Bug 107876 - financial calculator would call exit(1) if calculation
resulted in an interest rate of zero.
Christian Stimming
stimming at tuhh.de
Mon Feb 13 04:51:25 EST 2006
Hi Neil,
Neil Williams schrieb:
> On Monday 13 February 2006 2:08 am, Derek Atkins wrote:
>
>>Quoting Neil Williams <codehelp at cvs.gnucash.org>:
>>
>>>_C (double eint, double pmt, unsigned beg)
>>>{
>>>- return pmt * _B (eint, beg);
>>>+ unsigned check = _B (eint, beg);
>
>>I'm not convinced this patch is correct. _B() returns a double,
>
> I'm setting up an error state that is perpetuated through the code.
Oh no. This means you are using the code pattern "one special
calculation return value corresponds to an error value". This code
pattern should better be avoided, if at all possible. In this fin.c
case, I don't understand why a different solution isn't possible -- the
_B() function makes a divide-by-"eint", so it is perfectly fine to add
an assertion "assert(eint!=0.0)" there, and require all places that call
_B() to not pass an eint==0.0.
Since _B() is only called from two other places, it shouldn't be
difficult at all to add those required checks *before* calling _B().
There is really no need to check for this "special error value"
afterwards -- simply check for eint==0.0 *before* and all is fine, and
(even more important) everyone will understand this. Either way, you
have to check for that condition, but checking up front is far more
understandable and avoids any data type casts.
The calling function _C() obviously will then have the restriction that
eint must be nonzero as well, and it is called a few more times, but it
shouldn't be too difficult to add these checks to all calling places as
well. Please replace your "returned special error code" by a check for
nonzero-ness up front.
Christian
More information about the gnucash-devel
mailing list