Post Reply 
[42S] looking for decimal to rational fraction
01-17-2019, 11:38 PM
Post: #1
[42S] looking for decimal to rational fraction
I was looking for a program to do decimal to fraction conversion on the 42S (well, DM42).

I found this older thread, where user Xose posts a link to his code at a now defunct website.

The Internet Archive had a single copy of that page here, but it contains some odd characters, and I'm unsure how to deal with them.

You can see them at the link, and here's an excerpt from the downloaded file:

Code:
00 { 163-Byte Prgm }

01<B7>LBL "FRACT"
02 XEQ 11
03 ENTER
04 FP
05 12
06 X<>Y
07 X=0?
08 Rv
09 Rv
10 +/-
11 10^X
12 2
13 <F7>
14 STO 01
15 Rv
16 STO 05
17 ENTER
18 ABS
19 STO 00
20 <F7>
21 STO 04

see e.g. lines 1, 13 & 20.

How do I enter those? Or is the listing corrupted?

thanks very much…

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
01-17-2019, 11:44 PM
Post: #2
RE: [42S] looking for decimal to rational fraction
Ah! Comparing with the 41C prog further down the page, looks like most of them are the 42S's extended RCL commands combined with an arithmetic, e.g. RCL+

But what might the odd chars before LBL be? The 41C listing has those too…

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
01-18-2019, 12:01 AM (This post was last modified: 01-18-2019 12:02 AM by rprosperi.)
Post: #3
RE: [42S] looking for decimal to rational fraction
(01-17-2019 11:38 PM)cdmackay Wrote:  How do I enter those? Or is the listing corrupted?

I'd say they are corrupted, or at least were not recognizable when pasted into the listing. Note the 'bad' characters are not random. Every label has one, a few (but not all) RCL xx statements, plus lines 13, 20, and 70.

Probably Thomas will recognize what is unique/common about the affected lines.

