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

Andreas Köhler andi5.py at gmx.net
Mon Sep 1 17:08:20 EDT 2008


Hi Christian,

On Mon, 2008-09-01 at 22:57 +0200, Christian Stimming 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.

I understand that negative denominators might look bewildering to some,
but given the current API, one can _create(5, -1) such a number,
_check() it and get an _OK.  If there is a really made such a
distinction in the other functions, then I guess a comment would be nice
and appropriate conversion in _create almost necessary.

Just my 2¢.


> 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?

I do not hope so :)

Ciao,
-- andi5

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20080901/c9e89b1d/attachment.bin 


More information about the gnucash-devel mailing list