changeset 1251:a06e631e1846 octave-forge

alternative REM and MOD: more intuitive usage, especially with extrem values, like y=0 and inf.
author schloegl
date Thu, 29 Jan 2004 23:23:33 +0000
parents ff5cda33bd73
children db52758cd21d
files extra/NaN/INDEX extra/NaN/README.TXT extra/NaN/mod.m extra/NaN/rem.m
diffstat 4 files changed, 126 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/INDEX	Thu Jan 29 22:03:42 2004 +0000
+++ b/extra/NaN/INDEX	Thu Jan 29 23:23:33 2004 +0000
@@ -2,7 +2,7 @@
  coefficient_of_variation geomean meansq skewness
  covm cor cov corrcoef harmmean median statistic
  detrend kurtosis moment std mad naninsttest nantest 
- nansum nanstd normpdf normcdf norminv meandev 
+ nansum nanstd normpdf normcdf norminv meandev mod rem
  percentile quantiles rankcorr ranks rms sumskipnan 
  var mean sem spearman trimean tpdf tcdf tinv zscore 
 
--- a/extra/NaN/README.TXT	Thu Jan 29 22:03:42 2004 +0000
+++ b/extra/NaN/README.TXT	Thu Jan 29 23:23:33 2004 +0000
@@ -1,6 +1,6 @@
 NaN-Tb: A statistics toolbox 
 ------------------------------------------------------------
-Copyright (C) 2000-2003 Alois Schloegl <a.schloegl@ieee.org>
+Copyright (C) 2000-2004 Alois Schloegl <a.schloegl@ieee.org>
 
 
 FEATURES of the NaN-tb:
@@ -58,7 +58,9 @@
 	TCDF		student cumulative distribution 
 	TINV		inverse of the student cumulative distribution
 	NANSUM, NANSTD	fixes for buggy versions included
-	
+	MOD		modulus 
+	REM		remainder
+		
 	
 REFERENCE(S):
 ----------------------------------
@@ -198,7 +200,7 @@
 	$Revision$
 	$Id$
 	Version 1.53 	Date: 31 Oct 2003
-	Copyright (C) 2000-2003 by  Alois Schloegl <a.schloegl@ieee.org>	
+	Copyright (C) 2000-2004 by  Alois Schloegl <a.schloegl@ieee.org>	
 	WWW: http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/NaN/mod.m	Thu Jan 29 23:23:33 2004 +0000
@@ -0,0 +1,60 @@
+function [z,e] = mod(x,y)
+% MOD(x,y) calculates Modules Y from X 
+%
+%     z = x - y * floor(x/y);
+%     e = eps * floor(x/y);
+%
+%    [z,e] = MOD(X,Y)
+%	z is the modulus of Y for X
+%	e is the error tolerance, for checking the accuracy
+%		z(e > abs(y)) is not defined 
+%
+% 	z has always the same sign than y	
+%     
+% see also: REM
+
+
+%    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 2 of the License, or
+%    (at your option) 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, write to the Free Software
+%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+%       $Revision$
+%       $Id$
+%	Copyright (c) 2004 by Alois Schloegl <a.schloegl@ieee.org>	
+%       This function is part of the NaN-toolbox
+%       http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/
+
+
+s = warning('off');
+
+if isscalar(x)
+        x = repmat(x,size(y));
+end;
+if isscalar(y)
+        y = repmat(y,size(x));
+end;
+
+t = floor(x./y);
+z = x - y.*t;
+
+e = (abs(t)*eps);	% error interval 
+%z(e > abs(y)) = NaN;	% uncertainty of rounding error to large
+
+z(~t) = x(~t);		% remainder is x if y = inf
+z(~y) = 0;		% remainder must be 0 if y==0
+
+z = abs(z).*sign(y);	% correct sign
+
+warning(s);		% reset warning status
+    
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/NaN/rem.m	Thu Jan 29 23:23:33 2004 +0000
@@ -0,0 +1,60 @@
+function [z,e] = rem(x,y)
+% REM calculates remainder of X / Y  
+%
+%     z = x - y * fix(x/y);
+%     e = eps * fix(x/y);
+%
+%    [z,e] = REM(X,Y)
+%	z is the remainder of X / Y
+%	e is the error tolerance, for checking the accuracy
+%		z(e > abs(y)) is not defined 
+%
+% 	z has always the same sign than x	
+% 
+% see also: MOD
+
+%    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 2 of the License, or
+%    (at your option) 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, write to the Free Software
+%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+%       $Revision$
+%       $Id$
+%	Copyright (c) 2004 by Alois Schloegl <a.schloegl@ieee.org>	
+%       This function is part of the NaN-toolbox
+%       http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/
+
+
+s = warning('off');
+
+if isscalar(x)
+        x = repmat(x,size(y));
+end;
+if isscalar(y)
+        y = repmat(y,size(x));
+end;
+
+t = fix(x./y);
+z = x - y.*t;
+
+e = (abs(t)*eps);	% error interval 
+%z(e > abs(y)) = NaN;	% uncertainty of rounding error to large
+
+z(~t) = x(~t);		% remainder is x if y = inf
+z(~y) = 0;		% remainder must be 0 if y==0
+
+
+z = abs(z).*sign(x);	% correct sign
+
+warning(s);		% reset warning status
+
+