Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:40 30 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM Basic Exponentiation

Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5905
Posted: 08:49pm 24 Apr 2015
Copy link to clipboard 
Print this post

I just came across an interesting discussion on the PureBasic forum.
Do you treat 4^3^2 as
(4^3)^2 (left to right) or
4^(3^2) (right to left).

PRINT "4^3^2 = ";4^3^2
PRINT "(4^3)^2 = ";(4^3)^2
PRINT "4^(3^2) = ";4^(3^2)


Microsoft seems to work left to right and as MM Basic is based on GW Basic, it also uses left to right. This is stated in the manual so there should be no confusion.

It appears that many programming languages work right to left for 'power'
  Quote  
Mathematica 4^3^2 -> 262144
Maple 4^3^2 -> Error, power is non-associative
Maxima 4^3^2 -> 262144
Axiom 4^3^2 -> 262144
Reduce 4^3^2 -> 4096
Wolfram Language 4^3^2 -> 262144
Microsoft Visual Basic 6 4^3^2 -> 4096
MS Excel 4^3^2 -> 4096
perl 5 4^3^2 -> 262144 ie 4**(3**2)


Wikipedia says the exponential operator is right associative
http://en.wikipedia.org/wiki/Operator_associativity
  Quote  
In order to reflect normal usage, addition, subtraction, multiplication, and division operators are usually left-associative while an exponentiation operator (if present) is right-associative. Any assignment operators are also typically right-associative. To prevent cases where operands would be associated with two operators, or no operator at all, operators with the same precedence must have the same associativity.


Something to watch out for when translating programs and a good reason for lots of brackets.

Jim

VK7JH
MMedit   MMBasic Help
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3659
Posted: 10:10pm 24 Apr 2015
Copy link to clipboard 
Print this post

Interesting.... though I don't think I've ever written a double exponentiation in any language!

John
 
Dylan
Regular Member

Joined: 17/06/2013
Location: Netherlands
Posts: 81
Posted: 09:09am 25 Apr 2015
Copy link to clipboard 
Print this post

There are two reasons to.

1) Computer Science 2^(2^5) = 2^32 = maximum memory for a 32-bit OS, for example.

2) Physical sciences (2^t)^(1/3) = volume of something doubling every t time units.

Just don't look up http://en.wikipedia.org/wiki/Tetration and all will be well.
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 09:54am 25 Apr 2015
Copy link to clipboard 
Print this post

You mentioned it, I couldn't resist, I read the lot, and I am now more deranged than ever.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3659
Posted: 03:19am 26 Apr 2015
Copy link to clipboard 
Print this post

  Dylan said   There are two reasons to.

1) Computer Science 2^(2^5) = 2^32 = maximum memory for a 32-bit OS, for example.

2) Physical sciences (2^t)^(1/3) = volume of something doubling every t time units.

Just don't look up http://en.wikipedia.org/wiki/Tetration and all will be well.

For sure I've quite often used 2^32 one way or another, just never written it using a (to me pointless) double exponentiation.

John
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024