Detect number entry on HP-35s?
02-25-2015, 03:37 AM
Post: #1
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
Detect number entry on HP-35s?
The HP-35s does not have a Flag for number entry similar to the HP-41 Flag 22. Any ideas for a programmed workaround? For instance, I thought about using 'CLx' before input and then check x=0? but that would not allow zero entries.
02-25-2015, 10:23 AM
Post: #2
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 03:37 AM)mbrethen Wrote:  The HP-35s does not have a Flag for number entry similar to the HP-41 Flag 22. Any ideas for a programmed workaround? For instance, I thought about using 'CLx' before input and then check x=0? but that would not allow zero entries.
Your request is unclear to me. What else but number entry would you expect ?
Can you give a sample code of what you're trying to do ?
02-25-2015, 12:52 PM
Post: #3
 Thomas Radtke Senior Member Posts: 778 Joined: Dec 2013
RE: Detect number entry on HP-35s?
If you're about allowing the user to skip inputs, then you're on the wrong track. Choosing one of many variables can be done with indirect addressing, if that's all you want to accomplish. The operator would then have to state the variable number (you could add any offset if necessary) in I or J, and your program would INPUT(I) or INPUT(J).

hth
02-25-2015, 01:28 PM
Post: #4
 toml_12953 Senior Member Posts: 1,795 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 10:23 AM)Tugdual Wrote:
(02-25-2015 03:37 AM)mbrethen Wrote:  The HP-35s does not have a Flag for number entry similar to the HP-41 Flag 22. Any ideas for a programmed workaround? For instance, I thought about using 'CLx' before input and then check x=0? but that would not allow zero entries.
Your request is unclear to me. What else but number entry would you expect ?
Can you give a sample code of what you're trying to do ?

He wants to detect if numbers are typed or if letters are typed. On the 41, Flag 22 is set (and 23 is reset) when the user types a number in response to an input statement. Flag 23 is set (and 22 is reset) if the user types a letter instead.

Tom L

Tom L
Cui bono?
02-25-2015, 01:45 PM (This post was last modified: 02-25-2015 01:57 PM by mbrethen.)
Post: #5
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
RE: Detect number entry on HP-35s?
The idea is to fill a number of unnamed indirect variables and then branch off (terminate loop) when the user does not enter a value, similar to using FC?C 22 on the 41c.

Here is the beginning of my code:
Code:
W001  SF 0 W002  STO I W003  1.001 W004  STOx I W005  ENTER W006  FP W007  1E3 W008  x W009  ENTER W010  CLx W011  [INTG(LASTx),REGY] W012  PSE W013  R^ W014  R^ W015  INPUT A W016  (TEST ENTRY) W017  GTO WYYY W018  STO (I) (CODE) WXXX  GTO W005 (CODE) WYYY

The user inputs the starting register before executing. I could require the user to also input the total entries, but it would be nice if the program could figure that out ;-)
02-25-2015, 02:15 PM (This post was last modified: 02-25-2015 02:30 PM by Dieter.)
Post: #6
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 01:45 PM)mbrethen Wrote:  The idea is to fill a number of unnamed indirect variables and then branch off (terminate loop) when the user does not enter a value, similar to using FC?C 22 on the 41c.

The flag 22 method (or flag 3 on the 67/97) does not always work – for instance it cannot detect if the user recalls a value from a register instead of typing it directly, nor will it handle an input as simple as pressing the pi key.

(02-25-2015 01:45 PM)mbrethen Wrote:  Here is the beginning of my code:

I assume this is not the code you are actually working with. For instance there is no LBL W in line 001 (which is required for branching to line numbers) and I also wonder what line 005...011 will do. At line 005 the value in X always is 1.001, so the following three lines will always evaluate to 1000 and the display is [1000, 1]. Is this how the program is supposed to work? What is this [1000, 1] supposed to mean? Due to the "1E3 x" in line 007-008, LastX always is 1000, and so is the first value displayed within the square brackets.

If this is not the intended behaviour, please give an example of a value entered by the user on program start, and what you want the program to display in the first, second, third, ... loop. Finally, what's the use of SF 0 at the beginning?

BTW, if you want to use the indirect variables (with positive index), you have to make sure that a sufficient number of registers is allocated. This is usually done by storing a non-zero (!) value in the highest-numbered register beforehand. If the values are stored in consecutive registers and ascending order, simply storing the entered values will do. But this also means that no zero values can be entered! If you want to allow zero entries, the maximum number of registers has to be known on program start, and a non-zero value has to be stored in that register to make sure it exists (i.e. memory is allocated).

Dieter
02-25-2015, 02:16 PM
Post: #7
 Thomas Radtke Senior Member Posts: 778 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 01:45 PM)mbrethen Wrote:  The idea is to fill a number of unnamed indirect variables and then branch off (terminate loop) when the user does not enter a value, similar to using FC?C 22 on the 41c.
