(41) Jet fuel Density calculator
|
06-25-2022, 03:47 AM
Post: #2
|
|||
|
|||
RE: (41) Jet fuel Density calculator
(02-23-2022 05:38 AM)WrongWay Wrote: … the code I'm sure could easily be optimized and constructive feedback is always welcome. if-else Statements In general an if-else statement like this: Code: if predicate: … can be translated into: Code: predicate? This uses only two labels instead of three: Code: 33 FS? 00 Since we use only forward jumps, both labels can be reused in other occurrences as well: Code: 52 FS?C 00 This also avoids using the expensive global labels "K" and "L". Polynomial Evaluation A quadratic polynomial can be rewritten using Horner's method: \( \begin{align} ax^2 + bx + c = (ax + b)x + c \end{align} \) This avoids calculating powers of \(x\). If we first fill the stack with \(x\) it will be copied from register T down the stack with each operation. Since the coefficients are not used elsewhere we don't have to store them in registers: Code: 12 ENTER Saving Results I decided not to save the density in a register but leave the result on the stack for further computations: Code: 43 "FPL FUEL?" Of course the user might mess with the stack which may lead to wrong results. This leaves us with the following program for the HP-42S: Code: 00 { 191-Byte Prgm } It should also work with the HP-41C after the obvious transformations. We end up with a program with 20 fewer lines, using 191 bytes instead of 230, and using no registers. |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(41) Jet fuel Density calculator - WrongWay - 02-23-2022, 05:38 AM
RE: (41) Jet fuel Density calculator - Thomas Klemm - 06-25-2022 03:47 AM
RE: (41) Jet fuel Density calculator - WrongWay - 05-12-2024, 09:36 PM
|
User(s) browsing this thread: 1 Guest(s)