HP Forums
Returning multiple numbers onto the stack - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Returning multiple numbers onto the stack (/thread-2362.html)



Returning multiple numbers onto the stack - Jm9301 - 10-30-2014 02:42 PM

I have what I am sure may seem like a rather simple question to most of you I am sure.

I am a surveyor, and am working on several different ways of calculating points with my prime. I love the calculator, and it is quite the discussion piece amongst surveyors to say the least.

An example of my problem is outlined here:

EXPORT Traverse (n, e, ang, dist)

BEGIN
LOCAL a,b;

a:= cos(ang)*dist;

b:= sin(and)*dist;

return (n+a,e+b);

END;


Now this returns me Coordinates in the format (xxxxxx.xxx , yyyyyy.yyy) Which is ok, but i would like to have them as separate numbers on the stack for traversing forward. I have tried using multiple Return statements, tried all kinds of things but i cannot seem to get it down. please help!


RE: Returning multiple numbers onto the stack - Tim Wessman - 10-30-2014 03:06 PM

Unfortunately, returning multiple items and working directly on the stack is not supported yet in this release. Possible options include putting the results into complex numbers (that you are doing) which allows two 12 digit values linked together. You could also return a list or a vector with 2 items. There is just not any way at the moment to return more then a single result.


RE: Returning multiple numbers onto the stack - Jm9301 - 10-30-2014 06:05 PM

Thats what i was afraid of. Thanks for the help!


RE: Returning multiple numbers onto the stack - jayhawk - 11-10-2014 03:37 PM

(10-30-2014 02:42 PM)Jm9301 Wrote:  I have what I am sure may seem like a rather simple question to most of you I am sure.

I am a surveyor, and am working on several different ways of calculating points with my prime. I love the calculator, and it is quite the discussion piece amongst surveyors to say the least.

An example of my problem is outlined here:

EXPORT Traverse (n, e, ang, dist)

BEGIN
LOCAL a,b;

a:= cos(ang)*dist;

b:= sin(and)*dist;

return (n+a,e+b);

END;


Now this returns me Coordinates in the format (xxxxxx.xxx , yyyyyy.yyy) Which is ok, but i would like to have them as separate numbers on the stack for traversing forward. I have tried using multiple Return statements, tried all kinds of things but i cannot seem to get it down. please help!

Until HP updates the firmware of the Prime to give access to he stack, this might be helpful:
You want to pass N, E, Ang and Dist to Your program for calculating a new N and E.
And You want to only have to enter a new Ang and Dist to Traversing.

Try this:

Code:

EXPORT Traverse(ne,ang,dist)
BEGIN
  LOCAL n,e;

  n:=ne(1)+cos(ang)*dist;
  e:=ne(2)+sin(ang)*dist;
  return {n,e};
END;

Hope this helps
[edit]
NB! Be sure to be in RPN mode, so your program takes its arguments from the stack.
Also read Han's post below on handling lists and how to enter lists from keyboard.
An example running the program:
First run:
n=0
e=0
ang=45
dist=100

enter this
{0,0} <enter>
45 <enter>
100 <enter>
Traverse <enter> (You can define a user key for this)

now {new n, new e} wil be on stack level 1, so to traverse just enter:
next ang <enter>
next dist <enter>
Traverse <enter>

and so on...


RE: Returning multiple numbers onto the stack - Han - 11-10-2014 04:23 PM

In case it isn't already clear, you can access each individual element of the returned list via its index. For example, if L1:={10,20,30,40} then L1(1) would give you access to the value 10, and L1(3) would give you access to the value 30. I am of the opinion that this would actually be much easier to work with than dealing with the value's position in the stack.