HP 15C conditional does not behave as expected
05-07-2021, 09:13 AM (This post was last modified: 05-07-2021 09:17 AM by Siegfried.)
Post: #1
 Siegfried Member Posts: 138 Joined: Jan 2014
HP 15C conditional does not behave as expected
Using the below code with the following parameters:

1900 in register 3
-31.24 in register 2
8600 in x

the value in x before the conditional test X>Y? (f TEST 7) is 894.4946 and the value in y is 1.

The test should therefore test positive and the GTO .0 should be executed.
It isn't however.

Any hints what I am missing / doing wrong would be appreciated. I have verified that Y=1 using an R/S before the conditional.

P.S.: This is a correction for minimum safe heights for aircraft to account for low temperature taken from the draft of the new PANS-OPS (where a wrong formula has been published for decades). Therefore all altitude related values are in feet but temperatures are C/K.

Code:
HP 15C parameters: ISA Deviation STO 2 Temperature Source Elevation STO 3 Height to be corrected in X LBL A STO 1        'temporary store height to be corrected in 1 .0019812        'L0 STO 0        'goes to 0 288.15        'T0 STO .0        'goes to .0 CLx            clear Height correction (Hac) for initial calculation LBL .0         ENTER        'duplicate height correction 1            'add 1 + X<>Y        'move last height correction +1 to Y RCL +1        'add MDH to H_ac on stack RCL *0            'multiply by L0 RCL 3          'recall Elev RCL *0         'multiply by L0 RCL +.0        'add T0 / 1 + LN RCL 2           'Delta Tstd     CHS            '-Delta Tstd RCL /0          'divided by L0 * X>Y?               'if new correction is more than previous + 1 GTO .0        'repeat calculation with new correction value R/S            'if not, stop and show correction'
05-07-2021, 12:17 PM
Post: #2
 rprosperi Super Moderator Posts: 6,257 Joined: Dec 2013
RE: HP 15C conditional does not behave as expected
No idea if this is related but it appears there's a typo in this command:

PHP Code:
RCL +.0        'add T0

All other operations use register 0, while this one uses .0, a different register, and could be leading to an unexpected value.

--Bob Prosperi
05-07-2021, 03:56 PM
Post: #3
 Siegfried Member Posts: 138 Joined: Jan 2014
RE: HP 15C conditional does not behave as expected
(05-07-2021 12:17 PM)rprosperi Wrote:  All other operations use register 0, while this one uses .0, a different register, and could be leading to an unexpected value.

I store one of the constants into 0 and the other into .0, so this should be correct.

I tried essentially the same code on the WP-34S emulator in the meantime and it works flawlessly there.
05-07-2021, 04:22 PM (This post was last modified: 05-07-2021 07:59 PM by Gene.)
Post: #4
 Gene Moderator Posts: 1,370 Joined: Dec 2013
RE: HP 15C conditional does not behave as expected
Works fine for me as you have written it out on a 15c emulator. Don't have the physical unit with me at the moment.

Key codes to check:

Code:
42 21 11 44 1 48 0 0 1 9 8 1 2 44 0 2 8 8 48 1 5 44.0 43 35 42 21 .0 36 1 40 34 45 40 1 45 20 0 45 3 45 20 0 45 40 .0 10 1 40 43 12 45 2 16 45 10 0 20 31 43 30 7 22 .0 31
05-07-2021, 06:45 PM (This post was last modified: 05-07-2021 08:13 PM by Siegfried.)
Post: #5
 Siegfried Member Posts: 138 Joined: Jan 2014
RE: HP 15C conditional does not behave as expected
I think you got the loop label wrong which is .0 (corresponding to the GTO .0 at the end) which you have listed as
Code:
42 21 0

May I ask what your result is on program termination? I get the 894.xxx but that's wrong as the comparison should result in a few more loops and end up around 994.

I get the same result on a real HP-15C and nonpareil-15c.

I also tried this on a HP-41CX and get the same behaviour.

I have added an R/S to check the stack before the conditional test and have verified X=894.5956 and Y=1. So when Testing X>Y? the result is TRUE and either calculator should continue on the line after the conditional test (that is the GTO .0 instruction) but it stops on the R/S one line further.

(05-07-2021 04:22 PM)Gene Wrote:  Works fine for me as you have written it out on a 15c emulator. Don't have the physical unit with me at the moment.

Key codes to check:

Code:
42 21 11 44 1 48 0 0 1 9 8 1 2 44 0 2 8 8 48 1 5 44.0 43 35 42 21 0 36 1 40 34 45 40 1 45 20 0 45 3 [b]45 20 0[/b] 45 40 .0 10 1 40 43 12 45 2 16 45 10 0 20 31 43 30 7 22 .0 31
05-07-2021, 08:03 PM
Post: #6
 Gene Moderator Posts: 1,370 Joined: Dec 2013
RE: HP 15C conditional does not behave as expected
Sorry, corrected the .0 typo in the previous post.

It terminates with 894.595563 in the X register.

The Y register contains 895.4946483.

The TEST 7 instruction is working properly when the Y register contains a 1 the first time through the loop. I put a R/S before the test and checked a few loops.

The app is the iOS 15C SciCalc app.
05-07-2021, 08:19 PM
Post: #7
 Siegfried Member Posts: 138 Joined: Jan 2014
RE: HP 15C conditional does not behave as expected
Thank you, Gene!

I think my error is somewhere in the code after LBL .0 which seems to behave differently than I think it does.

It's quite some time since I last dabbled with this...

(05-07-2021 08:03 PM)Gene Wrote:  Sorry, corrected the .0 typo in the previous post.

It terminates with 894.595563 in the X register.

The Y register contains 895.4946483.

The TEST 7 instruction is working properly when the Y register contains a 1 the first time through the loop. I put a R/S before the test and checked a few loops.

The app is the iOS 15C SciCalc app.
05-07-2021, 08:25 PM
Post: #8
 Albert Chan Senior Member Posts: 2,559 Joined: Jul 2018
RE: HP 15C conditional does not behave as expected
(05-07-2021 09:13 AM)Siegfried Wrote:
Code:
LBL .0         ENTER        'duplicate height correction 1            'add 1 + ...

Does ENTER once really duplicate ?
I think ENTER is stack-lift disabled.
05-07-2021, 08:40 PM
Post: #9
 Gene Moderator Posts: 1,370 Joined: Dec 2013
RE: HP 15C conditional does not behave as expected
That's it ! Albert found it.

You need TWO ENTER statements after the LBL .0

When I run it that way, it ends with the answer of 994.65933422
05-07-2021, 09:04 PM
Post: #10
 Siegfried Member Posts: 138 Joined: Jan 2014
RE: HP 15C conditional does not behave as expected
(05-07-2021 08:40 PM)Gene Wrote:  That's it ! Albert found it.

You need TWO ENTER statements after the LBL .0

When I run it that way, it ends with the answer of 994.65933422
Thank you very much!

I just returned here to report that I had found the missing ENTER just to find my conclusion confirmed before I had reached it.

I had forgotten about the stack lift inhibit. Now I need to give that WP-34s program another look to find out why it worked there.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)