[41,42] Perfect functions - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP-41C Software Library (/forum-11.html) +--- Thread: [41,42] Perfect functions (/thread-14988.html) |
[41,42] Perfect functions - Werner - 05-13-2020 01:07 PM 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 RE: [41,42] Perfect functions - rprosperi - 05-13-2020 03:32 PM 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! RE: [41,42] Perfect functions - Werner - 05-13-2020 04:32 PM While short and concise, it is not a perfect function, Bob! Werner RE: [41,42] Perfect functions - rprosperi - 05-13-2020 10:31 PM 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. RE: [41,42] Perfect functions - Sylvain Cote - 05-13-2020 11:02 PM (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" RE: [41,42] Perfect functions - rprosperi - 05-13-2020 11:49 PM Close, but no cigar... This saves X into L, but you've lost the original Z. RE: [41,42] Perfect functions - Sylvain Cote - 05-14-2020 05:30 AM (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 RE: [41,42] Perfect functions - Werner - 05-14-2020 06:20 AM 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 RE: [41,42] Perfect functions - rprosperi - 05-14-2020 12:36 PM (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! |