If only reals are allowed, the user could enter i to indicate the end of the list.
02-25-2015, 02:49 PM
Post: #8
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 02:15 PM)Dieter Wrote:  I assume this is not the code you are actually working with. For instance there is no LBL W in line 001 (which is required for branching to line numbers) and I also wonder what line 005...011 will do. At line 005 the value in X always is 1.001, so the following three lines will always evaluate to 1000 and the display is [1000, 1]. Is this how the program is supposed to work? What is this [1000, 1] supposed to mean? Due to the "1E3 x" in line 007-008, LastX always is 1000, and so is the first value displayed within the square brackets.

The code was thrown together last night and isn't complete (nor debugged).

Quote:If this is not the intended behaviour, please give an example of a value entered by the user on program start, and what you want the program to display in the first, second, third, ... loop. Finally, what's the use of SF 0 at the beginning?

Dieter

Here was the thought process:
1. User enters the starting register number on the stack
2. Execute Program W
3. Flash array [column,row] (using two stack registers as counters)
4. Input value in variable A
5. Store in (I), beginning with starting register.
6. Increment counters and indirect register number
7. Go to step 3 until first column is filled
8. Start next column (Flag 0)
9. Exit program
02-25-2015, 07:12 PM (This post was last modified: 02-26-2015 12:36 PM by Dieter.)
Post: #9
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 02:49 PM)mbrethen Wrote:  Here was the thought process:
1. User enters the starting register number on the stack
2. Execute Program W
3. Flash array [column,row] (using two stack registers as counters)
4. Input value in variable A
5. Store in (I), beginning with starting register.
6. Increment counters and indirect register number
7. Go to step 3 until first column is filled
8. Start next column (Flag 0)
9. Exit program

So you want to enter a matrix. How does the program know its dimensions (#columns, #lines), resp. when is a line in step 7 considered "filled"? Do you want to enter line by line or column by column?

Or do you assume one line is complete as soon as no entry occurs? How do you then handle lines with different dimensions (# of columns)? If the first line had 3 values and the second one 5, how do you plan to access the, say, 4th element of the 2nd line?

While this is not what you're looking for, the following example shows my approach on entering a n x n matrix:

Code:
N001 LBL N N002 INPUT N N003 ABS N004 IP N005 STO N N006 1E3 N007 / N008 ENTER N009 SIGN N010 STO I   // address pointer := 1 N011 + N012 STO D   // save 1.nnn in D for later use N013 STO B   // store 1.nnn in B (line counter) N014 RCL N N015 RCLx N N016 RCL+ I  // first address beyond last used register = n*n + 1 N017 STO J   // the "+1" is needed because the last value may be zero N018 STO (J) // store some non-zero value there to allocate memory N019 RCL D <-------------+   // recall 1.nnn N020 STO C               |   // store in C (column counter)                          | N021 [IP(B), IP(C)] <-+  | N022 STO A            |  | N023 ALL              |  | N024 INPUT A          |  |  // display A? [line, column] N025 STO(I)           |  | N026 ISG I            |  |  // increment index (address) N027 ENTER            |  | N028 ISG C            |  |  // increment column# N029 GTO N021 --------+  |  // next column                          | N030 ISG B               |  // increment line# N031 GTO N019 -----------+  // next line N032 VIEW N N033 RTN

While the program waits for input, it displays a vector like [1, 1] with line# and column# in X. Now, getting back to your request, if the user does not enter anything the entry will be a vector. If you now could check whether X holds a simple real (=entry) or a vector (=no entry), your problem was solved.

Dieter
02-25-2015, 07:27 PM (This post was last modified: 02-25-2015 07:36 PM by Dieter.)
Post: #10
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 02:16 PM)Thomas Radtke Wrote:  If only reals are allowed, the user could enter i to indicate the end of the list.

This sounded like a good idea to me – until I tried it. The 35s does not allow comparing complex numbers (or complex with reals, for that matter). It will throw an INVALID DATA error. Sadly the 35s does not have a kind of TYPE command that returns the data type in X. This would allow both your suggestion as well as the solution I suggested in my previous post.

Dieter
02-25-2015, 07:42 PM
Post: #11
 Thomas Radtke Senior Member Posts: 778 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 07:27 PM)Dieter Wrote:  This sounded like a good idea to me – until I tried it. The 35s does not allow comparing complex numbers (or complex with reals, for that matter).
If he just square it and compare the result against -1?
02-25-2015, 08:00 PM (This post was last modified: 02-25-2015 08:40 PM by Dieter.)
Post: #12
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 07:27 PM)Dieter Wrote:  This sounded like a good idea to me – until I tried it. The 35s does not allow comparing complex numbers (or complex with reals, for that matter).
If he just square it and compare the result against -1?

