Post Reply 
Comparisons with zero on HP-65
08-28-2017, 09:30 PM (This post was last modified: 08-29-2017 12:16 AM by Matt Agajanian.)
Post: #1
Comparisons with zero on HP-65
Hi all.

The HP-65's looping and branching were (and still are) quite functional and powerful. Although only comparisons between X and Y were available, outside of putting zero on the stack, what are some other ways to accomplish comparisons between X and zero? What are some ways to achieve X and 0 comparisons which streamline program steps?

Thanks
Find all posts by this user
Quote this message in a reply
08-29-2017, 10:01 PM
Post: #2
RE: Comparisons with zero on HP-65
(08-28-2017 09:30 PM)Matt Agajanian Wrote:  What are some ways to achieve X and 0 comparisons which streamline program steps?

"Some ways"? I wonder if there is even one single way to compare X with 0 without placing a zero in X or Y.

The HP65 does not have tests that compare X with 0. So any method to do so has to use at least two steps. This means that "0 X=Y?" (resp. other tests) is as short as it gets. More streamlining simply is not possible.

But I'll be glad if you prove me wrong. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
08-29-2017, 10:14 PM (This post was last modified: 08-29-2017 10:15 PM by Matt Agajanian.)
Post: #3
RE: Comparisons with zero on HP-65
(08-29-2017 10:01 PM)Dieter Wrote:  
(08-28-2017 09:30 PM)Matt Agajanian Wrote:  What are some ways to achieve X and 0 comparisons which streamline program steps?

"Some ways"? I wonder if there is even one single way to compare X with 0 without placing a zero in X or Y.

The HP65 does not have tests that compare X with 0. So any method to do so has to use at least two steps. This means that "0 X=Y?" (resp. other tests) is as short as it gets. More streamlining simply is not possible.

But I'll be glad if you prove me wrong. ;-)

Dieter

Nope! But, I just thought I'd ask and see if our group had clever shortcuts to allow X to stay in the X register instead of being pushed into Y. But yes, that's about the shortest shortcut there is.

Thanks
Find all posts by this user
Quote this message in a reply
08-29-2017, 10:20 PM (This post was last modified: 08-29-2017 10:22 PM by Dieter.)
Post: #4
RE: Comparisons with zero on HP-65
(08-29-2017 10:14 PM)Matt Agajanian Wrote:  Nope! But, I just thought I'd ask and see if our group had clever shortcuts to allow X to stay in the X register instead of being pushed into Y.

X doesn't have to get pushed to Y. You can always add another step and add an X<>Y.
Or you simply place the zero before the value which is compared to 0 is calculated:

Instead of...
Code:
RCL 1
RCL 2
x
RCL 3
RCL 4
x
+
0
X<>Y    ; optional
X=Y?
...

...simply do it this way:
Code:
0
RCL 1
RCL 2
x
RCL 3
RCL 4
x
+
X=Y?
...

Dieter
Find all posts by this user
Quote this message in a reply
08-29-2017, 10:32 PM
Post: #5
RE: Comparisons with zero on HP-65
How about:

Code:
e^x
STO 8
CLx
LSTx
DSZ
GTO
<false>
<true>

Works for small values of x (-227 <= x <= 222).

Ceci n'est pas une signature.
Find all posts by this user
Quote this message in a reply
08-29-2017, 11:08 PM
Post: #6
RE: Comparisons with zero on HP-65
(08-29-2017 10:32 PM)Mark Hardman Wrote:  How about:

Code:
e^x
STO 8
CLx
LSTx
DSZ
GTO
<false>
<true>

Works for small values of x (-227 <= x <= 222).

Clever and innovative!
Find all posts by this user
Quote this message in a reply
08-30-2017, 06:43 PM (This post was last modified: 08-30-2017 06:55 PM by Dieter.)
Post: #7
RE: Comparisons with zero on HP-65
(08-29-2017 10:32 PM)Mark Hardman Wrote:  How about:

Code:
e^x
STO 8
CLx
LSTx
DSZ
GTO
<false>
<true>

Works for small values of x (-227 <= x <= 222).

Let me see if I understand this.

