Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update pi() and e() to use syntax closer to standard M. Add tests
- Loading branch information
1 parent
6a2877e
commit ab7df07
Showing
4 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |