Post Reply 
[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:
  • save X in LastX
  • take the n arguments from the stack, compute the result in X
  • roll down the stack and replicate reg T n-1 times

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"
02 STO L
03 X<>Y
04 ST+ Y
05 X<>Y
06 X!=0?
07 ST/ Y
08 X<> L
09 *
10 END

For the 42S, that can be shortened to:

Code:
00 { 17-Byte Prgm }
01▸LBL "PAR"
02 RCL+ ST Y
03 X≠0?
04 STO÷ ST Y
05 X<> ST L
06 ×
07 END

2. CEIL and FLOOR
Code:
01*LBL"CEIL"
02 INT
03 X<>Y
04 X<> L
05 X>Y?
06 ISG Y
07 X<=Y?
08 GTO 00
09*LBL"FLOOR"
10 INT
11 X<>Y
12 X<> L
13 X<Y?
14 DSE Y
15*LBL 00
16 X<> L
17 X<>Y
18 END

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"%*"
02 %
03 ST+ Y
04 X<> L
05 +
06 END

4. SINC
Sinc(x) = Sin(x)/x, or 1 if x=0
Code:
01 LBL"SINC"
02 SIN
03 X<> L
04 X!=0?
05 ST/ L
06 X<> L
07 X=0?
08 SIGN
09 END

Do you have more?

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
[41,42] Perfect functions - Werner - 05-13-2020 01:07 PM
RE: [41,42] Perfect functions - rprosperi - 05-13-2020, 03:32 PM
RE: [41,42] Perfect functions - Werner - 05-13-2020, 04:32 PM
RE: [41,42] Perfect functions - rprosperi - 05-13-2020, 10:31 PM
RE: [41,42] Perfect functions - rprosperi - 05-14-2020, 12:36 PM
RE: [41,42] Perfect functions - rprosperi - 05-13-2020, 11:49 PM
RE: [41,42] Perfect functions - Werner - 05-14-2020, 06:20 AM



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