[41,42] Perfect functions
|
05-13-2020, 01:07 PM
(This post was last modified: 05-14-2020 06:17 AM by Werner.)
Post: #1
|
|||
|
|||
[41,42] Perfect functions
A 'perfect' function is one that mimicks the built-in functions:
Here, I present a few routines that pass these requirements. 1. Parallel Resistance: In: X Y Out: X*Y/(X+Y) Code: 01 LBL"PAR" For the 42S, that can be shortened to: Code: 00 { 17-Byte Prgm } 2. CEIL and FLOOR Code: 01*LBL"CEIL" 3. combine two percentages 1+r%/100 = (1+x%/100)*(1+y%/100) -> r%=x% +y% + x%*y%/100 In: x% y% Out: r% Code: 01*LBL"%*" 4. SINC Sinc(x) = Sin(x)/x, or 1 if x=0 Code: 01 LBL"SINC" Do you have more? Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
05-13-2020, 03:32 PM
(This post was last modified: 05-13-2020 03:33 PM by rprosperi.)
Post: #2
|
|||
|
|||
RE: [41,42] Perfect functions
Here's the first program I put into any new RPN machine I play with:
%T - Return the percent that X is of Y Code: 01 LBL "%T" Derived with Joe Horn one late Friday night at a PPC meeting, around 1982-3? Cliff Stern may have been involved too. We celebrated by going to get 'breakfast' at Denny's at around 2am when the meeting ended, a long tradition after PPC meetings at the time. Edit: Forgot to say thanks Werner, for a handy new tool for the toolbox! --Bob Prosperi |
|||
05-13-2020, 04:32 PM
Post: #3
|
|||
|
|||
RE: [41,42] Perfect functions
While short and concise, it is not a perfect function, Bob!
Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
05-13-2020, 10:31 PM
Post: #4
|
|||
|
|||
RE: [41,42] Perfect functions
Oops. LastX is broken.... And to think I've been happy with it all these years for preserving the stack. Dang. On the other hand, while nice, I never thought of it as perfect.
No simple way I can see to fix that. I'll have to live with it, imperfect as it is. Thanks. --Bob Prosperi |
|||
05-13-2020, 11:02 PM
(This post was last modified: 05-13-2020 11:10 PM by Sylvain Cote.)
Post: #5
|
|||
|
|||
RE: [41,42] Perfect functions
(05-13-2020 04:32 PM)Werner Wrote: While short and concise, it is not a perfect function, Bob!I do not know if you want to keep P2 in the stack or not, so I assume not (05-13-2020 10:31 PM)rprosperi Wrote: No simple way I can see to fix that.Not that hard either. Code: STK : L X Y Z T Formula: R = (P1 / P2) × 100% Code: 01 LBL "%T" |
|||
05-13-2020, 11:49 PM
Post: #6
|
|||
|
|||
RE: [41,42] Perfect functions
Close, but no cigar...
This saves X into L, but you've lost the original Z. --Bob Prosperi |
|||
05-14-2020, 05:30 AM
Post: #7
|
|||
|
|||
RE: [41,42] Perfect functions
(05-13-2020 11:49 PM)rprosperi Wrote: Close, but no cigar...You're tough ... 2nd version Code: STK : L X Y Z T Formula: R = (P1 / P2) × 100% Code: FOCAL___ > _L_ _X_ _Y_ _Z_ _T_ Code: STO L > 12 12 .2 z t |
|||
05-14-2020, 06:20 AM
(This post was last modified: 05-14-2020 06:54 AM by Werner.)
Post: #8
|
|||
|
|||
RE: [41,42] Perfect functions
In analogy to % and %CH, %T should also leave Y intact.
This comes close: Code: >LBL"%T" So that leaves Code: >LBL"%T" Cheers, Werner PS. Added SINC to the original post 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
05-14-2020, 12:36 PM
Post: #9
|
|||
|
|||
RE: [41,42] Perfect functions
(05-13-2020 11:02 PM)Sylvain Cote Wrote: I do not know if you want to keep P2 in the stack or not, so I assume not I missed this comment the first time, sorry. As Werner noted, keeping P2 (Y) is required to mimic the other % functions, but also because often you are still operating on the total, which is likely why HP chose to keep Y in the other % functions. I need to check out the stackrobatics in the last one, but I'll keep the short one too. Thank you both! --Bob Prosperi |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)