Post Reply 
Returning multiple numbers onto the stack
10-30-2014, 02:42 PM
Post: #1
Returning multiple numbers onto the stack
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!
Find all posts by this user
Quote this message in a reply
10-30-2014, 03:06 PM (This post was last modified: 10-30-2014 03:09 PM by Tim Wessman.)
Post: #2
RE: Returning multiple numbers onto the stack
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.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
10-30-2014, 06:05 PM
Post: #3
RE: Returning multiple numbers onto the stack
Thats what i was afraid of. Thanks for the help!
Find all posts by this user
Quote this message in a reply
11-10-2014, 03:37 PM (This post was last modified: 11-11-2014 05:26 AM by jayhawk.)
Post: #4
RE: Returning multiple numbers onto the stack
(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...
Find all posts by this user
Quote this message in a reply
11-10-2014, 04:23 PM
Post: #5
RE: Returning multiple numbers onto the stack
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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