Post Reply 
NEIGHBOR function in RPL
06-05-2015, 11:35 PM (This post was last modified: 06-06-2015 09:49 AM by Didier Lachieze.)
Post: #3
RE: NEIGHBOR function in RPL
I was working on a very similar solution on the Prime, but when I tested your code on the 48GX I found that it was not working for negative X, one of the reasons being that -5 MANT returns 5 on the 48, while on the Prime MANT(-5) returns -5.

So here is my RPL solution which seems to work for positive and negative numbers:

Code:
« → X Y
  «  X MANT X SIGN * DUP DUP 1 SAME Y X < * 
    SWAP -1 SAME X Y < * + 11 + NEG ALOG
    Y X - SIGN * + X XPON ALOG *
  »
»

And the Prime code:

Code:
EXPORT NEIGHBOR(X,Y)
BEGIN
  LOCAL m,n;
  m:=MANT(X);
  n:=ALOG(−(11+(m=1)*(X>Y)+(m=−1)*(X<Y)));
  RETURN (m+n*SIGN(Y-X))*ALOG(XPON(X));
END;

EDIT: Updated to clean RPL code and remove the '\'s.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
NEIGHBOR function in RPL - Joe Horn - 06-05-2015, 09:03 PM
RE: NEIGHBOR function in RPL - Didier Lachieze - 06-05-2015 11:35 PM
RE: NEIGHBOR function in RPL - Gerald H - 06-06-2015, 09:17 AM
RE: NEIGHBOR function in RPL - Werner - 06-06-2015, 12:55 PM
RE: NEIGHBOR function in RPL - Gerald H - 06-06-2015, 03:03 PM
RE: NEIGHBOR function in RPL - Werner - 06-06-2015, 03:30 PM
RE: NEIGHBOR function in RPL - Gerald H - 06-06-2015, 03:45 PM
RE: NEIGHBOR function in RPL - Gerald H - 06-06-2015, 03:41 PM
RE: NEIGHBOR function in RPL - Gerald H - 06-06-2015, 03:50 PM



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