usfold.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 779 行 · 第 1/2 页
C
779 行
opnd1->complex.imagpart = -opnd2->complex.imagpart;
}
void XQNeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->dcomplex.realpart = -opnd2->dcomplex.realpart;
opnd1->dcomplex.imagpart = -opnd2->dcomplex.imagpart;
}
void XXNeg( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->xcomplex.realpart = -opnd2->xcomplex.realpart;
opnd1->xcomplex.imagpart = -opnd2->xcomplex.imagpart;
}
void XIPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->intstar4 = opnd2->intstar4;
}
void XRPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->single = opnd2->single;
}
void XDPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->dble = opnd2->dble;
}
void XEPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->extended = opnd2->extended;
}
void XCPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->complex.realpart = opnd2->complex.realpart;
opnd1->complex.imagpart = opnd2->complex.imagpart;
}
void XQPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->dcomplex.realpart = opnd2->dcomplex.realpart;
opnd1->dcomplex.imagpart = opnd2->dcomplex.imagpart;
}
void XXPlus( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->xcomplex.realpart = opnd2->xcomplex.realpart;
opnd1->xcomplex.imagpart = opnd2->xcomplex.imagpart;
}
//-------------------------------------------- logical operators
void XLEqv( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->logstar1 = ( opnd1->logstar1 == opnd2->logstar1 );
}
void XLNeqv( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->logstar1 = ( opnd1->logstar1 != opnd2->logstar1 );
}
void XLAnd( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->logstar1 = ( opnd1->logstar1 && opnd2->logstar1 );
}
void XLOr( ftn_type *opnd1, ftn_type *opnd2 ) {
//================================================
opnd1->logstar1 = ( opnd1->logstar1 || opnd2->logstar1 );
}
void XLNot( ftn_type *opnd1, ftn_type *opnd2 ) {
//=================================================
opnd1->logstar1 = !opnd2->logstar1;
}
//-------------------------------------------- bitwise operators
void XBitEqv( ftn_type *opnd1, ftn_type *opnd2 ) {
//===================================================
opnd1->intstar4 = ~( opnd1->intstar4 ^ opnd2->intstar4 );
}
void XBitNeqv( ftn_type *opnd1, ftn_type *opnd2 ) {
//====================================================
opnd1->intstar4 = ( opnd1->intstar4 ^ opnd2->intstar4 );
}
void XBitAnd( ftn_type *opnd1, ftn_type *opnd2 ) {
//===================================================
opnd1->intstar4 = ( opnd1->intstar4 & opnd2->intstar4 );
}
void XBitOr( ftn_type *opnd1, ftn_type *opnd2 ) {
//==================================================
opnd1->intstar4 = ( opnd1->intstar4 | opnd2->intstar4 );
}
void XBitNot( ftn_type *opnd1, ftn_type *opnd2 ) {
//===================================================
opnd1->intstar4 = ~opnd2->intstar4;
}
//------------------------------------------- CMP routines
void XICmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
if( opnd1->intstar4 < opnd2->intstar4 ) {
cmp = 0;
} else if( opnd1->intstar4 == opnd2->intstar4 ) {
cmp = 1;
} else {
cmp = 2;
}
opnd1->logstar4 = res[ cmp ];
}
void XRCmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
if( opnd1->single < opnd2->single ) {
cmp = 0;
} else if( opnd1->single == opnd2->single ) {
cmp = 1;
} else {
cmp = 2;
}
opnd1->logstar4 = res[ cmp ];
}
void XDCmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
if( opnd1->dble < opnd2->dble ) {
cmp = 0;
} else if( opnd1->dble == opnd2->dble ) {
cmp = 1;
} else {
cmp = 2;
}
opnd1->logstar4 = res[ cmp ];
}
void XECmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
if( opnd1->extended < opnd2->extended ) {
cmp = 0;
} else if( opnd1->extended == opnd2->extended ) {
cmp = 1;
} else {
cmp = 2;
}
opnd1->logstar4 = res[ cmp ];
}
void XCCmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
cmp = 2;
if( ( opnd1->complex.realpart == opnd2->complex.realpart ) &&
( opnd1->complex.imagpart == opnd2->complex.imagpart ) ) {
cmp = 1;
}
opnd1->logstar4 = res[ cmp ];
}
void XQCmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
cmp = 2;
if( ( opnd1->dcomplex.realpart == opnd2->dcomplex.realpart ) &&
( opnd1->dcomplex.imagpart == opnd2->dcomplex.imagpart ) ) {
cmp = 1;
}
opnd1->logstar4 = res[ cmp ];
}
void XXCmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//============================================================================
int cmp;
cmp = 2;
if( ( opnd1->xcomplex.realpart == opnd2->xcomplex.realpart ) &&
( opnd1->xcomplex.imagpart == opnd2->xcomplex.imagpart ) ) {
cmp = 1;
}
opnd1->logstar4 = res[ cmp ];
}
void XChCmp( ftn_type *opnd1, ftn_type *opnd2, const logstar1 __FAR *res ) {
//=============================================================================
opnd1->logstar4 = res[ 1 + LexStrCmp( opnd1->cstring.strptr,
opnd1->cstring.len,
opnd2->cstring.strptr,
opnd2->cstring.len ) ];
}
//-------------------------------------------- exponentiation
void GenExp( TYPE typ ) {
//==========================
OPTR op;
AddConst( CITNode );
AddConst( CITNode->link );
op = OPTR_EXP;
GenOprTable[ op ]( typ, typ, op );
}
static void InitOne( TYPE typ, ftn_type *one ) {
//==================================================
switch( typ ) {
case TY_INTEGER_1:
case TY_INTEGER_2:
case TY_INTEGER:
one->intstar4 = 1;
break;
case TY_REAL:
one->single = 1;
break;
case TY_DOUBLE:
one->dble = 1;
break;
case TY_TRUE_EXTENDED:
one->extended = 1;
break;
case TY_COMPLEX:
one->complex.realpart = 1;
one->complex.imagpart = 0;
break;
case TY_DCOMPLEX:
one->dcomplex.realpart = 1;
one->dcomplex.imagpart = 0;
case TY_TRUE_XCOMPLEX:
one->xcomplex.realpart = 1;
one->xcomplex.imagpart = 0;
}
}
static bool ZeroBase( TYPE typ, ftn_type *base ) {
//====================================================
switch( typ ) {
case TY_INTEGER_1:
case TY_INTEGER_2:
case TY_INTEGER:
return( base->intstar4 == 0 );
case TY_REAL:
return( base->single == 0 );
case TY_DOUBLE:
return( base->dble == 0 );
case TY_TRUE_EXTENDED:
return( base->extended == 0 );
case TY_COMPLEX:
return( ( base->complex.realpart == 0 ) &&
( base->complex.imagpart == 0 ) );
case TY_DCOMPLEX:
return( ( base->dcomplex.realpart == 0 ) &&
( base->dcomplex.imagpart == 0 ) );
default: // case TY_XCOMPLEX:
return( ( base->xcomplex.realpart == 0 ) &&
( base->xcomplex.imagpart == 0 ) );
}
}
static void (* const __FAR Mul[])( ftn_type *, ftn_type * ) =
{ &MulIOFlow, &MulIOFlow, &MulIOFlow,
&MulR, &MulD, &MulE,
&MulC, &MulQ, &MulX };
static void (* const __FAR Div[])( ftn_type *_x, ftn_type *_y ) =
{ &DivI, &DivI, &DivI,
&DivR, &DivD, &DivE,
&DivC, &DivQ, &DivX };
void ExpI( TYPE typ, ftn_type *base, intstar4 exponent ) {
//===========================================================
bool odd;
ftn_type result;
if( ZeroBase( typ, base ) ) {
if( exponent <= 0 ) {
Error( EX_Z_2_NOT_POS );
}
} else if( exponent == 0 ) {
InitOne( typ, base );
} else {
InitOne( typ, &result );
if( exponent < 0 ) {
// base == 1 / base
Div[ typ - TY_INTEGER_1 ]( &result, base );
*base = result;
InitOne( typ, &result );
exponent = -exponent;
}
if( ( exponent & 1 ) != 0 ) {
result = *base;
}
exponent /= 2;
while( exponent != 0 ) {
for(;;) {
Mul[ typ - TY_INTEGER_1 ]( base, base );
odd = ( ( exponent & 1 ) != 0 );
exponent /= 2;
if( odd ) break;
}
Mul[ typ - TY_INTEGER_1 ]( &result, base );
}
*base = result;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?