]> Cypherpunks repositories - gostls13.git/commitdiff
add an eval function (written by ken)
authorRob Pike <r@golang.org>
Sat, 19 Jul 2008 22:11:25 +0000 (15:11 -0700)
committerRob Pike <r@golang.org>
Sat, 19 Jul 2008 22:11:25 +0000 (15:11 -0700)
SVN=128122

test/chan/powser1.go

index 1b25d7eefb9bdb06051dc9f534bac2adc3bdd0d3..abafc469babd922734f031daec60613ae5203f52 100644 (file)
@@ -233,6 +233,24 @@ type PS2 *[2] PS; // pair of power series
 var Ones PS
 var Twos PS
 
+// print eval in floating point of PS at x=c to n terms
+func
+Evaln(c *rat, U PS, n int)
+{
+       xn := float64(1);
+       x := float64(c.num)/float64(c.den);
+       val := float64(0);
+       for i:=0; i<n; i++ {
+               u := get(U);
+               if end(u) != 0 {
+                       break;
+               }
+               val = val + x * float64(u.num)/float64(u.den);
+               xn = xn*x;
+       }
+       print val, "\n";
+}
+
 func mkPS() *dch {
        return mkdch()
 }