replace all temporary registers by '.' and ':', simplify inv macro

This commit is contained in:
Yargo iMac 2017-02-13 14:48:27 +01:00
parent 12836f1077
commit 5812333583
1 changed files with 17 additions and 17 deletions

View File

@ -17,23 +17,23 @@ fi
# macros defined as sed patterns
# (kill all '!' not part of comparison commands, and also comments)
mcrs='
s,%t,SAdLA100*SASBLALB/,g;# percent part: X:=100*X/Y, Y kept
s,%d,SAddLA-_100*SASBLALB/,g;# percent delta: X:=100*(X-Y)/Y, Y kept
s,%f,SAdlA*100LA-/,g;# percent future: X:=Y*X/(100-X), Y kept
s,%,SAdLA*100/,g;# percentage: X:=X*Y/100, Y kept
s,%t,S.dL.100*S.S:L.L:/,g;# percent part: X:=100*X/Y, Y kept
s,%d,S.ddL.-_100*S.S:L.L:/,g;# percent delta: X:=100*(X-Y)/Y, Y kept
s,%f,S.dl.*100L.-/,g;# percent future: X:=Y*X/(100-X), Y kept
s,%,S.dL.*100/,g;# percentage: X:=X*Y/100, Y kept
s,hm,r60*+,g;# hoursminutes: X:=X+Y*60
s,rem,\%,g;# remainder: X:=Y%X (instead of normal '%' command)
s,sto\(.\),s\1l\1,g;# sto.: store with copying (i.e keep value on stack)
s,fact,[SAlA*LA1-d0<B]SBSA1LAlBx0*sBLB+,g;# factorial: X:=X!
s,fact,[S.l.*L.1-d0<:]S:S.1L.l:x0*s:L:+,g;# factorial: X:=X!
s,neg,_1*,g;# negate: X:=-X
s,inv,1r/,g;# inverse: X:=1/X
s,\$m,[l4l1/l2l1/]SSl10!=SsSLS,g;# mean value: X:=reg.2/reg.1, Y:=reg.4/reg.1
s,inv,S.1L./,g;# inverse: X:=1/X
s,\$m,[l4l1/l2l1/]S.l10!=.s.L.,g;# mean value: X:=reg.2/reg.1, Y:=reg.4/reg.1
s,\$-,dL2r-s2dd*L3r-s3rdL4r-s4dd*L5r-s5*L6r-s6L11-s1,g;# remove statistic entry
s,\$+*,dL2+s2dd*L3+s3rdL4+s4dd*L5+s5*L6+s6L11+s1,g;# add statistic entry
s, , ,;# statistic registers:1=n 2=sumX 3=sumX^2 4=sumY 5=sumY^2 6=sumXY
s,[eE]\(_*[0-9][0-9]*\), 10 \1^*,g;# infix exponential: X:=X*10^N
s,drop,0*+,g;# stack drop
s,r,SRSSLRLS,g;# revert: X:=Y, Y:=X ('r' is a GNU extension)
s,r,S.S:L.L:,g;# revert: X:=Y, Y:=X ('r' is a GNU extension)
s,![ ]*[^<=>].*,,
s,#.*,,
'
@ -97,16 +97,16 @@ l0n[s0
]nl8n[s8
]nl9n[s9
]n
# clear stack, store 0 in reg.Z and macro in reg.Y, which compares stack
# clear stack, store 0 in reg.'.' and macro in reg.':', which compares stack
# depth with 1 (in case of empty stack generated by this '1') and if equal,
# prints 0 (from reg.Z), else former top of stack, and clears stack
c 0sZ [1z=Znc]sY
# apply macro in reg.Y to all saved stack values, and separate with NL
LElYx[
]nLDlYx[
]nLClYx[
]nLBlYx[
]nlAlYx[ # ]n
# prints 0 (from reg.'.'), else former top of stack, and clears stack
c 0s. [1z=.nc]s:
# apply macro in reg.':' to all saved stack values, and separate with NL
LEl:x[
]nLDl:x[
]nLCl:x[
]nLBl:x[
]nlAl:x[ # ]n
# print exponentialized version of stack top as comment:
# A=(number of digits - number of fraction digits - 1) of stack top,
# divide stack top by 10^A and print, print A