Wednesday, April 12, 2017

Base Calculator Mach Two

The changes here are small but meaningful.  Essentially, I added the ability to input and output non-integer numbers and more digit lists for fun and profit.

I added two methods, convertDecimalsFrom10:


And convertDecimalsTo10:

Both are fairly straightforward, and the only complex bit is the first for loop in convertDecimalsFrom10 -- which just tests smaller and smaller exponents until either the remaining float is less than .0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, which is a pretty small number.  As such, there is quite a bit of accuracy.


These are the current four digit lists.  The first is the standard one, which supports 2-36, the second is the extended one, which supports 2-63 (note the space), the third is the letter scale for base 26 shenanigans, and the fourth is ASCII and supports 2-94.  If you're using the ASCII one, it is recommended to not have the number contain a decimal point as you could end up with more than one.


The major issue this time was trying to avoid converting it to 10 and back.  I succeeded in doing that for integers, but unfortunately, due to the sometimes interminable nature of decimals, I could not find any bug-free way to do that here.  

Anyways, if I can solve the puzzle of changing the second float while translating the first, I'll be a happy man indeed.

No comments:

Post a Comment