/* 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 #ifdef USE_OCTAVE_NAN #define lo_ieee_nan_value() octave_NaN #endif //using namespace std; 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; inline unsigned int max(unsigned int x, unsigned int y) { return x > y ? x : y; } double scalar_bitop(double x,double y,unsigned int op) { double a=lo_ieee_nan_value(); 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); } #if HAVE_ND_ARRAYS octave_value_list bitop(NDArray xmat,NDArray ymat,unsigned int op) { octave_value_list retval; bool is_scalar_op=false,is_array_op=false; dim_vector dvx = xmat.dims (); dim_vector dvy = ymat.dims (); unsigned int nelx = dvx.numel (); unsigned int nely = dvy.numel (); if ( (nelx==1) || (nely==1)) is_scalar_op=true; if ( dvx == dvy ) is_array_op=true; if (is_array_op || is_scalar_op) { unsigned int i,j,k,l; NDArray a; if (nelx != 1) a.resize (dvx); else a.resize (dvy); for (i=0;i(ULONG_MAX)); return retval; }