AUDIT: r17421 - gnucash/trunk/lib/libqof/qof - Add a new function to the gnc_numeric library that converts denominators to exact powers of ten.
Charles Day
cedayiv at gmail.com
Tue Sep 2 16:58:08 EDT 2008
On Mon, Sep 1, 2008 at 2:39 PM, Andreas Köhler <andi5.py at gmx.net> wrote:
> Hi Charles,
>
> On Mon, 2008-09-01 at 14:24 -0700, Charles Day wrote:
> > On Mon, Sep 1, 2008 at 1:57 PM, Christian Stimming <stimming at tuhh.de>
> > wrote:
> > 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.
> >
> > The gnc-numeric.c code seems to assume that only the numerator is
> > needed to determine sign. For example, gnc_numeric_positive_p() and
> > gnc_numeric_negative_p() only check the sign of the numerator.
> >
> >
> >
> > For sure negative numbers will and must never suddently turn
> > into the inverse
> > of a number. Negative != inverted. Really. Always.
> >
> > There are several mentions of "reciprocal" in gnc-numeric.c comments,
> > referring to a negative denominator. See gnc_numeric_compare() and
> > gnc_numeric_equal(), for example. They seem to be doing what I
> > suggested, i.e. 5/-3 == 15/1.
>
> Indeed. There is also a documentation for the macro
> GNC_DENOM_RECIPROCAL. Rest assured that I profoundly dislike this
> "design choice". Fortunately, it does not seem to be in use (a lot).
> If possible, let us kill it, please.
>
I see that src/engine/test/test-numeric.c does tests to prove that the
reciprocal behavior is working. Hard to tell if that functionality is used
anywhere else though. But I found the following notes in ChangeLog.2006:
2006-02-04 05:37 chris
* [r13090] trunk/src/engine/test/test-numeric.c: Add some
test-cases for gnc_numerics using the reciprocal denominator.
Even though we don't explicitly ask for this representation,
certain calculations (e.g. those involving GNC_HOW_DENOM_SIGFIGS
in the loan druid and soon in budgets) will return numbers using
this representation. Unfortunately, these numbers aren't handled
correctly by most of the gnc_numeric functions, like the ones
for comparison, equality testing, arithmetic and conversion.
So it seems that the loan druid and budgets may unknowingly rely on
reciprocals.
>
> Ciao,
> -- andi5
>
>
>
Cheers,
Charles
More information about the gnucash-devel
mailing list