All decimal digits of reals in CAS

04072015, 03:17 AM
(This post was last modified: 05292017 01:41 PM by Joe Horn.)
Post: #1




All decimal digits of reals in CAS
This program, called "dec", outputs the exact internal decimal value of a floating point number in CAS. It is similar to (and is based on) my "hex" program with the only difference being that the output of "dec" is in standard decimal format, instead of hexadecimal.
Syntax in CAS: dec(real) Output: exact decimal representation of the real in scientific notation. Example in CAS: dec(pi) > "3.1415926535897824578569270670413970947265625" This means that pi in CAS is internally stored as exactly the same value as the displayed decimal number. The value is actually stored in binary, of course, but sometimes seeing its decimal equivalent is helpful, so that's what "dec" was created to do. If the display modes allowed settings up to 50 digits, there would be no need for this program. Trivial bonus feature: If the input is a ratio of exact integers, "dec" attempts to return all the digits of the ratio, up to 1000 digits. I cannot imagine any possible use for this feature. Example: dec(1./1537) > "6.506180871828206591089838184416294097900390625E4" (notice the "." in the input) dec(1 /1537) > "6.50618087182823682498373454782042940793754066363044892648015614834...E4" (1000 digits) "dec", a CAS program: Code: #cas Interesting exploration: Compare dec(pi) with dec(pI) with "pi" and "pI" spelled exactly as shown. See the difference in the results? pI is CAS's name for Home's pi. Disclaimer: Extensive testing on extreme inputs and goofy inputs and illegal inputs has not been done. It'll probably choke on stupid inputs. Weeding them out is left as an exercise for the student. X<> c Joe 

04102015, 02:55 PM
(This post was last modified: 04112015 03:10 AM by compsystems.)
Post: #2




RE: "dec": All decimal digits of reals in CAS
Thank You
I'm porting the code to other models of calculators, ti68k not have the XPON() command that I know, What does this function? mathematically (algorithm) ti68k & tinspireCAS code Code:


04102015, 08:14 PM
Post: #3




RE: "dec": All decimal digits of reals in CAS
Quote:ti68k not have the XPON() command that I know, What does this function? If you type the command in on the calculator and press help, you will see Code:
Hope it helps Cheers, Terje 

04102015, 09:02 PM
Post: #4




RE: "dec": All decimal digits of reals in CAS
(04102015 08:14 PM)Terje Vallestad Wrote:Quote:ti68k not have the XPON() command that I know, What does this function? XPON(X) is equivalent to \( \lfloor \log_{10}(X) \rfloor \)  the floor of the base10 logarithm of X. Graph 3D  QPI  SolveSys 

04112015, 02:43 AM
(This post was last modified: 04112015 03:42 AM by compsystems.)
Post: #5




RE: "dec": All decimal digits of reals in CAS
thanks Han
versión 1 in tibasic ti68k Code: version 2 in tibasic ti68k Code: version3 in tibasic ti68k with solve cmd Code: another samples dec(e) => "2.7182818284590410939927096478641033172607421875" dec(√(2)) "1.4142135623730922588947578333318233489990234375" always returns ~50 digits Joe Horn, please add at the beginning of your code, check flag should be in exact mode, otherwise always returns until 50 digits in tibasic is Code: setMode("exact/approx","exact") Another possible improvement is to support complex numbers, operating in the imaginary part and real part separately in tibasic some commands are extended to the field of complex sample fpart(1.234+5.6789*i) => 0.234+0.6789*i 

04122015, 03:15 AM
(This post was last modified: 04122015 03:21 AM by Joe Horn.)
Post: #6




RE: "dec": All decimal digits of reals in CAS
(04112015 02:43 AM)compsystems Wrote: dec(e) => "2.7182818284590410939927096478641033172607421875" There seems to be a misunderstanding here. The "dec" program does not return "about 50 digits". It always returns ALL the digits, no matter how many that may be. The reason that dec(e) returns "2.7182818284590410939927096478641033172607421875" is because that decimal number is EXACTLY how Prime stores e internally in CAS. It's not an approximation.* "dec" returns the exact decimal of the real input, no matter how many decimal digits that may require. It doesn't arbitrarily stop after 50 digits, or any other number of digits. (Exception: if the input is a ratio of two integertype objects, "dec" stops after outputting 1000 digits, as explained in the original posting). Other ways of seeing exactly the same value using my other routines: hex(e) > "1.5BF0A8B14576p+1" d2f(e) > 191282078589627/2^46 * Ok, ok, to be perfectly clear: it IS an approximation of the math constant e... but it's not an approximation of CAS's real floatingpoint value of e. It's exactly equal to THAT value, which is itself a rational approximation of the irrational constant known as "e". X<> c Joe 

04222015, 03:33 AM
(This post was last modified: 04222015 03:33 AM by Joe Horn.)
Post: #7




RE: "dec": All decimal digits of reals in CAS
(04202015 02:54 PM)compsystems Wrote: Please Joe Horn can comment on each line of code DEC() to understand the logic of the algorithm See listing below. The explanations are below their respective lines of code. "Pathological input" means reals so close to integers that some CAS functions fail to distinguish between them and the neighboring integer. Basic concept: Multiply by 10, chop off the integer part, and repeat, until input goes to zero. Input > Output string at each iteration 3.1416 > "3." 1.416 > "3.1" 4.16 > "3.14" 1.6 > "3.141" 6 > "3.1416" 0 > Exit Code: #cas X<> c Joe 

11022016, 10:05 PM
Post: #8




RE: "dec": All decimal digits of reals in CAS
I wonder what has changed since 10637, but running this as dec(pi) results on nonstop "Running non recursive evaluator"
Any suggestions? Thanks 

11062016, 04:04 AM
Post: #9




RE: "dec": All decimal digits of reals in CAS
(11022016 10:05 PM)Alberto Candel Wrote: I wonder what has changed since 10637, but running this as dec(pi) results on nonstop "Running non recursive evaluator" Strange; I get "3.1415926535897824578569270670413970947265625" on my rev 10637 Prime after about 0.885 seconds. Are you sure your listing is correct? X<> c Joe 

11062016, 05:44 AM
Post: #10




RE: "dec": All decimal digits of reals in CAS
Thank you for looking into it. But yes, I have 10637.
dec(pi) (or anything) shows "Running no recursive evaluator" and breaking the program shows "Bad index error: Bad Argument value" It could be something else with my Prime. 

11072016, 04:16 AM
Post: #11




RE: "dec": All decimal digits of reals in CAS
(11062016 05:44 AM)Alberto Candel Wrote: Thank you for looking into it. But yes, I have 10637. Just a guess: try resetting the recursive CAS settings to their defaults (Shift CAS, Page down, Shift Esc). If that doesn't help, then please post your program listing exactly asis, since there might be a typo in it. X<> c Joe 

11072016, 03:05 PM
(This post was last modified: 11072016 06:16 PM by Alberto Candel.)
Post: #12




RE: "dec": All decimal digits of reals in CAS
Well, that was it! For some reason I do not know, in my 2 HP Primes the recursive setting was "1" After reseting it is "100"
Your "dec" program works now like a charm. Thank you! 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)