I'm translating some Fortran into Javascript and the order of operations for exponents is pretty opaque to me for a particular class of equations.
Here's an example of the Fortran equation:
x = 1+a*b**c*c**d
Exponents in Fortran are designated with the ** operator. This page gives some hints:
Arithmetic expressions are evaluated in accordance with the following priority rules:
- All exponentiations are performed first; consecutive exponentiations are performed from right to left.
- All multiplication and divisions are performed next, in the order in which they appear from left to right.
So it feels to me like to translate this into, say, Python, you'd end up with something like:
x = 1+a*pow(b,c)*pow(c,d)
But that isn't getting me the answers I'd expect it to, so I wanted to check if that seemed sane or not (because order of operations was never a strong suit of mine even in the best of circumstances, certainly not with languages I am not very familiar with).
Here's another puzzler:
x = a*(1-(1-a)**b)+(1-a)*(a)**(1/b)
Oy! This hurts my head. (Does putting that lone (a) in parens matter?) At least this one has parens, which suggests:
x = a*(1-pow(1-a,b))+(1-a)*pow(a,1/b)
But I'm still not sure I understand this.