From: <sla...@us...> - 2009-12-30 00:27:49
|
Revision: 6678 http://octave.svn.sourceforge.net/octave/?rev=6678&view=rev Author: slackydeb Date: 2009-12-29 23:57:14 +0000 (Tue, 29 Dec 2009) Log Message: ----------- Refactor old code as a test file. Added Paths: ----------- trunk/octave-forge/main/ga/doc/old_stuff/ga_old_stuff_test.m Removed Paths: ------------- trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m Deleted: trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m 2009-12-29 12:05:22 UTC (rev 6677) +++ trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m 2009-12-29 23:57:14 UTC (rev 6678) @@ -1,46 +0,0 @@ -## Copyright (C) 2008 Luca Favatella <sla...@gm...> -## -## -## 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, 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; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __bin2hex__ (@var{s}) -## Return the hexadecimal number corresponding to the binary number stored in the string @var{s}. For example, -## -## @example -## __bin2hex__ ("1101110") -## @result{} 6E -## @end example -## -## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}. -## -## @example -## __bin2hex__ (["1101110"; "1110"]) -## @result{} [6E; E] -## @end example -## @seealso{__hex2bin__, bin2dec, dec2hex} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.5 - -function h = __bin2hex__ (b) - h = dec2hex (bin2dec (b)); -endfunction - -%!assert (__bin2hex__ ("1101110"), "6E") - -%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "E"]) \ No newline at end of file Deleted: trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m 2009-12-29 12:05:22 UTC (rev 6677) +++ trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m 2009-12-29 23:57:14 UTC (rev 6678) @@ -1,46 +0,0 @@ -## Copyright (C) 2008 Luca Favatella <sla...@gm...> -## -## -## 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, 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; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __bin2num__ (@var{b}) -## Return the IEEE 754 double precision number represented by the binary number stored in the string @var{b}. For example, -## -## @example -## __bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000") -## @result{} 1 -## @end example -## -## If @var{b} is a string matrix, returns a column vector of converted numbers, one per row of @var{b}. -## -## @example -## __bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) -## @result{} [1; -3] -## @end example -## @seealso{__num2bin__, __bin2hex__, hex2num} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.3 - -function n = __bin2num__ (b) - n = hex2num (__bin2hex__ (b)); -endfunction - -%!assert (__bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000"), 1) - -%!assert (__bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]), [1; -3]) \ No newline at end of file Deleted: trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m 2009-12-29 12:05:22 UTC (rev 6677) +++ trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m 2009-12-29 23:57:14 UTC (rev 6678) @@ -1,57 +0,0 @@ -## Copyright (C) 2008 Luca Favatella <sla...@gm...> -## -## -## 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, 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; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __hex2bin__ (@var{s}, @var{len}) -## Return the binary number corresponding to the hexadecimal number stored in the string @var{s}. For example, -## -## @example -## __hex2bin__ ("6E") -## @result{} 1101110 -## @end example -## -## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}, padded with leading zeros to the width of the largest value. -## -## @example -## __hex2bin__ (["6E"; "E"]) -## @result{} [1101110; 0001110] -## @end example -## -## The optional third argument, @var{len}, specifies the minimum -## number of digits in the result. - -## @seealso{__bin2hex__, hex2dec, dec2bin} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.7 - -function b = __hex2bin__ (h, len) - d = hex2dec (h); - - switch nargin - case {1} - b = dec2bin (d); - case {2} - b = dec2bin (d, len); - endswitch -endfunction - -%!assert (__hex2bin__ ("6E"), "1101110") - -%!assert (__hex2bin__ (["6E"; "0E"]), ["1101110"; "0001110"]) \ No newline at end of file Deleted: trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m 2009-12-29 12:05:22 UTC (rev 6677) +++ trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m 2009-12-29 23:57:14 UTC (rev 6678) @@ -1,47 +0,0 @@ -## Copyright (C) 2008 Luca Favatella <sla...@gm...> -## -## -## 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, 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; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __num2bin__ (@var{n}) -## Return the binary representation of the IEEE 754 double precision number @var{n}. For example, -## -## @example -## __num2bin__ (1) -## @result{} 0011111111110000000000000000000000000000000000000000000000000000 -## @end example -## -## If @var{n} is a number matrix, returns a column vector of converted numbers, one per row of @var{n}. -## -## @example -## __num2bin__ (["1"; "-3"]) -## @result{} [0011111111110000000000000000000000000000000000000000000000000000; 1100000000001000000000000000000000000000000000000000000000000000] -## @end example -## @seealso{__bin2num__, num2hex, __hex2bin__} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.4 - -function b = __num2bin__ (n) - ## a double precision number is always 64 bits long - b = __hex2bin__ (num2hex (n), 64); -endfunction - -%!assert (__num2bin__ (1), "0011111111110000000000000000000000000000000000000000000000000000") - -%!assert (__num2bin__ ([1; -3]), ["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) \ No newline at end of file Added: trunk/octave-forge/main/ga/doc/old_stuff/ga_old_stuff_test.m =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/ga_old_stuff_test.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/ga_old_stuff_test.m 2009-12-29 23:57:14 UTC (rev 6678) @@ -0,0 +1,103 @@ +## Copyright (C) 2008, 2009 Luca Favatella <sla...@gm...> +## +## This file is part of Octave. +## +## Octave 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 (at +## your option) any later version. +## +## Octave 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 Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## Some tests. + + +## @deftypefn {Function File} {} __bin2hex__ (@var{s}) +## Return the hexadecimal number corresponding to the binary number +## stored in the string @var{s}. +## +## If @var{s} is a string matrix, returns a column vector of converted +## numbers, one per row of @var{s}. +## +## @seealso{__hex2bin__} +## @end deftypefn +%!function h = __bin2hex__ (b) +%! h = dec2hex (bin2dec (b)); +%! +%!assert (__bin2hex__ ("1101110"), "6E"); +%!xtest assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "E"]); + + +## @deftypefn {Function File} {} __hex2bin__ (@var{s}, @var{len}) +## Return the binary number corresponding to the hexadecimal number +## stored in the string @var{s}. +## +## If @var{s} is a string matrix, returns a column vector of converted +## numbers, one per row of @var{s}, padded with leading zeros to the +## width of the largest value. +## +## The optional second argument, @var{len}, specifies the minimum +## number of digits in the result. +## +## @seealso{__bin2hex__} +## @end deftypefn + +%!function b = __hex2bin__ (h, len) +%! d = hex2dec (h); +%! +%! switch nargin +%! case {1} +%! b = dec2bin (d); +%! case {2} +%! b = dec2bin (d, len); +%! endswitch +%! +%!assert (__hex2bin__ ("6E"), "1101110"); +%!assert (__hex2bin__ (["6E"; "0E"]), ["1101110"; "0001110"]); + + +## @deftypefn {Function File} {} __bin2num__ (@var{b}) +## Return the IEEE 754 double precision number represented by the binary +## number stored in the string @var{b}. +## +## If @var{b} is a string matrix, returns a column vector of converted +## numbers, one per row of @var{b}. +## +## @seealso{__num2bin__} +## @end deftypefn + +%!function n = __bin2num__ (b) +%! n = hex2num (__bin2hex__ (b)); +%! +%!assert (__bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000"), 1); +%!assert (__bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; +%! "1100000000001000000000000000000000000000000000000000000000000000"]), [1; -3]); + + +## @deftypefn {Function File} {} __num2bin__ (@var{n}) +## Return the binary representation of the IEEE 754 double precision +## number @var{n}. +## +## If @var{n} is a number matrix, returns a column vector of converted +## numbers, one per row of @var{n}. +## +## @seealso{__bin2num__} +## @end deftypefn + +%!function b = __num2bin__ (n) +%! ## a double precision number is always 64 bits long +%! b = __hex2bin__ (num2hex (n), 64); +%! +%!assert (__num2bin__ (1), +%! "0011111111110000000000000000000000000000000000000000000000000000"); +%!assert (__num2bin__ ([1; -3]), +%! ["0011111111110000000000000000000000000000000000000000000000000000"; +%! "1100000000001000000000000000000000000000000000000000000000000000"]); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |