It turns out that trying to convert numbers from bases to bases without going through base 10, which already proved itself troublesome with decimal inputs, is nearly impossible with decimal bases. As such, although the program works, it is without the dramatic flair which it would otherwise have had.
Anyways, let us begin.
Here, you can see two translation lists, an accuracy, and a rather unusual input.
A moment of silence for the fallen. Their functionality has been replaced, their usefulness is no longer extant, and now their watch has ended.
This method takes any base 10 number and converts it to any other base. Note the $accuracy, which gives the number of decimal places it is accurate to. The higher the accuracy, the higher the...well...accuracy. However, there is the danger that you'll get an infinity error if the number gets too small, so some care must be had.
This method is mostly unchanged from the previous version and entirely unchanged in effect.
This method is exactly like convertDecimalsTo10, but with the order reversed (so as to increment going to the right), the exponents multiplied (because they're treated as positive), the for loop going from zero instead of one, and the printed statement saying it's dealing with ints.
This is a safety net, which makes sure that if a decimal point is in the inputed alphabet, the inputed number is treated as an integer. The outputted one, however, can be a non-int.
And so the most powerful base calculator ever made ends, with very few changes for precision.
The main problem this week, however, was not the methods. The main problem was the fact that, for example, (.25 - .2 ) returned .04999999999. This, remarkably, isn't good.
Luckily, after talking with Dr. Manilich, the professor who will teach Ruby on Rails next semester, I found a solution in the way of these lines:
BigDecimal is a Ruby gem, designed to convert numbers to "big decimals" (to_d) and so to be able to calculate with extreme precision. I downloaded it, required it, and so solved the problem and finished the program.
No comments:
Post a Comment