mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* apply patch to use Euclid's algo for gnc_numeric_reduce
more fixes for #95474 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7803 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
7127d3a6fa
commit
2020629a0e
@ -1,3 +1,8 @@
|
||||
2003-01-08 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
* apply patch to use Euclid's algo for gnc_numeric_reduce
|
||||
more fixes for #95474
|
||||
|
||||
2003-01-08 Christian Stimming <stimming@tuhh.de>
|
||||
|
||||
* po/ru.po: Updated very complete (!) Russian translation by
|
||||
|
@ -727,6 +727,33 @@ gnc_numeric_lcd(gnc_numeric a, gnc_numeric b) {
|
||||
* as the output denominator.
|
||||
********************************************************************/
|
||||
|
||||
gnc_numeric
|
||||
gnc_numeric_reduce(gnc_numeric in) {
|
||||
gint64 t;
|
||||
gint64 num = (in.num < 0) ? (- in.num) : in.num ;
|
||||
gint64 denom = in.denom;
|
||||
gnc_numeric out;
|
||||
|
||||
if(gnc_numeric_check(in)) {
|
||||
return gnc_numeric_error(GNC_ERROR_ARG);
|
||||
}
|
||||
|
||||
/* the strategy is to use euclid's algorithm */
|
||||
while (denom > 0) {
|
||||
t = num % denom;
|
||||
num = denom;
|
||||
denom = t;
|
||||
}
|
||||
/* num = gcd */
|
||||
|
||||
/* all calculations are done on positive num, since it's not
|
||||
* well defined what % does for negative values */
|
||||
out.num = in.num / num;
|
||||
out.denom = in.denom / num;
|
||||
return out;
|
||||
}
|
||||
|
||||
#if 0
|
||||
gnc_numeric
|
||||
gnc_numeric_reduce(gnc_numeric in) {
|
||||
|
||||
@ -800,6 +827,7 @@ gnc_numeric_reduce(gnc_numeric in) {
|
||||
out.denom = denom;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************************************************************
|
||||
* double_to_gnc_numeric
|
||||
|
Loading…
Reference in New Issue
Block a user