Problem with HEAD & TAIL Programmes on HP 33s
|
09-01-2022, 03:59 PM
(This post was last modified: 09-02-2022 10:19 AM by Gerald H.)
Post: #1
|
|||
|
|||
Problem with HEAD & TAIL Programmes on HP 33s
Previously I have used this programme
Code: 1. LBL H to return the leading digit of a natural number. Quite correctly the programme returns a false answer for large input, eg 999,999,999,999. The following programme solves that problem but is markedly slower Code: 1. LBL X Both programmes preserve the stack. Has anyone got a better solution? |
|||
09-01-2022, 04:33 PM
Post: #2
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
What if you use IP instead of FP?
This program is for the HP-42S, but I assume you get the idea: Code: 00 { 6-Byte Prgm } |
|||
09-01-2022, 05:14 PM
Post: #3
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
That doesn't work on a real HP-42S due to the rounding.
Maybe we can do it in two steps? Code: 00 { 15-Byte Prgm } Or then a little bit shorter: Code: 00 { 15-Byte Prgm } |
|||
09-01-2022, 06:33 PM
Post: #4
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
Another small improvement:
Code: 00 { 12-Byte Prgm } |
|||
09-01-2022, 06:45 PM
Post: #5
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
Thank you, Thomas, I take my hat off to you!
Your longer version is preferable on the 33s due to paucity of labels. My adaptation below preserves the stack in order to fit in with other programmes. Timings show your programme (in my adaptation) on 33s faster than my 2nd programme in 1st posting by a factor of 0.56, ie 17.41s against 31.18s. Code: 1. LBL X |
|||
09-01-2022, 07:34 PM
Post: #6
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
But then you can still replace:
Code: 5. LOG … by: Code: 5. SQRT … thus preserving the stack. Also the following command is not really needed: Code: 12. IP |
|||
09-02-2022, 02:32 AM
Post: #7
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
Very nice of you to take the time to help me & I hope others.
Yes, my version failed to preserve stack. Deletion of old line 12 (new line 11 in programme below) causes errors for largest numbers (>999999999988) & it sems a shame to save one line to lose the full range. I was a little shocked to discover my original version (1st in 1st posting) gave a wrong value for input 9. A learning experience for me. So here's latest version that preserves stack: Code: 1. LBL X |
|||
09-02-2022, 10:14 AM
(This post was last modified: 09-02-2022 10:14 AM by Gerald H.)
Post: #8
|
|||
|
|||
RE: Problem with HEAD Programme on HP 33s
I had a similar problem with the programme TAIL, which removes the initial digit of a natural number, consistently erring for very large numbers:
Code: 1. LBL T Following Thomas' suggestions in his programme, I now use the inflated programme below, which gives consistently correct answers. I write "inflated" as the programme is more than double the size of my old programme, but perhaps it's as small as can be. Code: 1. LBL T |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)