## HP15c software: convert a floating point number into a fraction (numerator and denominator)

command display
f LBL E 001-42,21,15
g ABS 002-43 16
STO 0 003-44 0
1 004- 1
STO 1 005-44 1
f LBL 9 006-42,21, 9
R_arrow_down 007- 33
1/x 008- 15
STO * 1 009-44,20, 1
Enter 010- 36
g INT 011-43 44
- 012- 30
4 013- 4
CHS 014- 16
10^x 015- 13
x<=y 016-43 10
GTO 9 017- 22 9
RCL 0 018-45 0
RCL 1 019-45 1
g INT 020-43 44
* 021- 20
f PSE 022-42 31
g LST X 023-43 36
g RTN 024- 43 32

This program uses the following labels: LBL E and LBL 9

### Using the program

I start every program with a label. This way you can have a number
of programs in your 15c and you just select which one to run by pressing f LABELNAME (f E in this case) or GSB LABELNAME (GSB E in this case).

Let's say you would like to know what 0.15625 as a fraction is.

You type: 0.15625, GSB E

The display shows "running" and then you see first 5 and ten sec later 32.
The fraction is therefore 5/32 (numerator=5 and denominator=32). 32 remains in X (display) after the program
finished and 5 remains in Y (type key "x><y" to see it).

Note that this program shows the resulting fraction always with positive numbers. That is: both 0.15625 and -0.15625 will result in 5/32. An extra step could be
added to add the sign at the end but that would make the program longer and it's not really needed.
### Algorithm

0.15625 -> 1/0.15625 = **6.4**
take off the integer part: 6.4 - 6=0.4
0.4 -> 1/0.4 = **2.5**
take off the integer part: 2.5 -2 =0.5
0.5 -> 1/0.5 = **2**
take off the integer part: 2-2=0
0 -> end of program
denominator = 6.4 * 2.5 * 2 = **32**
numerator = 0.15625 * denominator = 0.15625 * 32 = **5**

© Guido Socher