changeset 10037:7b32308b8ef5 octave-forge

miscellaneous: Adding truncate function for evaluation of the community.
author jpicarbajal
date Sun, 15 Apr 2012 10:50:05 +0000
parents 37d9084c34c8
children c2a549f1d3f8
files main/miscellaneous/NEWS main/miscellaneous/inst/truncate.m
diffstat 2 files changed, 54 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/main/miscellaneous/NEWS	Sun Apr 15 09:34:12 2012 +0000
+++ b/main/miscellaneous/NEWS	Sun Apr 15 10:50:05 2012 +0000
@@ -1,5 +1,14 @@
-Summary of important user-visible changes for miscellaneous 1.1.0:
--------------------------------------------------------------------
+Summary of important user-visible changes for the miscellaneous package
+------------------------------------------------------------------------
+===============================================================================
+miscellaneous-1.2.0   Release Date: 2012-XX-XX  Release Manager:
+===============================================================================
+ ** New functions:
+   truncate.m : truncates a number to a given precision.
+
+===============================================================================
+miscellaneous-1.1.0   Release Date: 2012-03-24  Release Manager:
+===============================================================================
 
  ** IMPORTANT NOTE:
     * the function `waitbar' has been renamed `text_waitbar'. Octave core has
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/miscellaneous/inst/truncate.m	Sun Apr 15 10:50:05 2012 +0000
@@ -0,0 +1,43 @@
+%% Copyright (c) 2012 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
+%%
+%%    This program is free software: you can redistribute it and/or modify
+%%    it under the terms of the GNU General Public License as published by
+%%    the Free Software Foundation, either version 3 of the License, or
+%%    any later version.
+%%
+%%    This program is distributed in the hope that it will be useful,
+%%    but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%%    GNU General Public License for more details.
+%%
+%%    You should have received a copy of the GNU General Public License
+%%    along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+%% -*- texinfo -*-
+%% @deftypefn {Function File} {@var{y} = } truncate (@var{x}, @var{order})
+%% Truncates @var{X} to @var{order} of magnitude.
+%%
+%% Example
+%% @example
+%%    format long
+%%    x = 987654321.123456789;
+%%    order = [3:-1:0 -(1:3)]';
+%%    y = truncate(x,order)
+%% y =
+%%   987654000.000000
+%%   987654300.000000
+%%   987654320.000000
+%%   987654321.000000
+%%   987654321.100000
+%%   987654321.120000
+%%   987654321.123000
+%% @end example
+%%
+%% @seealso{round,fix,ceil,floor}
+%% @end deftypefn
+
+function y = truncate (x,order)
+  ino = 0.1.^order;
+  o = 10.^order;
+  y = round (x.*ino).*o;
+end