Test / and % 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 > d = left / right, m = left % right;
if ( !( ( d == quo ) && ( m == rem ) ) )
{
++check_failures;
std::cerr << std::hex << std::uppercase
<< "doing: " << left << " / " << right << '\n'
<< "got: " << d << " - " << m << '\n'
<< "expected: " << quo << " - " << rem << "\n\n"
;
}
return 1;
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
----------------------- 118 tests 0 failures
As above, but the right hand side is unsigned_int< 32 >
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 );
typedef unsigned_int< 32 > uint32t;
uint32t right = _right, rem = _rem;
if ( _right != right ) return false;
if ( _rem != rem ) return false;
unsigned_int< 128 > d = left / right;
uint32t m = left % right;
if ( !( ( d == quo ) && ( m == rem ) ) )
{
++check_failures;
std::cerr << std::hex << std::uppercase
<< "doing: " << left << " / " << right << '\n'
<< "got: " << d << " - " << m << '\n'
<< "expected: " << quo << " - " << rem << "\n\n"
;
}
return 1;
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
----------------------- 82 tests 0 failures
As above, but the left hand side is unsigned_int< 32 >
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 );
typedef unsigned_int< 32 > uint32t;
uint32t left = _left, quo = _quo;
if ( _left != left || quo != _quo ) return 0;
uint32t d = left;
unsigned_int< 128 > m = _left;
d /= right;
m %= right;
if ( !( ( d == quo ) && ( m == rem ) ) )
{
++check_failures;
std::cerr << std::hex << std::uppercase
<< left << " / " << right << '\n'
<< "got: " << d << " - " << m << '\n'
<< "expected: " << quo << " - " << rem << "\n\n"
;
}
return 1;
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
----------------------- 30 tests 0 failures