| 1 |
batchmode; |
| 2 |
delimiters (); |
| 3 |
def -- = {curl 1}..{curl 1} enddef; |
| 4 |
showstats; |
| 5 |
|
| 6 |
begingroup |
| 7 |
save MF, TF, MS, TS; |
| 8 |
interim warningcheck:=0; |
| 9 |
|
| 10 |
vardef MF(text p)(text q) = show p/q (4096) enddef; |
| 11 |
vardef TF(text p)(text q) = show p/4096 (q), p/4096 (-q) enddef; |
| 12 |
vardef MS(expr p, q) = show p/q, (-p)/q, p/(-q), (-p)/(-q) enddef; |
| 13 |
vardef TS(expr p, q) = show p*q, (-p)*q, p*(-q), (-p)*(-q) enddef; |
| 14 |
|
| 15 |
% Hard cases for arithmetic routines (taken from mp/mathtest.c) |
| 16 |
TF(1618.00821)(19313.86989); % p*q=(10^9+1)*2^27-6 => 7629.39453 |
| 17 |
TS(12.91296)(12.91296); % => 166.74463 |
| 18 |
MF(4793.68996)(5477.58977); % => 3584.59740 |
| 19 |
MS(12.91296)(12.91296); % => 1.00000 |
| 20 |
TF(2048.00000)(15258.78908); % p*q=(10^9+1)*2^27 => 7629.39455 |
| 21 |
TF(2644.17595)(11818.42685); % p*q=(10^9+1)*2^27+2 => 7629.39455 |
| 22 |
TF(1164.89432)(26826.46791); % p*q=(10^9+1)*2^27+2^14+2 => 7629.39455 |
| 23 |
TF(3310.94371)(9438.39665); % p*q=(10^9+1)*2^27-2^14-3 => 7629.39453 |
| 24 |
TS(13107.20000)(2.50000); % p*q=2^47-2^15 => * |
| 25 |
TS(124.77580)(262.61502); % p*q=2^47-2^15+6 => * |
| 26 |
TS(1038.61232)(31.54979); % p*q=2^47-2^15-1 => 32767.99998 |
| 27 |
TS(64.03127)(511.75000); % p*q=2^47-2^14 => * |
| 28 |
TS(39.46178)(830.37315); % p*q=2^47-2^14+1 => * |
| 29 |
TS(1207.05434)(27.14708); % p*q=2^47-2^14-1 => * |
| 30 |
TS(7.25000)(4519.72414); % p*q=2^47-3*2^14 => 32767.99998 |
| 31 |
TS(215.31056)(152.18947); % p*q=2^47-3*2^14+1 => 32767.99998 |
| 32 |
TS(14833.24916)(2.20909); % p*q=2^47-3*2^14-1 => 32767.99998 |
| 33 |
TS(339.62500)(22.46417); % p*q=(10^9+1)*2^15 => 7629.39455 |
| 34 |
TS(47.62218)(160.20676); % p*q=(10^9+1)*2^15+2 => 7629.39455 |
| 35 |
TS(74.64186)(102.21335); % p*q=(10^9+1)*2^15-2 => 7629.39453 |
| 36 |
TF(2.50000)(13107.20000); % p*q=2^47-2^15 => 8.00000 |
| 37 |
TF(47.62218)(160.20676); % p*q=(10^9+1)*2^15+2 => 1.86264 |
| 38 |
MF(7629.39455)(8192.00000); % 2^29*p+q=2q*(5*10^8+1)+0 => 3814.69728 |
| 39 |
MF(15258.78906)(24998.04695); % 2^29*p+q=2q*(163852801)-5 => 2500.19531 |
| 40 |
MF(15258.78906)(20546.77141); % 2^29*p+q=2q*(199350055)+1 => 3041.84044 |
| 41 |
MF(15258.78906)(30447.06313); % 2^29*p+q=2q*(134528575)+2^14-5 => 2052.74315 |
| 42 |
MS(15258.78908)(2.00000); % 2^17*p+q=2q*(5*10^8+1)+0 => 7629.39455 |
| 43 |
MS(15258.78906)(166.56779); % 2^17*p+q=2q*(6003562)-1 => 91.60707 |
| 44 |
MS(15258.78906)(394.96335); % 2^17*p+q=2q*(2531881)+2 => 38.63344 |
| 45 |
MS(15258.78906)(42.34901); % 2^17*p+q=2q*(23613301)-2^14-1 => 360.31036 |
| 46 |
show oct "77777", hex "400a"; |
| 47 |
endgroup; |
| 48 |
|
| 49 |
showstats; |
| 50 |
path triang, circ; |
| 51 |
triang = (-3,-2)--(7,-2)--(0,7)--cycle; |
| 52 |
circ = makepath(pencircle shifted (0,.5) scaled 10); |
| 53 |
showstats; |
| 54 |
|
| 55 |
picture pic, pic[]; |
| 56 |
showstats; |
| 57 |
begingroup |
| 58 |
save sh, dr; |
| 59 |
vardef sh expr p = |
| 60 |
show p, stroked p, filled p, textual p, clipped p, bounded p, length p; |
| 61 |
showstats; |
| 62 |
enddef; |
| 63 |
vardef dr text t = |
| 64 |
pp3:=nullpicture; |
| 65 |
addto pp3 t; |
| 66 |
sh pp3; |
| 67 |
enddef; |
| 68 |
save pp; picture pp[]; |
| 69 |
showstats; |
| 70 |
pic = pp2 = nullpicture; |
| 71 |
sh pic; |
| 72 |
clip pic to makepath(pencircle scaled 100); |
| 73 |
sh pic; % clipped |
| 74 |
setbounds pp2 to triang; |
| 75 |
sh pp2; % bounded() |
| 76 |
dr doublepath (1,1)--(3,2) withpen pencircle; % stroked |
| 77 |
addto pic also pp3; |
| 78 |
sh pic; % clipped(), stroked |
| 79 |
show ulcorner pic, lrcorner pic; |
| 80 |
setbounds pic to triang rotated 90; |
| 81 |
sh pic; show llcorner pic, urcorner pic; |
| 82 |
sh pic; % bounded(clipped(), stroked) |
| 83 |
dr contour triang scaled 12 withcolor (.4,.4,.4); % filled |
| 84 |
addto pic also pp3; |
| 85 |
sh pic; % bounded(clipped(), stroked), filled |
| 86 |
dr also "A56" infont "trapf"; % text |
| 87 |
addto pic also pp3 rotated 30 shifted (2,3); |
| 88 |
sh pic; % bounded(clipped(), stroked), filled, textual |
| 89 |
dr doublepath (4,5)--(8,1) withpen pencircle xscaled 0; |
| 90 |
addto pic also pp3; |
| 91 |
sh pic; % bounded(clipped(), stroked), filled, textual, stroked |
| 92 |
sh "non-picture"; |
| 93 |
endgroup; |
| 94 |
|
| 95 |
showstats; |
| 96 |
for p within pic: show p; endfor |
| 97 |
|
| 98 |
showstats; |
| 99 |
pic1 := pic; |
| 100 |
clip pic1 to circ; |
| 101 |
show length pic1; |
| 102 |
showstats; |
| 103 |
addto pic1 also pic dashed nullpicture; |
| 104 |
show pic1, length pic1; |
| 105 |
showstats; |
| 106 |
for p within pic1: |
| 107 |
show stroked p, filled p, textual p, clipped p, bounded p; |
| 108 |
show pathpart p, penpart p, dashpart p, fontpart p, textpart p; |
| 109 |
show (redpart p, greenpart p, bluepart p); |
| 110 |
show (xpart p, ypart p), (xxpart p, yxpart p), (xypart p, yypart p); |
| 111 |
showstats; |
| 112 |
endfor |
| 113 |
pic1 := nullpicture; |
| 114 |
|
| 115 |
for p within nullpicture: show p; endfor |
| 116 |
for p within "B34" infont "trapf": show p; endfor |
| 117 |
showstats; |
| 118 |
|
| 119 |
shipout pic; |
| 120 |
charcode:=1; |
| 121 |
prologues:=1; |
| 122 |
shipout pic rotated 90; |
| 123 |
|
| 124 |
|
| 125 |
string s,EOF; |
| 126 |
EOF=char 0; |
| 127 |
numeric n; |
| 128 |
n = 0; |
| 129 |
showstats; |
| 130 |
forever: n:=n+1; |
| 131 |
s:= readfrom "mtrap.0"; |
| 132 |
exitif (s=EOF) or (n>300); |
| 133 |
if substring (0,14) of s<>"%%CreationDate": show s; fi |
| 134 |
endfor |
| 135 |
|
| 136 |
numeric n; |
| 137 |
n = 0; |
| 138 |
showstats; |
| 139 |
forever: n:=n+1; |
| 140 |
s := readfrom "mtrap.1"; |
| 141 |
if n<=2: show s; fi |
| 142 |
exitif (s=EOF) or (n>300); |
| 143 |
endfor |
| 144 |
show n; |
| 145 |
|
| 146 |
showstats; |
| 147 |
show readfrom "mtrap.17"; |
| 148 |
for n=1 step 1 until 3: |
| 149 |
s := readfrom "mtrap.0"; show s; |
| 150 |
endfor |
| 151 |
|
| 152 |
showstats; |
| 153 |
for i=1 step 1 until 10: |
| 154 |
write decimal i & " " & decimal(i*i) to "writeo"; |
| 155 |
write substring(0,i) of " " & "*" to "writeo.2"; |
| 156 |
endfor |
| 157 |
showstats; |
| 158 |
|
| 159 |
write EOF to "writeo"; |
| 160 |
s:=readfrom "mtrap.0"; % Ignore creation date |
| 161 |
for i=1 step 1 until 3: |
| 162 |
show readfrom "writeo", readfrom "mtrap.0"; |
| 163 |
endfor |
| 164 |
showstats; |
| 165 |
|
| 166 |
write "Clobbered." to "writeo"; |
| 167 |
|
| 168 |
tracingstats:=1; |
| 169 |
begingroup % Force string pool compaction |
| 170 |
save s; string s[]; |
| 171 |
s0="a"; s1="b"; s2="c"; s3="d"; |
| 172 |
randomseed:=4.34294; |
| 173 |
for i=1 step 1 until 200: |
| 174 |
s[floor uniformdeviate 4] := substring (0,60) of |
| 175 |
(s[floor uniformdeviate 4] & s[floor uniformdeviate 4]); |
| 176 |
endfor |
| 177 |
show s1; |
| 178 |
endgroup; |
| 179 |
showstats; |
| 180 |
|
| 181 |
|
| 182 |
begingroup |
| 183 |
numeric n; |
| 184 |
interim warningcheck:=1; |
| 185 |
n = 12000; show n; |
| 186 |
interim warningcheck:=0; |
| 187 |
n:= 40000; show n; |
| 188 |
endgroup; |
| 189 |
|
| 190 |
showstats; |
| 191 |
for x within triangle: show x; endfor |
| 192 |
showstats; |
| 193 |
write triang to "writeo"; |
| 194 |
write "triangle" "writeo"; |
| 195 |
write "triangle" to triang; |
| 196 |
showstats; |
| 197 |
|
| 198 |
closefrom "mtrap.0"; |
| 199 |
string s; s=readfrom "mtrap.0"; |
| 200 |
show readfrom "mtrap.0"; % should be 2nd line, not 5th line |
| 201 |
|
| 202 |
end |