From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107333 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Keith McKay Newsgroups: gmane.comp.tex.context Subject: Re: Arithmetic Overflow error in MetaFun Date: Sat, 16 May 2020 15:48:34 +0100 Organization: The PotHole Press Message-ID: References: <4830f0a0-ece9-53ce-2768-af9110f3962a@gmail.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6245585365145813295==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="23274"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat May 16 16:50:42 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZy9C-0005v9-B9 for gctc-ntg-context-518@m.gmane-mx.org; Sat, 16 May 2020 16:50:42 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 220F5183D03; Sat, 16 May 2020 16:48:40 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2TnfRyp2WJhD; Sat, 16 May 2020 16:48:38 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 69398183EBE; Sat, 16 May 2020 16:48:38 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 5412A183C63 for ; Sat, 16 May 2020 16:48:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yDMzuwbtsMUR for ; Sat, 16 May 2020 16:48:36 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.221.50; helo=mail-wr1-f50.google.com; envelope-from=mckaymeister@gmail.com; receiver= Original-Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id A67D3183AA1 for ; Sat, 16 May 2020 16:48:36 +0200 (CEST) Original-Received: by mail-wr1-f50.google.com with SMTP id v12so6684369wrp.12 for ; Sat, 16 May 2020 07:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:organization:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=6eIStu+5Hqge5XPa0Y2pPV7/Ycdp7Jp6VLUoTqvU+mE=; b=b+hPDI5Obmv4opehyHaZ3cVRXJMGzXP+u/WbM8WXGPzUncfBPlc4G1fdCB+AjMI9jB Gi2OWqWGOGyYPU0L8/zODw90eeEO7O7GYwhneidJeref03BRdwCzdxGSQWelh6CpXUKo jxxHqaZnvwfwvKdcj7jzSmemv5ox1YElgGZ+wmXa7itu2pJ3WjhfYnmxwK2ub9xi3FFh Ii/yinW4rK11C6r3zRga6zBdjj7tRhWsdEjxSdv+xpS3Tv9tgHPM1Ozpkn6FZdB3mkHB QUOLq53Ee1JlhVh+pNchAaki5odX6YQD9ays6dEuyaofF6T8JavjPnl1cMidlDQsop3C 4u8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=6eIStu+5Hqge5XPa0Y2pPV7/Ycdp7Jp6VLUoTqvU+mE=; b=tYLpO6xWk7FoEDAiR5egbmck35IjGrGZg9peHM+8eIBA3fUpG8qseNwn3a8Ny3gf+S RnrvNrtyvqgy2JqFIi3y1G5F7BF3QFqcIDpAfDcqbTzqXUV7jJ3OSq4tVepNyNytOajw 5zAwRewasOi7iD1iZnxSg9Z0g1iE4WrHUo2Ob8Hikzz2ipUfB1cdoUkttw6XFoAQ0geK ZYHG+OsecLAgUQ2OCSu6qdgf2j6xAJOHrMaLBQ3dUxxMqE3T1VhhsqVPhNj/2ZNPK1mH b/KQcreqcBKPSd0Gd0LglPebv+J+vyd7P8Xz9XaWujD2ymHc0wE+7WhpCYhVbmg4sW8+ 3CMQ== X-Gm-Message-State: AOAM532ImKRrORNyevZjnRW8fxTBFNr7ppWfu1nHB/s6cfIUSUMtxt4/ NIGGuHUOBCnUdyr6UG0E8lPGafRG X-Google-Smtp-Source: ABdhPJxCZQ8wnh97z+KSGCUd17eZ13epmIGJvYllKztYlOWaui/Rf56qLI57lzcNcZc4D6DQAhbiVA== X-Received: by 2002:a5d:65d0:: with SMTP id e16mr5939520wrw.371.1589640515996; Sat, 16 May 2020 07:48:35 -0700 (PDT) Original-Received: from Keiths-Mac-mini.local (cpc100294-uddi29-2-0-cust139.20-3.cable.virginm.net. [82.42.59.140]) by smtp.googlemail.com with ESMTPSA id w82sm7937283wmg.28.2020.05.16.07.48.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 May 2020 07:48:35 -0700 (PDT) In-Reply-To: <4830f0a0-ece9-53ce-2768-af9110f3962a@gmail.com> Content-Language: en-US X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107333 Archived-At: This is a multi-part message in MIME format. --===============6245585365145813295== Content-Type: multipart/alternative; boundary="------------C205FDD824FD8AFFEA619169" Content-Language: en-US This is a multi-part message in MIME format. --------------C205FDD824FD8AFFEA619169 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 > --------------C205FDD824FD8AFFEA619169 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

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

--------------C205FDD824FD8AFFEA619169-- --===============6245585365145813295== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============6245585365145813295==--