From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107331 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Keith McKay Newsgroups: gmane.comp.tex.context Subject: Arithmetic Overflow error in MetaFun Date: Sat, 16 May 2020 15:36:10 +0100 Organization: The PotHole Press Message-ID: <4830f0a0-ece9-53ce-2768-af9110f3962a@gmail.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3333592197143234828==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="96222"; 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:36:30 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 1jZxvR-000OvL-GU for gctc-ntg-context-518@m.gmane-mx.org; Sat, 16 May 2020 16:36:29 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id EBEE4183D43; Sat, 16 May 2020 16:36:16 +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 QJp68rYczHs5; Sat, 16 May 2020 16:36:16 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 10505183EC6; Sat, 16 May 2020 16:36:16 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id BB14A194085 for ; Sat, 16 May 2020 16:36:14 +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 6lmfHRGCD7ge for ; Sat, 16 May 2020 16:36:13 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.128.54; helo=mail-wm1-f54.google.com; envelope-from=mckaymeister@gmail.com; receiver= Original-Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 816F8C0F for ; Sat, 16 May 2020 16:36:13 +0200 (CEST) Original-Received: by mail-wm1-f54.google.com with SMTP id n18so1289581wmj.5 for ; Sat, 16 May 2020 07:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:organization:message-id:date:user-agent :mime-version:content-language; bh=Ov49QFpIkZkDNr1rafo85TLMFDUFtkTA8xzjUBRboO4=; b=rdvMcPZDqsXdfk7OVeU184O8chwCuuQSeQJ0BUNWnshgmj6uzBOH43z8YkWmd/g7KU rSbE75ZsTC7EqEi8BdbErJysTUfUVpM9bsGr0KxSkG08Jm09jfHipPMlX+4QZe3jlKVG tFOmKP4MJzv8RK+Uv8J3922ZSgcIxihqw+nyHQVSARHbmQqpNzCc/FImxOK8EGG0aQLN EFQAZJ5IE2RT6w/GPXX2il14e2954IGlIkIOKk6xvGqnidsjNy/3s3/RB6pEi+Z9ZUE5 eaVBAN8AyihgP7U7aS2QkJj6ekjmDTwZmdqi9kvvLOrkEMHpoS4L4SXIiZmFuYLdRLfC cBHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:organization:message-id:date :user-agent:mime-version:content-language; bh=Ov49QFpIkZkDNr1rafo85TLMFDUFtkTA8xzjUBRboO4=; b=UYH/pazQDDsrX2yA5z+koWKiYVp/yPXHvd3AAHyL6nTzI4YZJgRyx5hhtP6bcX9Igd LhuVlBZa1RtM8aC1Z5RPFdfed6BpVcMjxknVQnmp7doqH7VTUU0NKKc5oFGdFykpFaly FX+PRqYszBnGiiGwUW7Xhqs2suZD0UxYzR/LReqso5oj3cW6oYCSoECI72wpMImuN6nZ zzu3Re/LNYd5pEe0U7K3/Ergx3xpLw78VpNgmOZIAlXUZ/aw7dkGlOMhOYjAWLIn+MNB ZoElLW4R5rvMLV/mnAd+5o0J5I7l73j6mUp9BIbF3mUKQqE1rxhU3GILdyK2HRWP2wyX Q/VQ== X-Gm-Message-State: AOAM533lerMigI2b1xDaTx1M/6kJ+3sSDcN+cQxeMDgzUyU8Fd4qxDEt +HDbRG9cMVs1zetp+w1yvWYaBRMu X-Google-Smtp-Source: ABdhPJzp44c7tBcjUp1HWihblkeqqu9CJl4Vrgdfw2/EgWvafBw4JfTV42iq4MXVZqNSDDfCoPNJIA== X-Received: by 2002:a1c:2e4d:: with SMTP id u74mr9899219wmu.145.1589639772728; Sat, 16 May 2020 07:36:12 -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 q9sm7804090wmb.34.2020.05.16.07.36.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 May 2020 07:36:12 -0700 (PDT) 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:107331 Archived-At: This is a multi-part message in MIME format. --===============3333592197143234828== Content-Type: multipart/alternative; boundary="------------4420B3FC2A64AB5C6699E2B4" Content-Language: en-US This is a multi-part message in MIME format. --------------4420B3FC2A64AB5C6699E2B4 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------4420B3FC2A64AB5C6699E2B4 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

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

--------------4420B3FC2A64AB5C6699E2B4-- --===============3333592197143234828== 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== --===============3333592197143234828==--