Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Richmond Newsgroups: comp.lang.forth Subject: Re: Question on exponentiation Date: Sun, 18 Dec 2016 18:07:24 +0000 Organization: Frantic Lines: 34 Message-ID: <85d1gp2js3.fsf@example.com> References: NNTP-Posting-Host: PvntusSwr4q7vyFfAigJOw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:1RcZ/0KEn8Ws7IfD4fe8fcXW+js= Xref: csiph.com comp.lang.forth:53408 Ron Aaron writes: > On 12/18/2016 13:35, Albert van der Horst wrote: >> In article , >> Ron Aaron wrote: >>> One of my users complained that in 8th, "-2 2 ^" gives "4" while python >>> (and google's calculator, etc) gives "-4". >>> >>> I maintain that "-2 2 ^" is equivalent to "-2 -2 *" and therefore must >>> be "4". But clearly there are programs (and authors thereof) which >>> disagree. >>> >>> Can anyone shed light on why python gives the answer it does, and >>> whether or not I'm just crazy to expect -2 2 ^ to give the answer 4 ? >> >> Python can't calculate "-2 2 ^", maybe "-2**2" . By having ** bind thighter >> than -, the result ensues. > > Yes, exactly. "**" binds tighter than monadic "-" in Python. You must > use parentheses to get the result I would expect naively. > >> Of course your result is correct. Furthermore the Python decision is >> dubious, it doesn't agree with the best thought language ever, Algol68. >> There the rule is: All monadic operators bind more tightly then >> dyadic operators. > > Interesting about Algol68; never had occasion to look at it, though I > was (, a long time ago) familiar with PL/1. > > I think this simply illustrates a prime advantage of the "Forth way", > e.g. that there are no precedence rules and items are evaluated in the > order they appear. I think python is correct. In mathematics -x² is not the same as (-x)².