Lecture 4 - An introduction to computer arithmetic Flashcards
What are numbers on a computer?
A collection of binary digits (bits)
What are the two different ways numbers are represented on a computer?
Fixed point and floating point
What is a byte?
Short for binary term.
8 bits
Enough to hold a single character of text
What is a word?
Natural data size of a computer.
Depends on the CPU but for most desktop systems it is 32 bits (64 for newer systems)
What is a kilobyte?
2**10 bytes
What is a megabyte?
2**20 bytes
What is a Gigabyte?
2**30 bytes
What does the first number of a fixed point number represent?
The sign of the integer
0 - positive
1 - negative
What base are bits in?
Base 2
How do you multiply a fixed point number by a power of 2?
Shift the bits left
How do you multiply a fixed point number by a number which is not a power of 2?
Use the shift and ass algorithm. Express as a sum of powers.
How do you divide a fixed point number by a factor of 2?
Shift right. Drop the fractional part
What is overflow?
When the fixed point number you are trying to produce cannot be written with the number of bits being used.
What is fixed point data called in R?
Integers
How many bits are used to store fixed point data in R?
32
What is returned when you overflow a fixed point number on R?
N/A
Advantages of fixed point numbers in R.
- Results are exact
- Fast
Disadvantages of fixed point numbers in R.
- Limited applicability: integers and relaxed
- Limited range.
What are the 4 different components to make up a floating point number in R?
Sign
Fraction - unsigned integer
Base
Exponent - signed integer
What are the number of bits assigned to each component making up a floating point number on R using an 8 bit system?
1 bit for sign
3 bits for exponent
4 bits for the fraction
Why are there limitations with floating point numbers?
As the fraction and exponent are stored in a fixed number of bits.
What is the largest possible floating point number in an 8 bit system?
7.5
What is the smallest possible floating point number in an 8 bit system?
0.0078125
What is the machine epsilon and what does it govern?
The machine epsilon is the smallest positive integer such that epsilon + 1.0 is not equalto 1.0. It governs the relative accuracy of the system.
What is the machine epsilon equal to?
2**(1-d) where d is the number of bits in the fraction.
What are the consequences from a lack of accuracy of floating point numbers?
Things rarely add up because of rounding errors.
Order of summation matters.
Maximum error when adding n values to x is < (nepsilonx)/2
Mixed signs can cause problems.
What are floating point numbers called in R?
Numeric
How many bits are used for floating point numbers in R?
64
How are the bits distributed to the components making up a floating point number in R?
1 - sign
11 - exponent
53 - fraction
What is the largest possible floating point number in R?
8.98 x 10**(307)
What is the machine epsilon in R?
2.20x10**(-16)
What is returned for overflow of a floating point number in R?
+inf and -inf
What does NaN mean in R?
Not a number
What are underflows for floating point numbers set to in R and what is the warning message?
0, no warning generated.
How can you deal with floating point limitations?
- rewrite expressions to avoid overflow
- normalise scalars
- change exact tests to good enough tests
- be careful about order of operations
- use double precision (uses twice the memory)
Many of these show a trade between speed and accuracy
What are the advantages of floating point numbers in R?
Wider applicability
Wider range than fixed point
What are the disadvantages of floating point numbers in R?
Results are not exact
Slow
How is the correspondence between stored numbers and displayed symbols determined?
By a character set
What are 3 examples of character sets and what are the numbers of bits in the systems?
ASCII - 7 bit system
Extended ASCII - 8 bit system
UNICODE - 16 bit system