HP Forums

Full Version: Base converter with fractions?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(02-21-2017 05:59 PM)Jan_D Wrote: [ -> ]
(02-03-2017 01:51 PM)Jan_D Wrote: [ -> ]I slightly modified your program, not because it is not good enough but to make it better readable.

Instead of a CAS variable like tmp586605323013 it uses the CAS variable tmp.

It is also possible to make the program completely local, without using a global CAS variable tmp, and still do the calculations in CAS.

We can declare a local variable tmp, and the program will work with this local variable and use it for CAS calculations.

The only thing we have to pay attention to is that it is not allowed to use square brackets, but we have to use parentheses.

So instead of CAS("tmp[1]:=tmp[1]+d*b1^k") we have to write CAS("tmp(1):=tmp(1)+d*b1^k").

Instead of CAS("tmp(1):=tmp(1)+d*b1^k") we could also write: tmp(1):=CAS(“tmp(1)+d*b1^k").

Be careful with using non-CAS variables for CAS results. The CAS can handle integers of order larger than \( 10^{15} \) whereas we lose significant digits using non-CAS variables. So for "small" cases, your modifications would work just fine. However, for "larger" numbers (where after conversion into base 10, we would exceed the internal limit on the size of an integer), you would likely get the wrong result due to the conversion of an exact value from the CAS side into an approximate value in the non-CAS side.
(02-21-2017 07:30 PM)Han Wrote: [ -> ]Be careful with using non-CAS variables for CAS results. The CAS can handle integers of order larger than \( 10^{15} \) whereas we lose significant digits using non-CAS variables. So for "small" cases, your modifications would work just fine. However, for "larger" numbers (where after conversion into base 10, we would exceed the internal limit on the size of an integer), you would likely get the wrong result due to the conversion of an exact value from the CAS side into an approximate value in the non-CAS side.

You are completely right Han.

I did some testing, but not enough. I examined the content of tmp(2) and found out that it contained fractions, like 31/32 instead of numeric values.
Therefore I thought it did exact calculations, but you are right that this goes wrong for large integers, numerators or denominators.
Pages: 1 2
Reference URL's