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
1 2 3 -1 2 0.5
1 -1 0 2 -1 -1
10000 10000 20000 0 100000000 1
100000 100000 200000 0 10000000000 1
1000000 1000000 2000000 0 1000000000000 1


switch( $node->key() ) {
case 0:
$this->x = intval( $node->cData );
break;
case 1:
$this->y = intval( $node->cData );
break;
case 2:
$this->_checkCell( $node, $this->x + $this->y ); break;
break;
case 3:
$this->_checkCell( $node, $this->x - $this->y ); break;
break;
case 4:
$this->_checkCell( $node, $this->x * $this->y ); break;
break;
case 5:
if( $this->y == 0 ) {
throw new Exception( 'ArithmeticException: / by zero' );
}
$this->_checkCell( $node, $this->x / $this->y ); break;
break;

default:
break;
}



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