[Gnucash-changes] r13919 - gnucash/trunk/src/engine/test-core - Correctly ensure that the amount and value of test Splits have the same sign

Chris Shoemaker c.shoemaker at cox.net
Fri May 5 17:48:51 EDT 2006


On Fri, May 05, 2006 at 08:50:52AM -0400, Derek Atkins wrote:
> Chris Shoemaker <chris at cvs.gnucash.org> writes:
> 
> > Modified: gnucash/trunk/src/engine/test-core/test-engine-stuff.c
> > ===================================================================
> > --- gnucash/trunk/src/engine/test-core/test-engine-stuff.c	2006-05-04 09:18:39 UTC (rev 13918)
> > +++ gnucash/trunk/src/engine/test-core/test-engine-stuff.c	2006-05-05 00:17:04 UTC (rev 13919)
> > @@ -961,8 +961,7 @@
> >          amt = val;
> >      } else {
> >          gnc_numeric amt2 = xaccSplitGetAmount(s);
> > -        int i = gnc_numeric_positive_p(amt2) + gnc_numeric_positive_p(amt);
> > -        if (i % 2)
> > +        if (gnc_numeric_positive_p(amt2) ^ gnc_numeric_positive_p(val))
> >              amt = gnc_numeric_neg(amt2);
> >      }   
> 
> This seems rather confusing or convoluted.   Why not just run:
> 
>   if (gnc_numeric_positive_p(amt2) != gnc_numeric_positive_p(val))
>    ...
> 
> Are there really multiple bits such that you need to xor?

Hehe.  I agree that '!=' would be fine here, and maybe easier to read.
I suppose some might find it odd that '!=' didn't even occur to me to
use.  I guess there's something ingrained in me to not assume that two
different representations of boolean truth are identical.  Some
programmers seem to write functions that return "true" and then use
any non-zero value they feel like, even returning different values of
"true" in different cases.  Not that I condone such bad bahavior, but
I guess I've learned deal with it.

Hopefully C99's _Bool will eventually make my habit appear obsolete
and paranoid.  (or does glib already #define TRUE ((_Bool)1)?)

-chris


More information about the gnucash-devel mailing list