The Museum of HP Calculators

HP Forum Archive 20

[ Return to Index | Top of Index ]

34s work-around for 41c quirk
Message #1 Posted by gene wright on 12 Aug 2011, 5:53 p.m.

The HP 41 SIGN command returns +1 for a value of 0.

The 34s returns 0 for a value of 0.

So, what's an efficient way to code around this difference?

Could be:

X=0? 
SKIP 01 
SIGN

What do you think?

      
Re: 34s work-around for 41c quirk
Message #2 Posted by fhub on 12 Aug 2011, 6:14 p.m.,
in response to message #1 by gene wright

Quote:
The HP 41 SIGN command returns +1 for a value of 0.

The 34s returns 0 for a value of 0.

So, what's an efficient way to code around this difference?

Could be:

X=0? 
SKIP 01 
SIGN

What do you think?


No, that won't work: it gives 0 if x=0 (because it just skips the SIGN in this case).

If you replace SKIP 01 by 10^x (or e^x) it would work as you want!

Franz

PS: Dieter's solution INC X is indeed better (because faster) than my 10^x - I'm just not used to this INC X because none of my other calculators has it.

Edited: 12 Aug 2011, 6:31 p.m.

      
Re: 34s work-around for 41c quirk
Message #3 Posted by Dieter on 12 Aug 2011, 6:14 p.m.,
in response to message #1 by gene wright

Quote:
The HP 41 SIGN command returns +1 for a value of 0.
Yes. And that makes sense. The idea behind this is the ability of the HP41 to check for alpha data:
HP-41 series:
SIGN returns
   +1  for x>=0  (i.e. also for x=0)
   -1  for x<0
    0  if x contains alpha data
If you want a plain "mathematical" sign-function on the '41, simply use
   X<>0?
   SIGN
which requires just a single byte more.

So, returning 1 even for x=0 was and is okay on the HP-41 series since it has an additional benefit. But why should one duplicate this feature on another, different calculator whithout this special background that is the reason for this ..."special" behaviour? Do we really need a SIGN41 function on the 34s ?-)

BTW, as far as I see the code you proposed will not change anything, If x is zero the sign command is skipped and x remains zero (not one). If you really want to duplicate the HP-41 way, this could be done with

   X=0?
   INC X
   SIGN
But, as already mentioned, I don't think this makes sense on the 34s.

Dieter

            
Re: 34s work-around for 41c quirk
Message #4 Posted by M. Joury on 12 Aug 2011, 6:26 p.m.,
in response to message #3 by Dieter

My initial thought was that it should work. But you are right, it doesn't. Your solution does however.

I guess if you were converting an HP-41 program this might be useful.

            
Re: 34s work-around for 41c quirk
Message #5 Posted by Paul Dale on 12 Aug 2011, 6:36 p.m.,
in response to message #3 by Dieter

Dieter is correct and suggested the same workaround I thought of when I saw the question :-) The only difference with the workaround is Last X is set incorrectly when X is zero.

We've a total inability to distinguish alpha data from numbers unlike the 41 series. I think I could work around this with reals either by reducing the number of digits by one or reserving lots of NaN values as alpha data. This is pointless since we also support integers for which there is no space available to distinguish.

This is something that will definitely be addressed in the 34S successor. I'd still differ from the 41 series though. SIGN would still return -1, 0, +1 for negative, zero and positive numbers. We've got NaN for the string case :-)

- Pauli

                  
Agreed, but I need a 41 SIGN equivalent
Message #6 Posted by gene wright on 12 Aug 2011, 6:40 p.m.,
in response to message #5 by Paul Dale

I am converting some HP 41 programs that store a -1 or 1 depending on the value in X.

Don't think LastX will be a problem, so I think Dieter's approach will work.

I am not advocating for a SIGN41 function. :-) and I like the SIGN function on the 34s, just wanting to make sure I had not overlooked something...

Edited: 12 Aug 2011, 6:51 p.m.

                        
Re: Agreed, but I need a 41 SIGN equivalent
Message #7 Posted by Paul Dale on 12 Aug 2011, 7:07 p.m.,
in response to message #6 by gene wright

Quote:
I am not advocating for a SIGN41 function. :-) and I like the SIGN function on the 34s, just wanting to make sure I had not overlooked something...

Don't worry there is no chance of a SIGN41 function :-)

There is a better solution that does Last X correctly too:

    SIGN
    X=0?
    INC X

Put this into a S41 subroutine if you are keen.

- Pauli


[ Return to Index | Top of Index ]

Go back to the main exhibit hall