For x > ln 2 the e^x command returns a value > 2. So DSZ decrements this to a value >1 and the next step is not skipped.

For 0 < x < ln 2 the e^x command returns a value between 1 and less than 2. So DSZ decrements this to something between 0 and 0,999... and the next step is skipped.

For x < 0 the e^x command returns a value between 0 and less than 1. So DSZ decrements this to something between -1 and 0. I assume that this causes the next step to be skipped.

Somewhere between x=–23 and x=–24 the e^x result is so close to 0 that DSZ decrements this to a plain –1. I don't know how if the HP65 then skipped the next step or not, but I can say that the HP67 does not (!).

But this way the threshold for skip/no-skip is not 0, but ln 2 = 0,6931...
And maybe there is a second threshold somewhere below –20 (not sure).

Did I miss something here?

Dieter
Find all posts by this user
Quote this message in a reply
08-30-2017, 09:08 PM
Post: #8
RE: Comparisons with zero on HP-65
(08-30-2017 06:43 PM)Dieter Wrote:  Let me see if I understand this.

For x > ln 2 the e^x command returns a value > 2. So DSZ decrements this to a value >1 and the next step is not skipped.

For 0 < x < ln 2 the e^x command returns a value between 1 and less than 2. So DSZ decrements this to something between 0 and 0,999... and the next step is skipped.

For x < 0 the e^x command returns a value between 0 and less than 1. So DSZ decrements this to something between -1 and 0. I assume that this causes the next step to be skipped.

Somewhere between x=–23 and x=–24 the e^x result is so close to 0 that DSZ decrements this to a plain –1. I don't know how if the HP65 then skipped the next step or not, but I can say that the HP67 does not (!).

But this way the threshold for skip/no-skip is not 0, but ln 2 = 0,6931...
And maybe there is a second threshold somewhere below –20 (not sure).

Did I miss something here?

Dieter

DSZ only skips 2 steps if the value in R8 is exactly zero after being decremented by 1. After posting I realized that there are underflow conditions that will result in e^x returning a value of exactly 1. Results of e^x where -1e-11 <= x <= 1e-10 will also return exactly 1.

I concede that it is not the best solution, but it might have some value in limited cases.

Mark Hardman

Ceci n'est pas une signature.
Find all posts by this user
Quote this message in a reply
08-31-2017, 07:49 AM (This post was last modified: 08-31-2017 07:55 AM by Dieter.)
Post: #9
RE: Comparisons with zero on HP-65
(08-30-2017 09:08 PM)Mark Hardman Wrote:  DSZ only skips 2 steps if the value in R8 is exactly zero after being decremented by 1.

OK, that's something I did not know. The HP67 skips one step if INT(RI) is zero.
So your method is a X≠0? test. It turns a zero into 1 which is then decremented to zero again and DSZ skips.

Or maybe it's more like a X~=0? test:

(08-30-2017 09:08 PM)Mark Hardman Wrote:  After posting I realized that there are underflow conditions that will result in e^x returning a value of exactly 1. Results of e^x where -1e-11 <= x <= 1e-10 will also return exactly 1.

So the method tests whether e^x rounds to 1 or not.

Dieter
Find all posts by this user
Quote this message in a reply
08-31-2017, 09:34 AM
Post: #10
RE: Comparisons with zero on HP-65
The 34S's DSZ behaves the same as the 67, I didn't realise the 65 was different.


Pauli
Find all posts by this user
Quote this message in a reply
08-31-2017, 11:30 AM (This post was last modified: 08-31-2017 12:07 PM by Dieter.)
Post: #11
RE: Comparisons with zero on HP-65
(08-31-2017 09:34 AM)Paul Dale Wrote:  The 34S's DSZ behaves the same as the 67,

That's fine by me. ;-)
This seems to be one of the improvements of the HP67 compared to its predecessor.

(08-31-2017 09:34 AM)Paul Dale Wrote:  I didn't realise the 65 was different.

Me neither. But good to know.
Now I think I wll have to try the Panamatic HP65 emulator.

Edit: The mentioned emulator should run the original microcode and thus behave like the real thing. According to my results the interval around zero where e^x is rounded to 1 is –6,1 E–11 < x < +5 E–10.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 




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