/* Copyright (C) 2000 Kai Habel ** ** 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 */ /* INSTALLATION - copy this file and the Makefile to directory of octave's LOADPATH - compile this file: make */ #include #include #include #include #include #include typedef unsigned long bitop_int; const unsigned int ULONG_SIZE=CHAR_BIT*sizeof(bitop_int); const unsigned int BIT_AND = 1; const unsigned int BIT_OR = 2; const unsigned int BIT_XOR = 3; double scalar_bitop(double x,double y,unsigned int op) { double a=octave_NaN; if ((x>=0)&&(x<=ULONG_MAX)&&(y>=0)&&(y<=ULONG_MAX)) { bitop_int xval=static_cast( floor(x) ); bitop_int yval=static_cast( floor(y) ); if (op ==BIT_AND) a = static_cast(xval & yval); else if (op==BIT_OR) a = static_cast(xval | yval); else if (op==BIT_XOR) a = static_cast(xval ^ yval); } return(a); } octave_value_list bitop(Matrix xmat,Matrix ymat,unsigned int op) { octave_value_list retval; bool is_scalar_op=false,is_matrix_op=false; unsigned int xr=xmat.rows(); unsigned int yr=ymat.rows(); unsigned int xc=xmat.columns(); unsigned int yc=ymat.columns(); if ( (xr*xc)==1 || (yr*yc)==1) is_scalar_op=true; if ( (xr==yr)&&(xc==yc) ) is_matrix_op=true; if (is_matrix_op || is_scalar_op) { unsigned int i,j,k,l; unsigned int r=max(xr,yr),c=max(xc,yc); Matrix a(r,c); for(i=0;i(ULONG_MAX)); return retval; }