(15C) Decimal to x/16 - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (15C) Decimal to x/16 (/thread-4791.html) |
(15C) Decimal to x/16 - Dwight Sturrock - 09-24-2015 11:56 PM HP 15c x/16 Program to convert decimal fraction to a fraction readable on a tape measure: Registers: STO 0- ORIGINAL NUMBER STO 1- NUMERATOR STO 2- DENOMINATOR Code: 01 LBL A RE: HP 15C: Decimal to x/16 - Thomas Klemm - 09-25-2015 04:10 PM That's a nice program. Here's a variant that is a little shorter and uses only one register: Code: 001-42,21,11 LBL A The numerator and denominator are merged into a single number nn.dd. Thus we can divide both by 2 with a single instruction. The display settings aren't changed since the function INT(x + 0.5) is used to round a number. The stack is filled with 0.5 in lines 4-7 because this number can be used often. Personally I dislike that 16 occurs twice but I couldn't come up with a better solution. Maybe somebody else can? Kind regards Thomas RE: HP 15C: Decimal to x/16 - Dwight Sturrock - 09-26-2015 02:11 PM Elegant, Thomas, and a bit faster. I had a version for the 42S and I ported it quickly to the 15C years ago without much thought. It is a program I used on a daily basis in my work for many years. |