IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7189


Ignore:
Timestamp:
May 23, 2006, 1:43:18 PM (20 years ago)
Author:
Paul Price
Message:

Adding logical operators: & and |

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psBinaryOp.c

    r6885 r7189  
    3030 *  @author Robert DeSonia, MHPCC
    3131 *
    32  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    33  *  @date $Date: 2006-04-18 22:04:28 $
     32 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     33 *  @date $Date: 2006-05-23 23:43:18 $
    3434 *
    3535 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    325325}
    326326
     327
     328// Preprocessor macro function to create arithmetic function based on input type for integers only
     329#define BINARY_TYPE_INTEGER(DIM1,DIM2,OUT,IN1,OP,IN2)                                                        \
     330switch (IN1->type) {                                                                                         \
     331case PS_TYPE_U8:                                                                                             \
     332    DIM1##_##DIM2(OUT,IN1,OP,IN2,U8);                                                                        \
     333    break;                                                                                                   \
     334case PS_TYPE_U16:                                                                                            \
     335    DIM1##_##DIM2(OUT,IN1,OP,IN2,U16);                                                                       \
     336    break;                                                                                                   \
     337case PS_TYPE_U32:                                                                                            \
     338    DIM1##_##DIM2(OUT,IN1,OP,IN2,U32);                                                                       \
     339    break;                                                                                                   \
     340case PS_TYPE_U64:                                                                                            \
     341    DIM1##_##DIM2(OUT,IN1,OP,IN2,U64);                                                                       \
     342    break;                                                                                                   \
     343case PS_TYPE_S8:                                                                                             \
     344    DIM1##_##DIM2(OUT,IN1,OP,IN2,S8);                                                                        \
     345    break;                                                                                                   \
     346case PS_TYPE_S16:                                                                                            \
     347    DIM1##_##DIM2(OUT,IN1,OP,IN2,S16);                                                                       \
     348    break;                                                                                                   \
     349case PS_TYPE_S32:                                                                                            \
     350    DIM1##_##DIM2(OUT,IN1,OP,IN2,S32);                                                                       \
     351    break;                                                                                                   \
     352case PS_TYPE_S64:                                                                                            \
     353    DIM1##_##DIM2(OUT,IN1,OP,IN2,S64);                                                                       \
     354    break;                                                                                                   \
     355default:                                                                                                     \
     356    /* char* strType;                                                                                        \
     357    PS_TYPE_NAME(strType,IN1->type);                                                                         \
     358    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                                 \
     359            PS_ERRORTEXT_psMatrix_TYPE_MISMATCH,                                                             \
     360            strType);  */                                                                                    \
     361    if (OUT != IN1 && OUT != IN2) {                                                                          \
     362        psFree(OUT);                                                                                         \
     363    }                                                                                                        \
     364    return NULL;                                                                                             \
     365}
     366
    327367// Preprocessor macro function to create arithmetic function based on input type
    328368#define BINARY_TYPE(DIM1,DIM2,OUT,IN1,OP,IN2)                                                                \
     
    365405    break;                                                                                                   \
    366406default:                                                                                                     \
    367     /* char* strType; \
     407    /* char* strType;                                                                                        \
    368408    PS_TYPE_NAME(strType,IN1->type);                                                                         \
    369409    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                                 \
    370410            PS_ERRORTEXT_psMatrix_TYPE_MISMATCH,                                                             \
    371             strType);  */                                                                                      \
     411            strType);  */                                                                                    \
    372412    if (OUT != IN1 && OUT != IN2) {                                                                          \
    373413        psFree(OUT);                                                                                         \
     
    388428} else if(!strncmp(OP, "/", 1)) {                                                                            \
    389429    BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2);                                                            \
     430} else if(!strncmp(OP, "&", 1)) {                                                                            \
     431    if (PS_IS_PSELEMTYPE_INT(IN1->type) && PS_IS_PSELEMTYPE_INT(IN2->type)) {                                \
     432        BINARY_TYPE_INTEGER(DIM1,DIM2,OUT,IN1,(*i1) & (*i2),IN2);                                            \
     433    } else {                                                                                                 \
     434        psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                            \
     435                "Types (%x,%x) are not appropriate for logical AND.\n", IN1->type, IN2->type);               \
     436        return NULL;                                                                                         \
     437    }                                                                                                        \
     438} else if(!strncmp(OP, "|", 1)) {                                                                            \
     439    if (PS_IS_PSELEMTYPE_INT(IN1->type) && PS_IS_PSELEMTYPE_INT(IN2->type)) {                                \
     440        BINARY_TYPE_INTEGER(DIM1,DIM2,OUT,IN1,(*i1) | (*i2),IN2);                                            \
     441    } else {                                                                                                 \
     442        psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                            \
     443                "Types (%x,%x) are not appropriate for logical OR.\n", IN1->type, IN2->type);                \
     444        return NULL;                                                                                         \
     445    }                                                                                                        \
    390446} else if(!strncmp(OP, "^", 1)) {                                                                            \
    391447    if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) {                                                                \
Note: See TracChangeset for help on using the changeset viewer.