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
Mon Sep 1 16:44:42 EDT 2008


On Mon, Sep 1, 2008 at 1:09 PM, Andreas Köhler <andi5.py at gmx.net> wrote:

> Hi Charles,
>
> On Sun, 2008-07-27 at 11:33 -0400, Charles Day wrote:
> > Trac: http://svn.gnucash.org/trac/changeset/17421
> > Log:
> > Add a new function to the gnc_numeric library that converts denominators
> to exact powers of ten.
>
> > Modified: gnucash/trunk/lib/libqof/qof/gnc-numeric.c
> > ===================================================================
> > --- gnucash/trunk/lib/libqof/qof/gnc-numeric.c        2008-07-27 15:11:19
> UTC (rev 17420)
> > +++ gnucash/trunk/lib/libqof/qof/gnc-numeric.c        2008-07-27 15:33:23
> UTC (rev 17421)
> > +  fraction = converted_val.denom;
> > +  if (fraction <= 0)
> > +    return FALSE;
>
> out of curiosity, what is the reason for disallowing negative
> denominators?  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. So maybe any gnc_numeric with a
negative denominator could be converted to a decimal number. Perhaps instead
of returning FALSE, the routine could compute num * abs(denom) and return
TRUE. Assuming that the multiplication doesn't cause overflow, and that I
have understood the situation correctly.

Anyway, I think it is OK for the moment, as these types of numbers never
printed decimally in the past. Perhaps Christian could provide more
information on what negative denominators mean, and if/how we could print
them as decimal numbers. If the method I stated above is correct, then I
think it would be a pretty small change to add support for negative
denominators in this routine.


> Ciao,
> -- andi5
>
>
Cheers,
Charles


More information about the gnucash-devel mailing list