ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Arithmetic Overflow
@ 2006-01-06  2:15 David Arnold
  2006-01-06  6:09 ` David Arnold
  0 siblings, 1 reply; 3+ messages in thread
From: David Arnold @ 2006-01-06  2:15 UTC (permalink / raw)


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:

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Arithmetic Overflow
  2006-01-06  2:15 Arithmetic Overflow David Arnold
@ 2006-01-06  6:09 ` David Arnold
  2006-01-06  8:14   ` Taco Hoekwater
  0 siblings, 1 reply; 3+ messages in thread
From: David Arnold @ 2006-01-06  6:09 UTC (permalink / raw)


I found warningcheck:=0. Anything allow me to get even bigger numbers  
to work?

On Jan 5, 2006, at 6:15 PM, David Arnold wrote:

> 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:
>
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Arithmetic Overflow
  2006-01-06  6:09 ` David Arnold
@ 2006-01-06  8:14   ` Taco Hoekwater
  0 siblings, 0 replies; 3+ messages in thread
From: Taco Hoekwater @ 2006-01-06  8:14 UTC (permalink / raw)


David Arnold wrote:
> I found warningcheck:=0. Anything allow me to get even bigger numbers  
> to work?

Not easily. There is a set of macros for arbitrary
calculation using strings instead of integers (sarith),
and for Mlog encoded numbers (marith).
That might help, but it will mean quite some changes
to your code.  There is some explanation on the top
of "sarith.mp" and "marith.mp", which should be on
your system already.

Cheers, Taco

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-01-06  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-06  2:15 Arithmetic Overflow David Arnold
2006-01-06  6:09 ` David Arnold
2006-01-06  8:14   ` Taco Hoekwater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).