Post Reply 
this short program crashes my PRIME
12-18-2013, 12:06 AM
Post: #1
this short program crashes my PRIME
Code:

EXPORT ELODIFF(R)
BEGIN
LOCAL LI,I,A,B,C;
LI:={
{0,3,0.5},{4,10,0.51},{11,17,0.52},
{18,25,0.53},{26,32,0.54},{33,39,0.55},
{40,46,0.56}
};
FOR I FROM 1 TO SIZE(LI) DO
A:=LI(I,1);
B:=LI(I,2);
C:=LI(I,3);
 IF ((R≥A)  AND (R≤B)) THEN
  RETURN (C);
  KILL;
 END;
END;
RETURN 0;
END;

First time it returns right answer, e.g.:
ELODIFF(15)=.52 //this what I need
Second time I get:
ELODIFF(15)=15 //something gets wrong...
After several callings with different arguments my HP PRIME CRASHES...
Find all posts by this user
Quote this message in a reply
12-18-2013, 03:11 AM
Post: #2
RE: this short program crashes my PRIME
I think you may be confusing things by enclosing the returned variable C in parentheses. Try just RETURN C;
Find all posts by this user
Quote this message in a reply
12-18-2013, 06:14 AM
Post: #3
RE: this short program crashes my PRIME
I think the problem is with using SIZE in the FOR Loop. SIZE returns a list and not a scalar. You should assign the result of SIZE to a list first and then access the first element of that list as the upper loop limit.

Namir
Find all posts by this user
Quote this message in a reply
12-18-2013, 06:28 AM (This post was last modified: 12-18-2013 02:11 PM by Michael de Estrada.)
Post: #4
RE: this short program crashes my PRIME
(12-18-2013 06:14 AM)Namir Wrote:  I think the problem is with using SIZE in the FOR Loop. SIZE returns a list and not a scalar. You should assign the result of SIZE to a list first and then access the first element of that list as the upper loop limit.

Are you sure ? According to the Prime Help for SIZE, it accepts a list as the input and returns a scalar representing the number of element in the list, so for this program it should be 7.

I just checked it out and it does works that way, so for example SIZE({{1,2,3},{4,5,6},{7,8,9},{10}}) returns 4.
Find all posts by this user
Quote this message in a reply
12-18-2013, 07:35 AM
Post: #5
RE: this short program crashes my PRIME
Hello,

Not your fault... There is a bug in the return call in the for loop which is causing the issue...
a workaround while waiting for the fix is to copy your 'output' in a variable (C will work) and then to do a break; to exit from the for loop...
then return your C....

note, you can do:
if A<=R<=B then break; end;
this should work

Cyrille
Find all posts by this user
Quote this message in a reply
12-18-2013, 08:20 AM
Post: #6
RE: this short program crashes my PRIME
Thank you Cyrille, now it works!
Find all posts by this user
Quote this message in a reply
Post Reply 




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