All, Is there a switch I can set to get rid of the arithmetic
overflow in the following example?
%output=pdf
\setupcolors[state=start]
\definecolor[gridlines][s=0.7]
\startMPinclusions
color gridlines; gridlines:=\MPcolor{gridlines};
vardef create_grid (expr l,r,h,b,t,v,wid,ht)=
save ux, uy; numeric ux, uy;
(r-l)*ux=wid; (t-b)*uy=ht;
for k=b step v until t:
draw (l*ux,k*uy)--(r*ux,k*uy) withcolor \MPcolor{gridlines};
endfor;
for k=l step h until r:
draw (k*ux,b*uy)--(k*ux,t*uy) withcolor \MPcolor{gridlines};
endfor;
enddef;
vardef create_axes (expr l,r,b,t,wid,ht,blbl) (text xlbl,ylbl) =
save ux, uy; numeric ux, uy;
(r-l)*ux=wid; (t-b)*uy=ht;
textextoffset:=3pt;
drawdblarrow (1.05*l*ux,0)--(1.05*r*ux,0);
draw textext.rt(xlbl) shifted (1.05*r*ux,0);
if blbl:draw textext.bot(decimal r) shifted (r*ux,0); fi;
drawdblarrow (0,1.05*b*uy)--(0,1.05*t*uy);
draw textext.top(ylbl) shifted (0,1.05*t*uy);
if blbl: draw textext.lft(decimal t) shifted (0,t*uy); fi;
enddef;
vardef drawfcn (expr ind,dep,l,r,b,t,wid,ht,n) text txt =
save x, dx, ux, uy; numeric x, dx, ux, uy;
dx:=(r-l)/n;
(r-l)*ux=wid; (t-b)*uy=ht;
save cpath; path cpath; cpath:=(l,b)--(r,b)--(r,t)--(l,t)--cycle;
save p; path p; hide (x:=l;) p:=(scantokens(ind),scantokens(dep));
for xx:=l step dx until r:
hide (x:=xx;) p:=p--(scantokens(ind),scantokens(dep));
endfor;
hide(x:=r;) p:=p--(scantokens(ind),scantokens(dep));
p:=p cutbefore cpath;
p:=reverse p;
p:=p cutbefore cpath;
p:=p xyscaled (ux,uy);
drawdblarrow p txt;
enddef;
\stopMPinclusions
\starttext
\startMPpage %figure library name: x2
%initialize window parameters
numeric xmin, xmax, xscl, ymin, ymax, yscl;
xmin:=-10;
xmax:=10;
xscl:=1;
ymin:=-10;
ymax:=10;
yscl:=1;
%initialize number of points
numeric num_points;
num_points:=100;
%initialize dimensions of image
numeric width, height;
width=1.5in;
height=1.5in;
%create the grid
create_grid(xmin,xmax,xscl,ymin,ymax,yscl,width,height);
boolean lbl_scl; lbl_scl:=true;
%create the axes
create_axes(xmin,xmax,ymin,ymax,width,height,lbl_scl)("$x$")("$y$");
%draw the function
drawfcn("x","x*x",xmin,xmax,ymin,ymax,width,height,100)
withcolor blue ;
\stopMPpage
\startMPpage %figure library name: x4
%initialize window parameters
numeric xmin, xmax, xscl, ymin, ymax, yscl;
xmin:=-10;
xmax:=10;
xscl:=1;
ymin:=-10;
ymax:=10;
yscl:=1;
%initialize number of points
numeric num_points;
num_points:=100;
%initialize dimensions of image
numeric width, height;
width=1.5in;
height=1.5in;
%create the grid
create_grid(xmin,xmax,xscl,ymin,ymax,yscl,width,height);
boolean lbl_scl; lbl_scl:=true;
%create the axes
create_axes(xmin,xmax,ymin,ymax,width,height,lbl_scl)("$x$")("$y$");
%draw the function
drawfcn("x","x**4",xmin,xmax,ymin,ymax,width,height,100)
withcolor blue ;
\stopMPpage
\startMPpage %figure library name: x6
%initialize window parameters
numeric xmin, xmax, xscl, ymin, ymax, yscl;
xmin:=-10;
xmax:=10;
xscl:=1;
ymin:=-10;
ymax:=10;
yscl:=1;
%initialize number of points
numeric num_points;
num_points:=100;
%initialize dimensions of image
numeric width, height;
width=1.5in;
height=1.5in;
%create the grid
create_grid(xmin,xmax,xscl,ymin,ymax,yscl,width,height);
boolean lbl_scl; lbl_scl:=true;
%create the axes
create_axes(xmin,xmax,ymin,ymax,width,height,lbl_scl)("$x$")("$y$");
%draw the function
drawfcn("x","x**6",xmin,xmax,ymin,ymax,width,height,100)
withcolor blue ;
\stopMPpage
\stoptext
%%% Local Variables:
%%% mode: conTeXt-en
%%% End: