Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit ab7df07a04c6f7b4af281746c9f91f4e6e0222db 1 parent 6a2877e
@Whiteknight authored
Showing with 49 additions and 5 deletions.
  1. +12 −0 t/functions/e.t
  2. +12 −0 t/functions/pi.t
  3. +12 −2 toolbox/e.m
  4. +13 −3 toolbox/pi.m
View
12 t/functions/e.t
@@ -0,0 +1,12 @@
+plan(7);
+_e = e;
+is(parrot_typeof(_e), "Float", "e is a normal float");
+_e = e(2);
+is(parrot_typeof(_e), "NumMatrix2D", "e(2) is a matrix");
+is(columns(_e), 2);
+is(rows(_e), 2);
+
+_e = e(3, 4);
+is(parrot_typeof(_e), "NumMatrix2D", "e(3, 4) is a matrix");
+is(columns(_e), 4);
+is(rows(_e), 3);
View
12 t/functions/pi.t
@@ -0,0 +1,12 @@
+plan(7);
+p = pi;
+is(parrot_typeof(p), "Float", "pi is a normal float");
+p = pi(2);
+is(parrot_typeof(p), "NumMatrix2D", "pi(2) is a matrix");
+is(columns(p), 2);
+is(rows(p), 2);
+
+p = pi(3, 4);
+is(parrot_typeof(p), "NumMatrix2D", "pi(3, 4) is a matrix");
+is(columns(p), 4);
+is(rows(p), 3);
View
14 toolbox/e.m
@@ -1,5 +1,15 @@
-function val = e()
+function val = e(rows, cols)
%% val = e()
%% Returns the value of e, Euler's constant, to several decimal places
- val = 2.7182882845904523536;
+ % TODO: Should take an arbitrary number of args and return an N-dim matrix
+ _e = 2.7182882845904523536;
+ if nargin == 0
+ val = _e;
+ else
+ if nargin == 1
+ cols = rows;
+ end
+ val = parrot_new("NumMatrix2D");
+ parrot_method(val, "fill", _e, rows, cols);
+ end
endfunction
View
16 toolbox/pi.m
@@ -1,5 +1,15 @@
-function p = pi()
-%% p = pi()
+function val = pi(rows, cols)
+%% val = pi()
%% returns the value of pi to about 13 decimal places
- p = 3.1415926535898;
+ % TODO: Should take an arbitrary number of args and return an N-dim matrix
+ _p = 3.1415926535898;
+ if nargin == 0
+ val = _p;
+ else
+ if nargin == 1
+ cols = rows;
+ end
+ val = parrot_new("NumMatrix2D");
+ parrot_method(val, "fill", _p, rows, cols);
+ end
endfunction
Please sign in to comment.
Something went wrong with that request. Please try again.