Answering my own problem here. I've just searched through the mailing list archives and it seems that if I add [instance=doublefun] I do not get the Arithmetic Overflow error. Joy! Thanks Best Wishes Keith McKay On 16/05/2020 15:36, Keith McKay wrote:
Colleagues
I'm having problems with an Arithmetic Overflow error when calculating the x and y values for functions of the form:
y = ax^4 + bx^3 + cx^2 + dx + e
to which I then add a bit of randomness and other embellishments. I have had a look in the Metafun and Metafont manuals but nothing jumps out at me. In the minimum working example below, this Arithmetic Overflow occurs when xord =13.5 but I can get the calculation to work if I separate out the equation and then add together, since it seems to be failing on the pow(xord,4) instruction. Is there a switch in MetaFont that should be set or a better way of getting round this Arithmetic Overflow error?
Thanks
Best Wishes
Keith McKay
%%%%%%%%%%%%%MWE%%%%%%%%%%%
\setuppapersize [A4,landscape]
\starttext
\startMPpage
StartPage;
width := PaperWidth ; height := PaperHeight ; unit := cm ;
path p;
p := unitsquare scaled .1cm ;
path pat;
pat := (0.0*cm,19.935*cm);
for xord = 0 step 0.1 until 25:
show xord;
%%%%%%%%fails at xord = 13.5%%%%%%%%%
yord := ((-0.000268117) * pow(xord,4)) +(0.0136949 * pow(xord, 3)) + ((-0.16608) * sqr(xord)) + ((-0.771743) * xord) + 19.935;
%%%%%comment out above and uncomment below and it works%%%%
% yord1 := (-0.000268117) * sqr(xord);
% yord1a := yord1 * sqr(xord);
% yord2 := (0.0136949 * pow(xord, 3));
% yord3 := ((-0.16608) * sqr(xord));
% yord4 := ((-0.771743) * xord);
% yord := yord1 + yord1a + yord2 + yord3 + yord4 + 19.935;
xrand := (uniformdeviate(1) - 0.5)*2;
yrand := uniformdeviate(1) - 0.5;
xcoord := xord + xrand;
ycoord := yord + yrand;
if odd xord:
pat := pat ... (xcoord*cm, ycoord*cm);
else:
pat := pat --- (xcoord*cm, ycoord*cm);
fill p shifted (xcoord*cm, ycoord*cm) withcolor (uniformdeviate(1),uniformdeviate(1),uniformdeviate(1)) ;
fi;
draw pat withpen pencircle scaled (uniformdeviate(0.75)*mm) withcolor (uniformdeviate(1),uniformdeviate(1),uniformdeviate(1)); %withtransparency (1, .5);
drawdot (xcoord*cm, ycoord*cm) withpen pencircle scaled (uniformdeviate(2.5)*mm) withcolor (uniformdeviate(1),uniformdeviate(1),uniformdeviate(1));
endfor;
StopPage;
\stopMPpage
\stoptext