From: <jpi...@us...> - 2012-04-15 11:00:19
|
Revision: 10226 http://octave.svn.sourceforge.net/octave/?rev=10226&view=rev Author: jpicarbajal Date: 2012-04-15 11:00:12 +0000 (Sun, 15 Apr 2012) Log Message: ----------- miscellaneous: Adding truncate function for evaluation of the community. Modified Paths: -------------- trunk/octave-forge/main/miscellaneous/devel/truncate.m Modified: trunk/octave-forge/main/miscellaneous/devel/truncate.m =================================================================== --- trunk/octave-forge/main/miscellaneous/devel/truncate.m 2012-04-15 11:00:07 UTC (rev 10225) +++ trunk/octave-forge/main/miscellaneous/devel/truncate.m 2012-04-15 11:00:12 UTC (rev 10226) @@ -14,15 +14,19 @@ %% along with this program. If not, see <http://www.gnu.org/licenses/>. %% -*- texinfo -*- -%% @deftypefn {Function File} {@var{y} = } truncate (@var{x}, @var{order}) +%% @deftypefn {Function File} {@var{y} = } truncate (@var{x}, @var{order},@var{method}) +%% @deftypefnx {Function File} {@var{y} = } truncate (@dots,@var{method}) %% Truncates @var{X} to @var{order} of magnitude. %% -%% Example +%% The optional argument @var{method} can be a hanlde to a function used to +%% truncate the number. Default is @code{@round}. +%% +%% Examples: %% @example %% format long %% x = 987654321.123456789; %% order = [3:-1:0 -(1:3)]'; -%% y = truncate(x,order) +%% y = truncate (x,order) %% y = %% 987654000.000000 %% 987654300.000000 @@ -31,13 +35,20 @@ %% 987654321.100000 %% 987654321.120000 %% 987654321.123000 +%% +%% format +%% [truncate(0.127,-2), truncate(0.127,-2,@floor)] +%% ans = +%% 0.13000 0.12000 +%% %% @end example + %% %% @seealso{round,fix,ceil,floor} %% @end deftypefn -function y = truncate (x,order) +function y = truncate (x,order,method=@round) ino = 0.1.^order; o = 10.^order; - y = round (x.*ino).*o; + y = method (x.*ino).*o; end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |