Skip to content

Commit

Permalink
update pi() and e() to use syntax closer to standard M. Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Dec 8, 2009
1 parent 6a2877e commit ab7df07
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
12 changes: 12 additions & 0 deletions 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);
12 changes: 12 additions & 0 deletions 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);
14 changes: 12 additions & 2 deletions 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
16 changes: 13 additions & 3 deletions 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

0 comments on commit ab7df07

Please sign in to comment.