Homework 3: Computer Math

Of course computers can do math. But exactly how computers do math is a bit of a surprise to beginning programmers. Computer math is not exactly like the math you have been learning all this time. We need to play with it a bit and see why.


One basic kind of number used in computers is an “integer”. This is a simple one, it has no fractional part, and no decimal point (or commas for that matter):

  • 1,3,5,-7, 11 are all integers

Integer Operations

  • Adding, subtracting and multiplication all act normally.

  • Division is different!

    • remember how you did this in elementary school!
  • What is 5 / 2?

    • Not 2.5, tht is a different number
    • 2 goes into 5 2 times (with a remainder of 1)
    • You learned this long ago, but probably forgot it.
  • Limits

    • From HW2, you say the range of legal numbers for some “types” of numbers in C++

    • What happens if you go beyond those values.

      • unsigned number is 0, what is one less than that?
      • unsigned number is limited to 255, what is one more than that?

Floating Point Numbers

“Real” numbers have decimal points, and fractional parts. They can be very big, or very little.

  • Two different ways of showing them:

    • Fixed point: 4.5

    • Scientific: 0.45E+01

      • The “Enn” part adjusts the decimal point by some power of 10)
    • Not every number can be represented: 1.0/3.0

      • The “errors” in numbers can be a problem in some calculations: 1.0 / 3.0 * 3.0 = 0.99999999999

What to do

As part of learning about computer arithmetic, let’s explore some basic terms. o a bit of research into computer arithmetic. Specifically see what you can find out about these terms:

  • Arithmetic Overflow
  • Arithmetic Underflow
  • IEEE Floating Point
  • Double Precision
  • Sign Bit
  • Rounding/Truncation
  • Arbitrary Precision
  • Precedence Rules

write a short paragraph describing what each of these terms is about. Submit that text file on BB.