# Integer Arithmetic

The computer relies on arithmetic. Here we test a variety of arithmetic operations expressed as 32 bit two's complement binary numbers (Java's int).

 eg.ArithmeticFixture x y + - * / 0 0 0 0 0 0```Traceback (most recent call last): File "../fit/fit/Fixture.py", line 56, in doCells self.doCell(cells, i) File "/home/simon/fit/python-Source/eg/ArithmeticFixture.py", line 23, in doCell elif column == 5: self.check(cell, self.x/self.y) ZeroDivisionError: integer division or modulo by zero ``` 1 2 3 -1 2 0.5 expected0 actual 1 -1 0 2 -1 -1 10000 10000 20000 0 100000000 1 100000 100000 200000 0 10000000000```Traceback (most recent call last): File "../fit/fit/Fixture.py", line 56, in doCells self.doCell(cells, i) File "/home/simon/fit/python-Source/eg/ArithmeticFixture.py", line 22, in doCell elif column == 4: self.check(cell, self.x*self.y) OverflowError: integer multiplication ``` 1```Traceback (most recent call last): File "../fit/fit/Fixture.py", line 56, in doCells self.doCell(cells, i) File "/home/simon/fit/python-Source/eg/ArithmeticFixture.py", line 22, in doCell elif column == 4: self.check(cell, self.x*self.y) OverflowError: integer multiplication ``` 1000000 1000000 2000000 0 1000000000000```Traceback (most recent call last): File "../fit/fit/Fixture.py", line 56, in doCells self.doCell(cells, i) File "/home/simon/fit/python-Source/eg/ArithmeticFixture.py", line 22, in doCell elif column == 4: self.check(cell, self.x*self.y) OverflowError: integer multiplication ``` 1```Traceback (most recent call last): File "../fit/fit/Fixture.py", line 56, in doCells self.doCell(cells, i) File "/home/simon/fit/python-Source/eg/ArithmeticFixture.py", line 22, in doCell elif column == 4: self.check(cell, self.x*self.y) OverflowError: integer multiplication ```

Now we try something similar using automatic type conversion offered by ColumnFixtures.

 eg.ArithmeticColumnFixture x y plus() times() divide() floating() 2 3 5 6 0 0.666667 expected0.66666666666666663 actual 0 0 0 0 error error 0 0 0 0 200 300 500 60000 0 0.666667 expected0.66666666666666663 actual 2 3 10 expected5 actual 10 expected6 actual 10 expected0 actual 200 3 5 expected203 actual 6 expected600 actual 0 expected66 actual 0.666667 expected66.666666666666671 actual 2 -3 -1 -6 -0 expected-1 actual -0.666667 expected-0.66666666666666663 actual

 fit.Summary input file /usr/local/src/fit/python-Source/Documents/arithmetic.html input update Fri Oct 4 22:51:02 2002 counts 32 right, 12 wrong, 0 ignored, 5 exceptions run date Sun Oct 6 19:50:51 2002 output file /usr/local/src/fit/python-Source/Reports/arithmetic.html

Document prepaired by Ward Cunningham
First Version July 11, 2002
Last Update August 17, 2002