3 def -- = {curl 1}..{curl 1} enddef;
8 interim warningcheck:=0;
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;
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";
51 triang = (-3,-2)--(7,-2)--(0,7)--cycle;
52 circ = makepath(pencircle shifted (0,.5) scaled 10);
60 show p, stroked p, filled p, textual p, clipped p, bounded p, length p;
68 save pp; picture pp[];
70 pic = pp2 = nullpicture;
72 clip pic to makepath(pencircle scaled 100);
74 setbounds pp2 to triang;
76 dr doublepath (1,1)--(3,2) withpen pencircle; % stroked
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
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;
91 sh pic; % bounded(clipped(), stroked), filled, textual, stroked
96 for p within pic: show p; endfor
103 addto pic1 also pic dashed nullpicture;
104 show pic1, length 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);
115 for p within nullpicture: show p; endfor
116 for p within "B34" infont "trapf": show p; endfor
122 shipout pic rotated 90;
131 s:= readfrom "mtrap.0";
132 exitif (s=EOF) or (n>300);
133 if substring (0,14) of s<>"%%CreationDate": show s; fi
140 s := readfrom "mtrap.1";
142 exitif (s=EOF) or (n>300);
147 show readfrom "mtrap.17";
148 for n=1 step 1 until 3:
149 s := readfrom "mtrap.0"; show s;
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";
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";
166 write "Clobbered." to "writeo";
169 begingroup % Force string pool compaction
171 s0="a"; s1="b"; s2="c"; s3="d";
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]);
184 interim warningcheck:=1;
186 interim warningcheck:=0;
191 for x within triangle: show x; endfor
193 write triang to "writeo";
194 write "triangle" "writeo";
195 write "triangle" to triang;
199 string s; s=readfrom "mtrap.0";
200 show readfrom "mtrap.0"; % should be 2nd line, not 5th line