A tiny synthetic HP41 challenge - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: A tiny synthetic HP41 challenge (/thread-7390.html) |
A tiny synthetic HP41 challenge - Dieter - 12-07-2016 07:17 PM I'm not an expert if it comes to synthetic programming on the HP41, so probably someone else here may have a better idea than me for the following little challenge. The task: truncate a number after six or seven significant digits and normalize it to the domain 0 <= X < 1. Some examples: 3,141592654 => 0,314159 or 0,3141592 –1,234567809 E–32 => 0,123456 or 0,1234567 9,999999999 E+99 => 0,999999 or 0,9999999 0,123456 => 0,123456 Here's my solution: Code: CLA The append command adds three bytes (decimal 0, 9, 153 or hex 00, 09, 99) to clear the last three digits and set the exponent to –1. I am sure you can do better. So what's your idea here? Dieter RE: A tiny synthetic HP41 challenge - hth - 12-08-2016 06:25 PM I am not good at synthetics at all. Your solution looks clever, but I think it will not handle the case when X is 0 properly. I also think you can just remove the last CLA, there is no need to clean up. Håkan RE: A tiny synthetic HP41 challenge - Dieter - 12-08-2016 06:46 PM (12-08-2016 06:25 PM)hth Wrote: I am not good at synthetics at all. Your solution looks clever, but I think it will not handle the case when X is 0 properly. Thank you for your reply. Of course the code works for x=0. A look at the M-register shows what it does. Assume x=pi. Code: CLA 00 00 00 00 00 00 00 I hoped for an elegant method of shifting the value by a nybble (half a byte) so that also results with 4, 6 or 8 digits become possible. Or something more elegant than three ASTO commands. ;-) (12-08-2016 06:25 PM)hth Wrote: I also think you can just remove the last CLA, there is no need to clean up. I should have known this 40 years ago: "No, Mom, my room is OK this way. Håkan said there is no need to clean up". ;-) Dieter RE: A tiny synthetic HP41 challenge - hth - 12-08-2016 08:34 PM (12-08-2016 06:46 PM)Dieter Wrote: Thank you for your reply. Of course the code works for x=0. A look at the M-register shows what it does. Assume x=pi. If you have 0 as input and you append the 999 exponent at the end, then RCL M will put a non-normalized number in X? (12-08-2016 06:46 PM)Dieter Wrote:(12-08-2016 06:25 PM)hth Wrote: I also think you can just remove the last CLA, there is no need to clean up. LOL! Håkan RE: A tiny synthetic HP41 challenge - Dieter - 12-08-2016 09:17 PM (12-08-2016 08:34 PM)hth Wrote: If you have 0 as input and you append the 999 exponent at the end, then RCL M will put a non-normalized number in X? Ah, OK, that's of course correct. But the next operation or a STO/RCL should normalize it. You can also do it within the routine. For instance by adding zero, like it's done in "MT" of the PPC ROM: Code: CLA Still including a final CLA for cleanup. ;-) Dieter |