Author Topic: associativity of the exponential operator  (Read 7192 times)

0 Members and 1 Guest are viewing this topic.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: associativity of the exponential operator
« Reply #15 on: January 24, 2022, 04:19:48 am »
hello Qwerkey
thank you for the clarification :)

Offline Ed Davis

  • Newbie
  • Posts: 40
    • View Profile
Re: associativity of the exponential operator
« Reply #16 on: January 24, 2022, 07:48:45 am »
QB64 and other Basics treat the ^ operator as left-associative while other programming languages that have an exponentiation operator treat it as right-associative, for example Python and FORTRAN
doing a web search is inconclusive some assert that there's no consensus  whether it should be left or right associative while other state that it's right-associative
Mathematica and Maxima treats it as right-associative while Maple gives the error message that the power operator is non-associative
from a mathematical perspective which is right? non-associative or right-associative?

You might enjoy this article.  The author did a survey of how several languages treat this - it was very interesting!

https://codeplea.com/exponentiation-associativity-options

Just for fun, I played around with +2^+2^+3 and -2^-2^-3 in gw-basic, qbasic, vb.net, qb64 and vbscript.  gw-basic and qbasic gave identical results in all my tests.  The other 3 either failed or gave different results in some tests.  It was interesting, but as noted later on, hopefully no one would actually use such an expression without parenthesis.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: associativity of the exponential operator
« Reply #17 on: January 24, 2022, 08:46:41 am »
thanks Ed :)
as for negation I have seen that in math notation the number is enclosed in parenthesis like (-2)^k so I tend to agree with that.