Hi Charles, On Mon, 2008-09-01 at 13:44 -0700, Charles Day wrote: > On Mon, Sep 1, 2008 at 1:09 PM, Andreas Köhler <[EMAIL PROTECTED]> > 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.
I would rather say that you can extract signs from nominators as well as denominators and put them in front of the fraction. So -(1/3) == (-1)/3 == 1/(-3) and 1/3 == (-1)/(-3). So the change is probably even easier :) But even reversing signs can result in overflows (in a signed one-byte integer, -128 may be allowed, whereas 128 is not). You were probably thinking in negative powers, because (1/3)^(-1) == 3/1 == 3. I just hope I did not talk gibberish :) Ciao, -- andi5
signature.asc
Description: This is a digitally signed message part
_______________________________________________ gnucash-devel mailing list [email protected] https://lists.gnucash.org/mailman/listinfo/gnucash-devel
