#QUALITY by cg
authorClaus Gittinger <cg@exept.de>
Fri, 29 Nov 2019 19:20:23 +0100
changeset 2438 fee9c7662c51
parent 2437 9a0290a12bae
child 2439 fb81e7ceb6b2
#QUALITY by cg class: RegressionTests::FloatTest added: #test_11a_pi #test_11b_pi #test_12_e removed: #test_11_pi
RegressionTests__FloatTest.st
--- a/RegressionTests__FloatTest.st	Fri Nov 29 19:04:53 2019 +0100
+++ b/RegressionTests__FloatTest.st	Fri Nov 29 19:20:23 2019 +0100
@@ -994,8 +994,8 @@
     "Created: / 03-07-2017 / 13:51:54 / cg"
 !
 
-test_11_pi
-    "/ pi / 4  =  4 arctan(1/5) - arctan(1/239)
+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|
 
@@ -1005,6 +1005,55 @@
     pi := pi_4 * 4. 
     err := Float pi - pi.
     self assert:(err < (8 * Float 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 asFloat.
+    b := 0.5 asFloat sqrt.
+    s := 0.5 asFloat.
+    m := 1.0 asFloat.
+
+    pi := 2.0 asFloat * 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 := Float pi - pi.
+    self assert:(err < (8 * Float epsilon)).
+!
+
+test_12_e
+    "/ Taylor for e
+
+    | e t n i err|
+
+    e := 2.0.
+    t := 1.0.
+    n := 1.0.
+    i := 0.
+
+    [t > Float epsilon] whileTrue:[
+        i := i + 1.
+        n := n + 1.0.
+        t := t / n.
+        e := e + t.
+    ].
+
+    err := Float e - e.
+    self assert:(err < (8 * Float epsilon)).
 ! !
 
 !FloatTest class methodsFor:'documentation'!