AUDIT: r17421 - gnucash/trunk/lib/libqof/qof - Add a new function to the gnc_numeric library that converts denominators to exact powers of ten.

Christian Stimming stimming at tuhh.de
Mon Sep 1 16:57:09 EDT 2008


Am Montag, 1. September 2008 22:44 schrieb Charles Day:
> > > +  fraction = converted_val.denom;
> > > +  if (fraction <= 0)
> > > +    return FALSE;
> >
> > out of curiosity, what is the reason for disallowing negative
> > denominators?

My immediate reaction to this question: Denominators should be positive so 
that a comparison of equal numbers gives predictable results, and also to 
avoid any confusion about the actual meaning of a negative denominator.

> > I am not sure whether there is a gnc_numeric API function 
> > to switch signs of nom and denom safely, but I am sure that doing it is
> > possible :-) But maybe the current behavior is actually desired.
>
> Honestly, I'm not 100% sure what negative denominators mean. The function I
> added is essentially a modified version of is_decimal_fraction() from
> app-utils/gnc-ui-utils.c, and since negative denominators were not
> considered decimal numbers there, I did the same.
>
> On the other hand, I believe that a negative denominator of -3 may actually
> mean a denominator equal to 1/3. So if a gnc_numeric of 5/-3 is equal to
> 5/(1/3), then that is also equal to 5*3=15.

Uh oh? No, not at all, please. A negative denominator must mean at most that 
the sign of the rational number is changed from positive to negative, or, if 
the numerator is negative as well, the sign of the number is changed from 
negative to positive. No more, no less. As this doesn't make much sense, it 
is sensible to restrict the denominator to positive numbers only.

For sure negative numbers will and must never suddently turn into the inverse 
of a number. Negative != inverted. Really. Always.

Or did I miss anything here?

Regards,

Christian


More information about the gnucash-devel mailing list