Computer Arithmetic
Carry = 1 if ’1’ bit gets carried out of MSB. Indicates error in
unsigned no. system.
V = 1 if
A+B, MSB(A) = MSB(B) MSB(Result)
A-B, MSB(A) MSB(B) and MSB(Result) MSB(A)
Sign extension: copy MSB to all the higher
bits.
Multi-precision arithmetic: add the lower 32-bit words,
then ADC the upper 32-bit words.
Range of 2’s comp =
to
Fixed point
Precision = value of LSB (smallest fractional value)
, precision is .
Precision is fixed and uniform throughout the range.
For a fixed number of bits, allocating more bits for the integer part (increase range) will reduce the precision.
Floating point
32-bit: 1 (Sign), 8 (exponent, ), 23 (fraction, ), bias = 127
64-bit: 1 (Sign), 11 (exponent, ), 52 (fraction, ), bias = 1023
Format:
E.g. 1 00001100 010100....0
Normalised mode
Maintain a non-zero digit (1) before the radix point.
Exponent range: 0000 0001 to 1111 1110
Smallest magnitude: X 0000 0001 0000....0
Largest magnitude: X 1111 1110 1111 ....1
Underflow: numbers between to , i.e. values close to zero that cannot be represented.
Fixed vs floating pt (32-bit)
Max range (fixed) = (no fractional part)
Max range (floating) = ( to )
Max precision (fixed) = (no integer part)
Max precision (floating, near to 0) = less than
Floating point has higher range and better precision at small numbers, but very coarse precision at the 2 ends of the range. Floating point provides uniform precision across entire range.
More stuff
Arithmetic between numbers with huge diff in magnitude: add/subtract numbers of similar smaller magnitude first, to allow their magnitude to be closer to the bigger magnitudes.
To preserve precision AMAP, do division last, as division truncates LSB and loses bits.