#include #include "validate.h" #include "funcList.h" bool ValidateAdd( const string& operation ) // // Input: A, B, C, where C = A + B // { if( operation != "add" ) return false; ln a, b, c, d; cin >> a >> b >> c; d = a + b; CheckForError( d, c, "operator+( ln )" ); d = a; d += b; CheckForError( d, c, "operator+=( ln )" ); if( b.GetSize( ) == 1 ) { // will it fit in a long? if( ( b.GetDigit( 0 ) & 0x10000000 ) == 0 ) { long bLong = b.GetDigit( 0 ); if( b.IsNegative( ) ) bLong = -bLong; d = a + bLong; CheckForError( d, c, "operator+( long )" ); d = a; d += bLong; CheckForError( d, c, "operator+=( long )" ); } unsigned long intMask = ( (sizeof(int)==2) ? 0x1000 : 0x10000000 ); if( ( b.GetDigit( 0 ) & intMask ) == 0 ) { int bInt = b.GetDigit( 0 ); if( b.IsNegative( ) ) bInt = -bInt; d = a + bInt; CheckForError( d, c, "operator+( int )" ); d = a; d += bInt; CheckForError( d, c, "::operator+=( int )" ); } if( b.GetSign( ) == positive ) { // unsigned case unsigned long bULong = b.GetDigit( 0 ); if( bULong == b.GetDigit( 0 ) ) { d = a + bULong; CheckForError( d, c, "operator+( unsigned long )" ); d = a; d += bULong; CheckForError( d, c, "operator+=( unsigned long )" ); } unsigned int bUInt = b.GetDigit( 0 ); if( bUInt == b.GetDigit( 0 ) ) { d = a + bUInt; CheckForError( d, c, "operator+( unsigned int )" ); d = a; d += bUInt; CheckForError( d, c, "operator+=( unsigned int )" ); } } } return true; } static TestFunctionList RegFunc( ValidateAdd );