Scientific Math Text Input Evaluator

D

Deleted member 103

Guest
Hello Rioven,

Thank you!
I have your module installed in my update.


Ciao,
Filippo
 

agraham

Expert
Licensed User
Longtime User
-2^2 = -4 that's normal and must be so !
I hate to disagree but not necessarily so. Look at note one under "References and Notes" in that Wikipedia article you linked to. Also in the table of precedence for C type programs under "Mathematical precedence" the unary operators have the second highest precedence though you can't apply this example as C does not implement an exponentiation operator (it uses a function instead). My own opinion is that the "obvious" place for "^" is above the " * / % " operators and below unary " + - ".

In a Recursive Descent Parser, like the one I wrote for my BasicLib library, the "natural" place to put the unary operators is at the highest precedence so thay are treated like Sin(..) and Rnd(..) etc. In this case the unary " - " is like a Neg(...) function.

-2^2 = (-2)^2 = Neg(2)^2 = 4

Regardless of that, for many many years have I have not relied on precedence but always use parentheses in any but the simplest expression to make the order of evaluation explicit and most importantly, obvious.
 

klaus

Expert
Licensed User
Longtime User
Hi Andrew,

For the -2^2 = -4
I was reasoning like written or printed mathematics and not in programming language and for me the ^ sign is the exponant operator.

And it's the same reasoning as when -2^2 is somewhere else in the equation like:
5-2^2 = 1

Besides in B4PPC and VB -2^2= -4

Best regards.
 
Top