Decimals to improper fractions program?
|
06-05-2018, 06:36 PM
(This post was last modified: 06-06-2018 01:17 PM by Dieter.)
Post: #4
|
|||
|
|||
RE: Decimals to improper fractions program?
(06-05-2018 05:13 AM)Oddballs Wrote: I am trying to program my HP35s and Free42 to take a decimal number and convert it to improper fractions... On this site you will find various programs that convert a decimal number into fractions. For instance this program that is based on the one in the HP67/97 math pac. Here is a slightly modified version for the HP41. Set the display mode to the desired accuracy and the result is a fraction that agrees with the original value to display precision. It should also run on the 42s. Here you can omit the PSE at the end because numerator and denominator will be returned in the two display lines as Y and X. Code: 01 LBL"DF" Example: Find approximations for pi that agree in 2, 6 and 9 decimals. FIX 2 [pi] XEQ"DF" => "22" 7 FIX 6 [pi] XEQ"DF" => "355" 113 FIX 9 [pi] XEQ"DF" => "104348" 33215 You can also set SCI display mode. In this case the calculated fraction agrees with the input to the specified number of significant digits. On the 35s you could use an adapted version of this program. But why don't you simply take advantage of the built-in decimal-fraction conversion (FDISP key)? OK, this returns proper fractions, but you can easily convert these to improper ones. The 35s function can also be individually configured with flags and the /c key. Take a look at the manual for more information. Edit and Update: Here is a somewhat optimized version for the 42s / Free42. It returns the numerator and denominator as well as the approximation and its error. Also negative results are properly displayed. Code: 00 { 90-Byte Prgm } Example: approximate ln 2 to six decimals. Code: [DISP] [FIX] 6 BTW, in ALL mode on Free42 I obtained this approximation of pi... 66 627 445 592 888 887 / 21 208 174 623 389 167 ...which indeed agrees in 34 significant digits. ;-) Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)