Assign Operators

sint2t is signed_int< 64 > on most 32 bit machines.

Contents

Addition (+=)

sint2t mul =  sint2t( 1 ) << (UINT_BITS - 1);
sint2t a = 100, b = 300, c;

c = a;
c += b;

CHECK( c == 400 );

b = -b;

c = a;
c += b;

CHECK( c == -200 );

a *= mul;
b *= mul;

c = a;
c += b;

cout << "(" << a << " + " << b << ") = " << c << '\n';

/** only depend on unsigned characteristics here
*/
c = -((-c) / mul);

CHECK( c == -200 );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(214748364800 + -644245094400) = -429496729600
Ok

Subtraction (-=)

/** sint2t is signed_int< 64 > on most 32bit machines
*/
sint2t mul =  sint2t( 1 ) << (UINT_BITS - 1);
sint2t a = 100, b = 300, c;

c = a;
c -= b;

CHECK_PRINT( c == -200, c );

b = -b;

c = a;
c -= b;

CHECK_PRINT( c == 400, c );

a *= mul;
b *= mul;

c = a;
c -= b;

cout << "(" << a << " - " << b << ") = " << c << '\n';

c /= mul;

CHECK_PRINT( c == 400, c );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(214748364800 - -644245094400) = 858993459200
Ok

Multiplication (*=)

sint2t mul =  sint2t( 1 ) << (UINT_BITS - 1);
sint2t a = 400, b = 300, c;

c = a;
c *= b;

CHECK_PRINT( c == 120000, c );

b = -b;

c = a;
c *= b;

CHECK_PRINT( c == -120000, c );

a *= mul;

c = a;
c *= b;

cout << "(" << a << " * " << b << ") = " << c << '\n';

/** only depend on unsigned characteristics here
*/
c = -((-c) / mul);

CHECK_PRINT( c == -120000, c );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(858993459200 * -300) = -257698037760000
Ok

Division (/=)

sint2t mul =  sint2t( 1 ) << (UINT_BITS - 1);
sint2t a = 1200, b = 30, c;

c = a;
c /= b;

CHECK_PRINT( c == 40, c );

b = -b;

c = a;
c /= b;

CHECK_PRINT( c == -40, c );

a *= mul;
b *= mul;

c = a;
c /= b;

cout << "(" << a << " / " << b << ") = " << c << '\n';

CHECK_PRINT( c == -40, c );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(2576980377600 / -64424509440) = -40
Ok

Modulus (%=)

sint2t mul =  sint2t( 1 ) << (UINT_BITS - 1);
sint2t a = 1215, b = 30, c;

c = a;
c %= b;

CHECK_PRINT( c == 15, c );

b = -b;

c = a;
c %= b;

CHECK_PRINT( c == -15, c );

a *= mul;
b *= mul;

c = a;
c %= b;

cout << "(" << a << " / " << b << ") = " << c << '\n';

/** only depend on unsigned characteristics here
*/
c = -((-c) / mul);
CHECK_PRINT( c == -15, c );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(2609192632320 / -64424509440) = -32212254720
Ok