RegressionTests__QDoubleTests.st
changeset 2439 fb81e7ceb6b2
parent 2436 ae3aaedd0b32
child 2440 dd7f294de89b
--- a/RegressionTests__QDoubleTests.st	Fri Nov 29 19:20:23 2019 +0100
+++ b/RegressionTests__QDoubleTests.st	Fri Nov 29 19:20:34 2019 +0100
@@ -813,6 +813,68 @@
      self run:#test_10_printing
      self new test_10_printing
     "
+!
+
+test_11a_pi
+    "/ Machin's Formula for Pi pi / 4  =  4 arctan(1/5) - arctan(1/239)
+
+    | at1_5 at1_239 pi_4 pi err|
+
+    at1_5 := (1 asQDouble / 5) arcTan.
+    at1_239 := (1 asQDouble / 239) arcTan.
+    pi_4 := (at1_5 * 4) - at1_239.
+    pi := pi_4 * 4. 
+    err := QDouble pi - pi.
+    self assert:(err < (8 * QDouble epsilon)).
+!
+
+test_11b_pi
+    "/ Salamin-Brent Quadratic Formula for Pi
+
+    | max_iter a b s m a_new b_new p_old pi err|
+
+    max_iter := 6.
+
+    a := 1.0 asQDouble.
+    b := 0.5 asQDouble sqrt.
+    s := 0.5 asQDouble.
+    m := 1.0 asQDouble.
+
+    pi := 2.0 asQDouble * a squared / s.
+    1 to:max_iter do:[:i |
+        m := m * 2.
+        a_new := 0.5 * (a+b).
+        b_new := a * b.
+        s := s - (m * (a_new squared - b_new)).
+        a := a_new.
+        b := b_new sqrt.
+        p_old := pi.
+        pi := 2 * a squared / s.
+    ].
+
+    err := QDouble pi - pi.
+    self assert:(err < (8 * QDouble epsilon)).
+!
+
+test_12_e
+    "/ Taylor for e
+
+    | e t n i err|
+
+    e := 2.0 asQDouble.
+    t := 1.0 asQDouble.
+    n := 1.0.
+    i := 0.
+
+    [t > QDouble epsilon] whileTrue:[
+        i := i + 1.
+        n := n + 1.0.
+        t := t / n.
+        e := e + t.
+    ].
+
+    err := QDouble e - e.
+    self assert:(err < (8 * QDouble epsilon)).
 ! !
 
 !QDoubleTests class methodsFor:'documentation'!