RPN coding diversion post 11tybn Re: Color calculators Message #24 Posted by bhtooefr on 2 May 2013, 11:19 a.m., in response to message #23 by bhtooefr
Figured out a listing that should work on a MK-61 (I don't have my MK-61 with me right now, though, just my DM-15CC), and keeps the aspect ratio. This will be atrociously slow because I kept it entirely to the stack (I'm of the opinion that register use is to be avoided if at all possible, because the user may have meaningful data in registers), meaning there's an extra subtraction and an extra square root (because I needed to have the aspect ratio squared + 1, and I couldn't keep a spare copy of the aspect ratio around and have enough room in the 4-level stack).
It might be faster to use the height, rather than the width, to calculate the actual PPI (eliminates a multiplication), but it'll require more stack gymnastics, making the program longer, and stack gymnastics seem to be VERY SLOW on the MK-61.
The listing is in FOCAL format, but only does things that can be replicated on an MK-61 (except for the R^, but that's easy to fake).
01 LBL"PPI (replace with ENTER^ on an MK-61)
02 0
03 +
04 RDN
05 /
06 x^2
07 1
08 +
09 ENTER^
10 R^ (replace with 3x RDN on an MK-61)
11 x^2
12 x<>y
13 /
14 SQRT
15 x<>y
16 1
17 -
18 SQRT
19 ENTER^
20 RDN
21 *
22 /
23 RTN
Pretty ugly, but it doesn't touch registers at all. (My rule of thumb on an RPN machine is, the user may have valuable information in a register, so don't touch them if at all possible. My rule of thumb on an RPL machine is, the user may have valuable information on the stack, so restrict stack manipulation to the arguments and intermediate calculations (and don't pollute the stack with useless intermediate calculations, either), and the user DOES have valuable information in global variables, so never touch them (yes, I know, there's legitimate uses for them, but what I'm doing doesn't need to save data between program runs), use local variables instead (but, on an RPL machine, you can use the stack, too, my mind just works better with pulling the arguments in as local variables, and operating on them that way).)
|