Post Reply 
Order of operations - what is 6÷2(1+2) ?
12-30-2020, 05:41 PM
Post: #78
RE: Order of operations - what is 6÷2(1+2) ?
(12-23-2020 03:14 AM)robve Wrote:  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.

You are right.

I peeked at Lua 5.4 source code, llex.c, llex()
read_numeral() only allowed to convert non-negative numbers.

Code:
case '-': {  /* '-' or '--' (comment) */
  next(ls);
  if (ls->current != '-') return '-';
  /* else is a comment */
  ...
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
  return read_numeral(ls, seminfo);
}
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) ? - Albert Chan - 12-30-2020 05:41 PM



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