When I can I try and do some programming for myself. It is not as often as I would like, as I have a family and can never keep a computer in good shape, but I do try it from time to time.
Sometimes I try and put forward a challenge. One I did previously came out of a project for work (a previous job). That team was big on testing, so I created a tool that could take two unspecified inputs and determine if they are equal. I created it in C# and .Net, and use that languages reflection capability to determine the parts of an object and compare them to the same part of the other if it exists. It is called GenericDeepEquality, the code is on GitHub and I have published a NuGet package, located here.
The current challenge I am undertaking is creating a library for Math with Big Numbers. Also, maybe, designing it to work for any base number system. This isn't to make the next great Math library, it's just to figure out how to do it and play with algorithms for mathematical functions.
So, now it time to work through some ideas to determine where I am going to start.
The main issue of a big number is the big number and how to handle it. In C# an integer is represented by an int. An int has the ability to represent a number between -2,147,483,648 to 2,147,483,647, That's a lot of number space, but it's not enough for the federal budget, for example, and there are applications that require much larger numbers, like cryptography.
Additionally, there are technically three main parts of a number variable, assigning the number a value, storing that value and displaying that value. Some might ask about manipulating the value, but with math, the operations usually produce new values, so that is different, also, that is a different part of the processes in general.
Terminology: As I am using it, not necessarily completely accurate to math.
- digit - one "character" of a number. 19 has the digits of 1 and 9. Digit may seem to imply base 10, but I am using it in a more generic manner.
- significant digit - a representation of the position of a digit in a number. Standard terminology has the "least significant digit" being the digit representing the zeroth power of the base in the number and the "most significant digit" being the digit representing the highest power of the base in the number. In 19, the most significant digit is 1 and the least significant digit is 9.
- base - The number of values available for a single digit. For example base 2 have 0 & 1, where as base 10 has 0, 1, 2, 3, 4, 5, 6, 7, 8 & 9. A number can be written as the sum of a series of single digit numbers times a power of the base representing it's location in then number. 19 can be written as 1*101 + 9*100.
Before we can do anything else we need to determine how we are going to store the value. Now, much like you can write a number larger than 9 by adding another digit to the left (10), we can create an array of ints, such that the following ints would represent the next significant "digit" in the number. So, an array of integer values (int being one possible type). Of course, now as I'm thinking about it, I should do them all.
So, what I'm thinking now is I need to create an interface, so that all of the different versions can be used in the same algorithms. Now I need to figure out what I need for a number interface.
I'm going to put this out there and come back to designing the interface.
No comments:
Post a Comment