Post Reply 
Order of operations - what is 6÷2(1+2) ?
12-23-2020, 03:14 AM (This post was last modified: 12-23-2020 03:26 AM by robve.)
Post: #71
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 10:50 PM)Albert Chan Wrote:  
(12-22-2020 08:03 PM)robve Wrote:  Yes for Prolog:
?- X is -2^2.
X = 4.

Prolog should return -4 for this, according to its precedence table. (pow higher than unary minus)

Problem is it parsed first number as -2, removed the unary minus.

I agree. Parsers should not consider the - to be part of the number to avoid this flaw.

So it is ridiculously funny to see the following (note the spacing between - and 2):

?- X is -2^2.
X = 4.

?- X is - 2^2.
X = -4.

On the other hand, SWI-Prolog has a reasonably powerful implementation of multi-precision arithmetic with bigint and rationals (bigint/bigint) https://www.swi-prolog.org/pldoc/man?section=arith something I contributed to to this project many years ago and now fully integrated.

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Order of operations - what is 6÷2(1+2) ? - robve - 12-23-2020 03:14 AM



User(s) browsing this thread: 2 Guest(s)