changeset 6781:3058060c560f

[project @ 2007-07-19 08:07:31 by dbateman]
author dbateman
date Thu, 19 Jul 2007 08:07:32 +0000
parents 38bc358b6c9a
children e3f06290847c
files doc/ChangeLog doc/interpreter/bit.txi doc/interpreter/numbers.txi doc/interpreter/octave.texi scripts/ChangeLog scripts/plot/fplot.m
diffstat 6 files changed, 156 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Wed Jul 18 18:04:56 2007 +0000
+++ b/doc/ChangeLog	Thu Jul 19 08:07:32 2007 +0000
@@ -1,3 +1,10 @@
+2007-07-19  David Bateman  <dbateman@free.fr>
+
+	* interpreter/bit.xi: Remove.
+	* interpreter/numbers.txi: Move here, and add examples.
+	* interpreter/octave.texi: Remove "Bit manipulation" chapter and make
+	it a sub-section of the "Numeric Data Types" chapter.
+
 2007-07-06  David Bateman  <dbateman@free.fr>
 
         * interpreter/arith.txi: Add accumarray.
--- a/doc/interpreter/bit.txi	Wed Jul 18 18:04:56 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-@c Copyright (C) 2007 John W. Eaton
-@c This is part of the Octave manual.
-@c For copying conditions, see the file gpl.texi.
-
-@node Bit Manipulations
-@chapter Bit Manipulations
-
-Octave provides the following functions for bit twiddling.
-
-@DOCSTRING(bitset)
-
-@DOCSTRING(bitget)
-
-@DOCSTRING(bitcmp)
-
-@DOCSTRING(bitshift)
-
-@DOCSTRING(bitand)
-
-@DOCSTRING(bitor)
-
-@DOCSTRING(bitxor)
-
-@DOCSTRING(bitmax)
--- a/doc/interpreter/numbers.txi	Wed Jul 18 18:04:56 2007 +0000
+++ b/doc/interpreter/numbers.txi	Thu Jul 19 08:07:32 2007 +0000
@@ -78,6 +78,7 @@
 * Matrices::                    
 * Ranges::                      
 * Integer Data Types::
+* Bit Manipulations::
 * Logical Values::              
 * Predicates for Numeric Objects::  
 @end menu
@@ -467,6 +468,87 @@
 result is often floored to the nearest integer. So, the result of
 @code{int32(5)./int32(8)} is @code{1}.
 
+@node Bit Manipulations
+@section Bit Manipulations
+
+Octave provides a number of functions for the manipulation of numeric
+values on a bit by bit basis. The basic functions to set and obtain the
+values of individual bits are @code{bitset} and @code{bitget}.
+
+@DOCSTRING(bitset)
+
+@DOCSTRING(bitget)
+
+The arguments to all of Octave's bitwise operations can be scalar or
+arrays, except for @code{bitcmp}, whose @var{k} argument must a
+scalar. In the case where more than one argument is an array, then all
+arguments must have the same shape, and the bitwise operator is applied
+to each of the elements of the argument individually. If at least one
+argument is a scalar and one an array, then the scalar argument is
+duplicated. Therefore
+
+@example
+bitget (100, 8:-1:1)
+@end example
+
+is the same as
+
+@example
+bitget (100 * ones (1, 8), 8:-1:1)
+@end example
+
+It should be noted that all values passed to the bit manipulation
+functions of Octave are treated as integers. Therefore, even though the
+example for @code{bitset} above passes the floating point value
+@code{10}, it is treated as the bits @code{[1, 0, 1, 0]} rather than the
+bits of the native floating point format representation of @code{10}.
+
+As the maximum number that can be represented by a number is important
+for bit manipulation, particularly when forming masks, Octave supplies
+the function @code{bitmax}.
+
+@DOCSTRING(bitmax)
+
+This is the double precision version of the functions @code{intmax},
+previously discussed.
+
+Octave also include the basic bitwise 'and', 'or' and 'exclusive or'
+operators.
+
+@DOCSTRING(bitand)
+
+@DOCSTRING(bitor)
+
+@DOCSTRING(bitxor)
+
+The bitwise 'not' operator is unary operator that performs a logial
+negation of each of the bits of the value. For this to make sense, the
+mask against which the value is negated must be defined. Octave's
+bitwise 'not' operator is @code{bitcmp}.
+
+@DOCSTRING(bitcmp)
+
+Octave also includes the ability to left and right values bitwise.
+
+@DOCSTRING(bitshift)
+
+Bits that are shifted out of either end of the value are lost. Octave
+also uses arithmetic shifts, where the sign bit of the value is keep
+during a right shift. For example
+
+@example
+@group
+bitshift (-10, -1)
+@result{} -5
+bitshift (int8 (-1), -1)
+@result{} -1
+@end group
+@end example
+
+Note that @code{bitshift (int8 (-1), -1)} is @code{-1} since the bit
+representation of @code{-1} in the @code{int8} data type is @code{[1, 1,
+1, 1, 1, 1, 1, 1]}.
+
 @node Logical Values
 @section Logical Values
 
