Tuesday, June 20, 2006

To Infinity But No Further!

So I'm taking a beginning programming class. The language is C++ and the most interesting thing I've learned so far is integer math. There are a few different kinds of numbers in C++ (and other languages), such as int (integers, plain numbers w/o decimals) and float (a number with decimals). The language handles operations on them differently. For example, when dividing two ints like five divided by two, the decimal is just dropped, so 5/2=2. If they were floats the answer would be 2.5.

My internal explanation for Why? was that different kinds of numbers were stored in different ways and have different limitations on them (because the limits of 32 bit computing seem always soon). So this morning I read this post linked from Digg and started to realize another handy reason why integer math exists: sometimes you don't want to spend your computer's time pondering the infinite.


killy said...

Yesterday i took the day off because adolfo's school had closed due to flooding. After we had lunch with carol, adolfo iv and i went to Microcenter to look around. Currently, they've got all sorts of books on clearance (50% off!). There were several books there on mathimatics in computing - fascinating.

Speaking of programming classes, my three-day ActionScript class is coming up. Sadly, i've been swamped at the office with nursing posters, formating publication images and other miscellaneous projects that i've hardly had the time to code a line.

Adolph said...

I think that for most people (or at least for people like me) math is probably taught too early. I forget too much of it by the time I start to really use it!

Killy, which class are you taking?

I gave the post a little more thought: how would I code adding the ints 2/3 and 1/3 together in C++? It would make a good trick question on a test because doing it linearly, "(2/3)+(1/3)" would give a result of 0, not 1. Casting the ints as floats wouldn't help much either, I think; it would probably need to be "(1+2)/3" or somesuch.