Of course you can ignore the bad characters in the Labels and RCL lines; just skip the bad character (though for the RCL lines they could be RCL+ nn). As the original values are no longer present, it will be hard to figure out what is missing for the 3 empty lines, unless you can figure out the intended algorithm (I can't).

Sorry, not much help....

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
01-18-2019, 12:17 AM
Post: #4
RE: [42S] looking for decimal to rational fraction
thanks Bob, it will be an exercise for me to get it working, the RCLxx bits are a good start Smile

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
01-18-2019, 12:26 AM
Post: #5
RE: [42S] looking for decimal to rational fraction
(01-17-2019 11:38 PM)cdmackay Wrote:  I was looking for a program to do decimal to fraction conversion on the 42S (well, DM42).

I found this older thread, where user Xose posts a link to his code at a now defunct website.

The Internet Archive had a single copy of that page here, but it contains some odd characters, and I'm unsure how to deal with them.

You can see them at the link, and here's an excerpt from the downloaded file:

Code:
00 { 163-Byte Prgm }

01<B7>LBL "FRACT"
02 XEQ 11
03 ENTER
04 FP
05 12
06 X<>Y
07 X=0?
08 Rv
09 Rv
10 +/-
11 10^X
12 2
13 <F7>
14 STO 01
15 Rv
16 STO 05
17 ENTER
18 ABS
19 STO 00
20 <F7>
21 STO 04

see e.g. lines 1, 13 & 20.

How do I enter those? Or is the listing corrupted?

thanks very much…

Use right-click "View Frame Source" in the Chrome browser to get a better view of the source. The funny characters before the LBL are just to make the labels stand out on the listing and can be ignored. The characters on lines 13 and 20 are the 'divide' operator.

Code:
******************************

FRACT for the HP42S

00 { 163-Byte Prgm }

01·LBL "FRACT"
02 XEQ 11
03 ENTER
04 FP
05 12
06 X<>Y
07 X=0?
08 Rv
09 Rv
10 +/-
11 10^X
12 2
13 ÷
14 STO 01
15 Rv
16 STO 05
17 ENTER
18 ABS
19 STO 00
20 ÷
21 STO 04
22 1
23 STO 02
24 CLX
25 STO 03
26 RCL 00
27·LBL 00
28 RCL 00
29 RCL× 02
30 ENTER
31 ENTER
32 2
33 1/X
34 +
35 XEQ 10
36 -
37 ABS
38 RCL 01
39 RCL× 02
40 X>Y?
41 GTO 01
42 Rv
43 Rv
44 1/X
45 ENTER
46 IP
47 ABS
48 RCL× 02
49 RCL+ 03
50 RCL 02
51 STO 03
52 Rv
53 STO 02
54 Rv
55 FP
56 GTO 00
57·LBL 01
58 RCL 00
59 RCL× 02
60 2
61 1/X
62 +
63 XEQ 10
64 RCL× 04
65 CLA
66 AIP
67 +"/"
68 RCL 02
69 AIP
70 ÷
71 STO 00
72 RCL- 05
73 +" ("
74 X=0?
75 +"=)"
76 X>0?
77 +">)"
78 X<0?
79 +"<)"
80 XEQ 12
81 AVIEW
82 RTN
83·LBL 10
84 X>=0?
85 GTO 02
86 1
87 -
88·LBL 02
89 IP
90 RTN
91·LBL 11
92 STO 10
93 Rv
94 STO 09
95 Rv
96 STO 08
97 Rv
98 STO 07
99 Rv
100 RTN
101·LBL 12
102 RCL 07
103 RCL 08
104 RCL 09
105 RCL 10
106 RTN
107 END

******************************

FRACT for the HP41C

01·LBL "FRACT"
02 ENTER^
03 FRC
04 12
05 X<>Y
06 X=0?
07 RDN
08 RDN
09 CHS
10 10^X
11 2
12 /
13 STO 01
14 RDN
15 STO 05
16 ENTER^
17 ABS
18 STO 00
19 /
20 STO 04
21 1
22 STO 02
23 CLX
24 STO 03
25 RCL 00
26·LBL 00
27 RCL 00
28 RCL 02
29 *
30 ENTER^
31 ENTER^
32 2
33 1/X
34 +
35 XEQ 10
36 -
37 ABS
38 RCL 01
39 RCL 02
40 *
41 X>Y?
42 GTO 01
43 RDN
44 RDN
45 1/X
46 ENTER^
47 INT
48 ABS
49 RCL 02
50 *
51 RCL 03
52 +
53 RCL 02
54 STO 03
55 RDN
56 STO 02
57 RDN
58 FRC
59 GTO 00
60·LBL 01
61 RCL 00
62 RCL 02
63 *
64 2
65 1/X
66 +
67 XEQ 10
68 RCL 04
69 *
70 RCL 02
71 RTN
72·LBL 10
73 CHS
74 X<=0?
75 GTO 02
76 1
77 -
78·LBL 02
79 INT
80 CHS
81 RTN

— Ian Abbott
Find all posts by this user
Quote this message in a reply
01-18-2019, 12:47 AM
Post: #6
RE: [42S] looking for decimal to rational fraction
You can get Ian's cleaned-up Version into the DM42 without retyping it, as follows:

First, remove the funny characters in front of the LBLs (all seven of them) and replace them with spaces.
Next, find the five lines that start with +" (plus sign followed by double quote) and change those plus signs to |- (vertical bar followed by minus sign)

Then, copy the program text and paste it into Free42 in PRGM mode. Check your work by making sure the pasted program has the right number of lines and bytes.

You can now use Export Programs to create a raw file, which you can transfer to the DM42 and load there.
Visit this user's website Find all posts by this user
Quote this message in a reply
01-18-2019, 01:24 AM
Post: #7
RE: [42S] looking for decimal to rational fraction
(01-18-2019 12:26 AM)ijabbott Wrote:  Use right-click "View Frame Source" in the Chrome browser to get a better view of the source. The funny characters before the LBL are just to make the labels stand out on the listing and can be ignored. The characters on lines 13 and 20 are the 'divide' operator.

Nice tip, thanks Ian. View Frame Source works in FF as well.

(01-18-2019 12:47 AM)Thomas Okken Wrote:  You can get Ian's cleaned-up Version into the DM42 without retyping it, as follows:

First, remove the funny characters in front of the LBLs (all seven of them) and replace them with spaces.
Next, find the five lines that start with +" (plus sign followed by double quote) and change those plus signs to |- (vertical bar followed by minus sign)

Then, copy the program text and paste it into Free42 in PRGM mode. Check your work by making sure the pasted program has the right number of lines and bytes.

You can now use Export Programs to create a raw file, which you can transfer to the DM42 and load there.

See what I mean... Wink

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
01-18-2019, 07:55 PM
Post: #8
RE: [42S] looking for decimal to rational fraction
thanks very much indeed Ian & Thomas, much appreciated.

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
01-18-2019, 08:20 PM
Post: #9
RE: [42S] looking for decimal to rational fraction
(01-18-2019 12:47 AM)Thomas Okken Wrote:  
Then, copy the program text and paste it into Free42 in PRGM mode. Check your work by making sure the pasted program has the right number of lines and bytes.

You can now use Export Programs to create a raw file…

Alternatively for those without Free42 to hand [why not? Smile] this decoder also works perfectly (once Thomas's corrections are made):

https://www.swissmicros.com/dm42/decoder/

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
01-18-2019, 08:36 PM
Post: #10
RE: [42S] looking for decimal to rational fraction
hmm. although it works perfectly on Free42 Decimal Mac, it gets a Size Error on Free42 Android, and Invalid Type on DM42.

further assembly required…

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
01-18-2019, 09:18 PM (This post was last modified: 01-18-2019 09:36 PM by cdmackay.)
Post: #11
RE: [42S] looking for decimal to rational fraction
There were two problems: first, on my Free42 Android, somehow the REGS matrix had disappeared, causing the Size Error. A SIZE 25 sorted that out.

However, the program appears to be a little brittle regarding the stack contents when it starts.

It starts by jumping to LBL 11, which saves the stack contents into R07–R10:

Code:
01 LBL "FRACT"
02 XEQ 11

91 LBL 11
92 STO 10
93 Rv
94 STO 09
95 Rv
96 STO 08
97 Rv
98 STO 07
99 Rv
100 RTN

and it restores them when it's done.

Unfortunately, those STO fail if there's something on the stack that can't be saved into a register, causing the Invalid Type. For example, a matrix, if you've just done a SIZE 25 Smile

That's fixed by putting some reals on the stack first. Normally not likely to be an issue, but not ideal.

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
Post Reply 




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