#include "iostream.h"
#include "math.h"
#define bits ( sizeof( int ) * 8 - 1 )
static int CheckFlag( int x, int y )
{
int s1 = x >> bits;
int s2 = y >> bits;
s1=abs(s1);
s2=abs(s2);
return ( s1 * 2 + s2 );
}
static int SameSign( int Flag, int x, int y )
{
int t[2] = { x, y };
long z = x - y;
int s = z >> (bits+32);
s=abs(s);
return t[s];
}
static int DiffSign(int Flag,int x,int y) 比较
{
int t[2] = { x, y };
return t[Flag - 1];
}
static int (*FuncList[4])(int Flag,int x,int y)={SameSign, DiffSign, DiffSign, SameSign};
static int Max( int x, int y )
{
int Flag = CheckFlag( x, y );
return (*FuncList[Flag])(Flag,x,y);
}
void main()
{
int x,y,z;
cout<<"请输入整型x的值(-32768~32767):";
cin>>x;
cout<<"请输入整型y的值(-32768~32767):";
cin>>y;
z=Max(x,y);
cout<<"最大的数:"<<z<<endl;
}
#define bits ( sizeof( int ) * 8 - 1 ) //移动的位数
static int SameSign( int Flag, int x, int y ) //函数功能:x,y同号时的比较
static int DiffSign(int Flag,int x,int y) //函数功能:x,y异号时的比较
static int (*FuncList[4])(int Flag,int x,int y)={SameSign, DiffSign, DiffSign, SameSign}; //定义函数指针数组
static int Max( int x, int y ) //函数功能:求最大值
static int CheckFlag( int x, int y ) //函数功能:检测x,y的符号
/*
Flag 的值
+ +:0
- +;1
+ 1:2
- -:3
*/