--- a/doc/interpreter/octave.texi	Wed Jul 18 18:04:56 2007 +0000
+++ b/doc/interpreter/octave.texi	Thu Jul 19 08:07:32 2007 +0000
@@ -145,7 +145,6 @@
 * Plotting::                    
 * Matrix Manipulation::         
 * Arithmetic::                  
-* Bit Manipulations::
 * Linear Algebra::              
 * Nonlinear Equations::         
 * Sparse Matrices::
@@ -250,6 +249,7 @@
 * Matrices::                    
 * Ranges::                      
 * Integer Data Types::
+* Bit Manipulations::
 * Logical Values::              
 * Predicates for Numeric Objects::  
 
@@ -584,7 +584,6 @@
 @include plot.texi
 @include matrix.texi
 @include arith.texi
-@include bit.texi
 @include linalg.texi
 @include nonlin.texi
 @include sparse.texi
--- a/scripts/ChangeLog	Wed Jul 18 18:04:56 2007 +0000
+++ b/scripts/ChangeLog	Thu Jul 19 08:07:32 2007 +0000
@@ -1,3 +1,7 @@
+2007-07-19  David Bateman  <dbateman@free.fr>
+
+	* plot/fplot.m: More compatible version.
+
 2007-07-18  Michael Goffioul  <michael.goffioul@gmail.com>
 
 	* plot/clf.m: Check for valid handle before deleting.
--- a/scripts/plot/fplot.m	Wed Jul 18 18:04:56 2007 +0000
+++ b/scripts/plot/fplot.m	Thu Jul 19 08:07:32 2007 +0000
@@ -19,50 +19,99 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits})
+## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{tol})
 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n})
+## @deftypefnx {Function File} {} fplot (@dots{}, @var{LineSpec})
 ## Plot a function @var{fn}, within the defined limits.  @var{fn}
 ## an be either a string, a function handle or an inline function.
 ## The limits of the plot are given by @var{limits} of the form
 ## @code{[@var{xlo}, @var{xhi}]} or @code{[@var{xlo}, @var{xhi},
-## @var{ylo}, @var{yhi}]}. @var{n} is the number of points to use and
-## defaults to 100. 
+## @var{ylo}, @var{yhi}]}. @var{tol} is the default tolerance to use for the
+## plot, and if @var{tol} is an integer it is assumed that it defines the 
+## number points to use in the plot. The @var{LineSpec} is passed to the plot
+## command.
 ##
 ## @example
 ##    fplot ("cos", [0, 2*pi])
 ##    fplot ("[cos(x), sin(x)]", [0, 2*pi])
 ## @end example
+## @seealso{plot}
 ## @end deftypefn
 
-function fplot (fn, limits, n)
+function fplot (fn, limits, n, linespec)
   if (nargin < 2 || nargin > 3)
     print_usage ();
   endif
 
   if (nargin < 3) 
-    n = 100; 
+    n = 0.002; 
   endif
 
-  x = linspace (limits(1), limits(2), n)';
+  have_linespec = true;
+  if (nargin < 4) 
+    have_linespec = false;
+  endif
 
-  nam = fn;
+  if (ischar (n))
+    have_linespec = true;
+    linespec = n;
+    n = 0.002;
+  endif
+
   if (strcmp (typeinfo (fn), "inline function"))
     fn = vectorize (fn);
-    y = fn (x);
     nam = formula (fn);
   elseif (isa (fn, "function_handle"))
-    y = fn (x);
     nam = func2str (fn);
   elseif (all (isalnum (fn)))
-    y = feval (fn, x);
+    nam = fn;
   else
-    finl = vectorize (inline (fn));
-    y = finl (x);
+    fn = vectorize (inline (fn));
+    nam = formula (fn);
+  endif
+
+  if (floor(n) != n)
+    tol = n;
+    x0 = linspace (limits(1), limits(2), 3)';
+    y0 = feval (fn, x0);
+    err0 = Inf;
+    n = 5;
+    x = linspace (limits(1), limits(2), n)';
+    y = feval (fn, x);
+
+    while (n < 2 .^ 20)
+      y00 = interp1 (x0, y0, x, "linear");
+      err = 0.5 * max (abs ((y00 - y) ./ (y00 + y))(:));
+      if (err == err0 || 0.5 * max (abs ((y00 - y) ./ (y00 + y))(:)) < tol)
+	break;
+      endif
+      x0 = x;
+      y0 = y;
+      err0 = err;
+      n = 2 * (n - 1) + 1;
+      x = linspace (limits(1), limits(2), n)';
+      y = feval (fn, x);
+    endwhile 
+  else
+    x = linspace (limits(1), limits(2), n)';
+    y = feval (fn, x);
   endif
 
   if (length (limits) > 2) 
     axis (limits);
   endif
 
-  plot (x, y, [";", nam, ";"]);
-
+  if (have_linespec)
+    plot (x, y, linespec);
+  else
+    plot (x, y);
+  endif
+  if (isvector(y))
+    legend (nam);
+  else
+    for i=1:columns(y)
+      nams{i} = sprintf ("%s(:,%i)", nam, i);
+    endfor
+    legend (nams{:});
+  endif
 endfunction