third root of -8...
Re: third root of -8...
...
Last edited by ratwolf on Tue Apr 20, 2021 1:34 pm, edited 1 time in total.
Re: third root of -8...
...
Last edited by ratwolf on Tue Apr 20, 2021 1:34 pm, edited 1 time in total.
-
- Posts: 1100
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: third root of -8...
This "unary minus," having higher precedence than subtraction, is something I seem to have found in every parser textbook I've ever looked at, but I can't figure out where it comes from. It doesn't seem to have originated from mathematics, or at least, all the math textbooks I have ever seen put parentheses around -1 in expressions like (-1)^n. And those are rather common!
It's not like I've taken a survey on the subject, but I wonder how common this high-precedence unary minus really is in practice. In C it seems to be irrelevant, because C doesn't have an exponentiation operator, and the HP-17B and 27S appear to give unary minus the same precedence as subtraction.
It's not like I've taken a survey on the subject, but I wonder how common this high-precedence unary minus really is in practice. In C it seems to be irrelevant, because C doesn't have an exponentiation operator, and the HP-17B and 27S appear to give unary minus the same precedence as subtraction.
Re: third root of -8...
...
Last edited by ratwolf on Tue Apr 20, 2021 1:35 pm, edited 1 time in total.
-
- Posts: 1100
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: third root of -8...
Yep, so that behaves like unary minus has the same precedence as subtraction, per the convention in written math. The calculator equivalents would be 8 +/- ENTER 3 1/X Y^X and 8 ENTER 3 1/X Y^X +/-, respectively.
Re: third root of -8...
OTOH, if C did have an exponentiation operator, it would probably have lower precedence than unary minus. All the unary prefix operators in C essentially have the same precedence, higher than any of the binary operators, so adding a binary operator with higher precedence would uglify the syntax somewhat.Thomas Okken wrote: ↑Mon Mar 22, 2021 11:01 amThis "unary minus," having higher precedence than subtraction, is something I seem to have found in every parser textbook I've ever looked at, but I can't figure out where it comes from. It doesn't seem to have originated from mathematics, or at least, all the math textbooks I have ever seen put parentheses around -1 in expressions like (-1)^n. And those are rather common!
It's not like I've taken a survey on the subject, but I wonder how common this high-precedence unary minus really is in practice. In C it seems to be irrelevant, because C doesn't have an exponentiation operator, and the HP-17B and 27S appear to give unary minus the same precedence as subtraction.