Mark Mzyk | February 5, 2008
In my spare time, what little of it there seems to be, I’ve been working my way through the Crosswalk (Programming Erlang). I’m finding Erlang to be a fascinating language, particularly since it is also serving as my introduction to functional programming. One paragraph in particular caught my eye. On page 15, Joe Armstrong writes this:
Erlang uses arbitrary-sized integers for performing integer arithmetic. In Erlang, integer arithmetic is exact, so you don’t have to worry about arithmetic overflows or not being able to represent an integer in a certain word size.
And then Joe moves on to the next topic, like this is no big deal. Wait, you mean I don’t have to wonder if something is greater than the max int?
In fact, the only thing that limits an integer’s size is the amount of memory available on the system. Why isn’t an abstraction like this more wide spread? Why is it still necessary in so many languages for the programmer to have to worry about the max int size? Maybe this is more wide spread and I’m just not knowledgeable enough to know it.
My other thought was how does Erlang achieve this? Well, thanks to my lurking on the Erlang questions mailing list I discovered the answer: Bignum arithmetic. I had never heard of it before, but it’s one of those concepts that seems so intuitive after you read about it, you wonder why you never questioned that an int had to be confined to X number of bytes.
You never know what surprises await when you decide to learn a new programming language.
Filed in: Languages.