Stories
Slash Boxes
Comments

SoylentNews is people

Submission Preview

Link to Story

Making a bignum library for fun

Accepted submission by owl at 2024-06-18 14:51:34
Software
https://austinhenley.com/blog/bignum1.html [austinhenley.com]

What happens when numbers get too big for a computer to work with?

For example, a 64-bit unsigned integer can be as large as 18,446,744,073,709,551,615. That is... huge. But what if it isn't enough?

Enter bignums, or arbitrary-precision numbers. These very, very large numbers allow you to go beyond CPU limitations for representing integers and performing arithmetic, limited only by the computer's memory.

If you open up Python and throw some really, really big numbers at it, you'll see that it works without any issue. Although C requires using a library for bignums, Python supports them right out of the box. In fact, you can use big numbers and small numbers interchangeably and it is completely abstracted away from the programmer.

I've always wanted to know how these bignum libraries work, so this is my adventure in learning about them.

The irony with this blog post, for any of us who did any assembly programming on the old 8-bit microprocessors (8080/Z80/6502/6800), is that doing "big-nums" was a required bit of knowledge to do any math larger than 8-bits wide (6502) or 16-bits wide (for a few instructions on the 8080/Z80/6800). The blog writer must be one of today's Ten Thousand [xkcd.com].


Original Submission