Multiplication Tests

Test * over several predefined values.

All inputs and outputs are unsigned_int< 128 >

unsigned_int< 128 > left =  str_to_unsigned_int< 128 >( data->dividend  );
unsigned_int< 128 > right = str_to_unsigned_int< 128 >( data->divisor   );
unsigned_int< 128 > quo =   str_to_unsigned_int< 128 >( data->quotient  );
unsigned_int< 128 > rem =   str_to_unsigned_int< 128 >( data->remainder );

  

unsigned_int< 128 > r, s;
r = quo * right;
s = right * quo;

bool f = false;
if ( r != (left - rem) ) ++check_failures, f = true;
if ( s != (left - rem) ) ++check_failures, f = true;
 
if ( f )
{
  std::cerr << std::uppercase << std::right
    << std::hex << quo << " * " << right << '\n'
    << "got:      " << std::setw( 32 ) << r << '\n'
    << "got:      " << std::setw( 32 ) << s << '\n'
    << "expected: " << std::setw( 32 ) << (left - rem) << "\n\n"
  ;
}
return 2;

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

-----------------------

236 tests 0 failures

Test *= over several predefined values.

All inputs and outputs are unsigned_int< 128 >

unsigned_int< 128 > left =  str_to_unsigned_int< 128 >( data->dividend  );
unsigned_int< 128 > right = str_to_unsigned_int< 128 >( data->divisor   );
unsigned_int< 128 > quo =   str_to_unsigned_int< 128 >( data->quotient  );
unsigned_int< 128 > rem =   str_to_unsigned_int< 128 >( data->remainder );
  

unsigned_int< 128 > r, s;
r = quo;
r *= right;
s = right;
s *= quo;

bool f = false;
if ( r != (left - rem) ) ++check_failures, f = true;
if ( s != (left - rem) ) ++check_failures, f = true;
 
if ( f )
{
  std::cerr << std::uppercase << std::right
    << std::hex << quo << " * " << right << '\n'
    << "got:      " << std::setw( 32 ) << r << '\n'
    << "got:      " << std::setw( 32 ) << s << '\n'
    << "expected: " << std::setw( 32 ) << (left - rem) << "\n\n"
  ;
}
return 2;

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

-----------------------

236 tests 0 failures