Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

update pi() and e() to use syntax closer to standard M. Add tests

  • Loading branch information...
commit ab7df07a04c6f7b4af281746c9f91f4e6e0222db 1 parent 6a2877e
Andrew Whitworth authored December 08, 2009
12  t/functions/e.t
... ...
@@ -0,0 +1,12 @@
  1
+plan(7);
  2
+_e = e;
  3
+is(parrot_typeof(_e), "Float", "e is a normal float");
  4
+_e = e(2);
  5
+is(parrot_typeof(_e), "NumMatrix2D", "e(2) is a matrix");
  6
+is(columns(_e), 2);
  7
+is(rows(_e), 2);
  8
+
  9
+_e = e(3, 4);
  10
+is(parrot_typeof(_e), "NumMatrix2D", "e(3, 4) is a matrix");
  11
+is(columns(_e), 4);
  12
+is(rows(_e), 3);
12  t/functions/pi.t
... ...
@@ -0,0 +1,12 @@
  1
+plan(7);
  2
+p = pi;
  3
+is(parrot_typeof(p), "Float", "pi is a normal float");
  4
+p = pi(2);
  5
+is(parrot_typeof(p), "NumMatrix2D", "pi(2) is a matrix");
  6
+is(columns(p), 2);
  7
+is(rows(p), 2);
  8
+
  9
+p = pi(3, 4);
  10
+is(parrot_typeof(p), "NumMatrix2D", "pi(3, 4) is a matrix");
  11
+is(columns(p), 4);
  12
+is(rows(p), 3);
14  toolbox/e.m
... ...
@@ -1,5 +1,15 @@
1  
-function val = e()
  1
+function val = e(rows, cols)
2 2
 %% val = e()
3 3
 %% Returns the value of e, Euler's constant, to several decimal places
4  
-    val = 2.7182882845904523536;
  4
+    % TODO: Should take an arbitrary number of args and return an N-dim matrix
  5
+    _e = 2.7182882845904523536;
  6
+    if nargin == 0
  7
+        val = _e;
  8
+    else
  9
+        if nargin == 1
  10
+            cols = rows;
  11
+        end
  12
+        val = parrot_new("NumMatrix2D");
  13
+        parrot_method(val, "fill", _e, rows, cols);
  14
+    end
5 15
 endfunction
16  toolbox/pi.m
... ...
@@ -1,5 +1,15 @@
1  
-function p = pi()
2  
-%% p = pi()
  1
+function val = pi(rows, cols)
  2
+%% val = pi()
3 3
 %% returns the value of pi to about 13 decimal places
4  
-    p = 3.1415926535898;
  4
+    % TODO: Should take an arbitrary number of args and return an N-dim matrix
  5
+    _p = 3.1415926535898;
  6
+    if nargin == 0
  7
+        val = _p;
  8
+    else
  9
+        if nargin == 1
  10
+            cols = rows;
  11
+        end
  12
+        val = parrot_new("NumMatrix2D");
  13
+        parrot_method(val, "fill", _p, rows, cols);
  14
+    end
5 15
 endfunction

0 notes on commit ab7df07

Please sign in to comment.
Something went wrong with that request. Please try again.