The 35s supports a genuine complex data type. The result of an operation on a complex number always is complex again. So while i is 0 + 1i, i² equals –1 + 0i, which still is a complex number even if the imaginary part is zero. But there may be a workaround:

Code:
INPUT A ENTER ENTER      // save input 0i0        // add 0 + 0i +          // to turn it into a complex number ENTER x          // square it ARG        // arg(x²) is zero for positive reals x≠0?       // x² not a positive real? GTO (exit) // then exit loop R↓         // restore input STO(I)     // and process it

This should work.

The only significant limitation is the input range which is limited to values less than 10250.
This could be avoided by testing if abs(cos(arg(x+0i0)))=1. ;-)

Code:
INPUT A ENTER ENTER      // save input 0i0        // add 0 + 0i +          // to turn it into a complex number ARG        // arg(x) = 0 for positive reals resp. pi/180° for negative reals COS        // the cosine of this is 1 resp. –1 ABS        // which means that the absolute value is 1 ACOS       // arccos of 1 is zero (one step less than a test against 1) x≠0?       // was it not a real? GTO (exit) // then exit loop R↓         // restore input STO(I)     // and process it

Dieter
02-25-2015, 08:24 PM
Post: #13
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 07:12 PM)Dieter Wrote:  So you want to enter a matrix. How does the program know its dimensions (#columns, #lines), resp. when is a line in step 7 considered "filled"? Do you want to enter line by line or column by column?

column by column

Quote:Or do you assume one line is complete as soon as no entry occurs?

yes, then save the number of rows into a variable.

Quote:How do you then handle lines with different dimensions (# of columns)? If the first line had 3 values and the second one 5, how do you plan to access the, say, 4th element of the 2nd line?

It would continue filling columns, cycling through row variable. The array is complete when the user doesn't make an entry.

Quote:While the program waits for input, it displays a vector like [1, 1] with line# and column# in X. Now, getting back to your request, if the user does not enter anything the entry will be a vector. If you now could check whether X holds a simple real (=entry) or a vector (=no entry), your problem was solved.

Dieter

That might actually work. Thanks!
02-25-2015, 10:39 PM (This post was last modified: 02-25-2015 10:51 PM by mbrethen.)
Post: #14
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 02:15 PM)Dieter Wrote:  At line 005 the value in X always is 1.001, so the following three lines will always evaluate to 1000 and the display is [1000, 1]. Is this how the program is supposed to work?

Dieter
Ah, I recognize my mistake, The X should be STOx REGY but I couldn't figure out how to do this, or if it is possible on a 35s.
02-26-2015, 05:03 AM
Post: #15
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
RE: Detect number entry on HP-35s?
I checked the manual and whether the user enters a number or not, the current contents of the variable is placed in the x-register. Testing the vector isn't a viable method.
02-26-2015, 06:15 AM
Post: #16
 Thomas Radtke Senior Member Posts: 778 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 08:00 PM)Dieter Wrote:  The result of an operation on a complex number always is complex again.
I see, forgot that :-(.
02-26-2015, 06:31 AM
Post: #17
 d b Senior Member Posts: 489 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-25-2015 08:00 PM)Dieter Wrote:  The result of an operation on a complex number always is complex again.
I'm going to think about that. There's a life lesson there somewhere. Thanks Dieter.
02-26-2015, 12:33 PM (This post was last modified: 02-26-2015 12:38 PM by Dieter.)
Post: #18
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-26-2015 05:03 AM)mbrethen Wrote:  I checked the manual and whether the user enters a number or not, the current contents of the variable is placed in the x-register.

Sure – that's how the method works! In my sample code the variable (here A) initially holds the vector [row, column] which is displayed as the user is prompted for input. If nothing is entered, there still is this vector stored in A.

(02-26-2015 05:03 AM)mbrethen Wrote:  Testing the vector isn't a viable method.

The method is fine. I just do not (yet) know of a way to implement it on a 35s. ;-)

Dieter
02-26-2015, 12:35 PM
Post: #19
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-26-2015 06:31 AM)Den Belillo (Martinez Ca.) Wrote:
(02-25-2015 08:00 PM)Dieter Wrote:  The result of an operation on a complex number always is complex again.
I'm going to think about that.

Well, the result of an operation on a complex number is a complex number again on the 35s, that is. ;-)

Dieter
02-26-2015, 12:50 PM
Post: #20
 Thomas Radtke Senior Member Posts: 778 Joined: Dec 2013
RE: Detect number entry on HP-35s?
(02-26-2015 12:35 PM)Dieter Wrote:  Well, the result of an operation on a complex number is a complex number again on the 35s, that is. ;-)
It is unnecessary complex, so to say .
 « Next Oldest | Next Newest »

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