diff options
author | Thomas White <taw@physics.org> | 2021-07-23 12:50:48 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-07-23 12:50:48 +0200 |
commit | 4fbe2e349908a53032b3f23c2180a46e4f770c92 (patch) | |
tree | 5157bb0b63f273a00cf995e82a0cdce3494b5817 /libcrystfel/src | |
parent | d877680fd03083a696ee5c6a23d7c6b67b36a0e8 (diff) |
rtnl_add: Don't use rational type for intermediate result
It's confusing and unnecessary.
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/rational.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libcrystfel/src/rational.c b/libcrystfel/src/rational.c index db02ee93..2cedf246 100644 --- a/libcrystfel/src/rational.c +++ b/libcrystfel/src/rational.c @@ -140,19 +140,20 @@ Rational rtnl_div(Rational a, Rational b) Rational rtnl_add(Rational a, Rational b) { - Rational r, trt1, trt2; + Rational r; + long long int common_den; + long long int a_num, b_num; - trt1.num = a.num * b.den; - trt2.num = b.num * a.den; - check_overflow(trt1.num, a.num, b.den); - check_overflow(trt2.num, b.num, a.den); + a_num = a.num * b.den; + b_num = b.num * a.den; + check_overflow(a_num, a.num, b.den); + check_overflow(b_num, b.num, a.den); - trt1.den = a.den * b.den; - trt2.den = trt1.den; - check_overflow(trt1.den, a.den, b.den); + common_den = a.den * b.den; + check_overflow(common_den, a.den, b.den); - r.num = trt1.num + trt2.num; - r.den = trt1.den; + r.num = a_num + b_num; + r.den = common_den; squish(&r); return r; } |