[gnome-calculator] Use double instead of float for better precision ln (fixes bug 702817).
- From: Arth Patel <arthpatel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Use double instead of float for better precision ln (fixes bug 702817).
- Date: Wed, 5 Mar 2014 18:26:26 +0000 (UTC)
commit 6eb0f2b5e6df456a97a796b35d811376a69679e0
Author: Daniel Renninghoff <daniel danielrenninghoff com>
Date: Wed Feb 26 03:02:56 2014 +0100
Use double instead of float for better precision ln (fixes bug 702817).
ln now also works for e^x, where x >= 3.
https://bugzilla.gnome.org/show_bug.cgi?id=702817
src/number.vala | 59 ++----------------------------------------------------
1 files changed, 3 insertions(+), 56 deletions(-)
---
diff --git a/src/number.vala b/src/number.vala
index 6db386e..89b5a01 100644
--- a/src/number.vala
+++ b/src/number.vala
@@ -2103,10 +2103,10 @@ public class Number
/* REMOVE EXPONENT TO AVOID FLOATING-POINT OVERFLOW */
var e = t1.re_exponent;
t1.re_exponent = 0;
- var rx = t1.to_float_old ();
+ var rx = t1.to_double ();
t1.re_exponent = e;
- var rlx = (float) (Math.log (rx) + e * Math.log (BASE));
- t2 = new Number.float (-(float)rlx);
+ var rlx = Math.log (rx) + e * Math.log (BASE);
+ t2 = new Number.double (-rlx);
/* UPDATE Z AND COMPUTE ACCURATE EXP OF APPROXIMATE LOG */
z = z.subtract (t2);
@@ -2120,59 +2120,6 @@ public class Number
return z;
}
- // FIXME: This is here becase ln e breaks if we use the symmetric to_float
- private float to_float_old ()
- {
- if (is_zero ())
- return 0f;
-
- var z = 0f;
- var i = 0;
- for (; i < T; i++)
- {
- z = BASE * z + re_fraction[i];
-
- /* CHECK IF FULL SINGLE-PRECISION ACCURACY ATTAINED */
- if (z + 1.0f <= z)
- break;
- }
-
- /* NOW ALLOW FOR EXPONENT */
- z = (float) (z * mppow_ri (BASE, re_exponent - i - 1));
-
- if (re_sign < 0)
- return -z;
- else
- return z;
- }
-
- private double mppow_ri (float ap, int bp)
- {
- if (bp == 0)
- return 1.0f;
-
- if (bp < 0)
- {
- if (ap == 0)
- return 1.0f;
- bp = -bp;
- ap = 1 / ap;
- }
-
- var pow = 1.0;
- while (true)
- {
- if ((bp & 01) != 0)
- pow *= ap;
- if ((bp >>= 1) != 0)
- ap *= ap;
- else
- break;
- }
-
- return pow;
- }
-
/* RETURNS MP Y = Ln (1+X) IF X IS AN MP NUMBER SATISFYING THE
* CONDITION ABS (X) < 1/B, ERROR OTHERWISE.
* USES NEWTONS METHOD TO SOLVE THE EQUATION
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]