HP Forums
HP 15C conditional does not behave as expected - 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: HP 15C conditional does not behave as expected (/thread-16892.html)



HP 15C conditional does not behave as expected - Siegfried - 05-07-2021 09:13 AM

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'



RE: HP 15C conditional does not behave as expected - rprosperi - 05-07-2021 12:17 PM

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.


RE: HP 15C conditional does not behave as expected - Siegfried - 05-07-2021 03:56 PM

(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.


RE: HP 15C conditional does not behave as expected - Gene - 05-07-2021 04:22 PM

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



RE: HP 15C conditional does not behave as expected - Siegfried - 05-07-2021 06:45 PM

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



RE: HP 15C conditional does not behave as expected - Gene - 05-07-2021 08:03 PM

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.


RE: HP 15C conditional does not behave as expected - Siegfried - 05-07-2021 08:19 PM

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.



RE: HP 15C conditional does not behave as expected - Albert Chan - 05-07-2021 08:25 PM

(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.


RE: HP 15C conditional does not behave as expected - Gene - 05-07-2021 08:40 PM

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


RE: HP 15C conditional does not behave as expected - Siegfried - 05-07-2021 09:04 PM

(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.