Exponentiation with infix operators in (or operating on) the base: Difference between revisions
Content added Content deleted
(→{{header|Smalltalk}}: added Sorry for the output to look different; but it does not really make sense here) |
m (→{{header|Smalltalk}}: format) |
||
Line 319: | Line 319: | ||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
Smalltalk has no prefix operator for negation. To negate, you have to send the number a "negated" message, which has higher precedence than any binary message. Literal constants may have a sign (which is not an operation, but part of the constant). |
Smalltalk has no prefix operator for negation. To negate, you have to send the number a "negated" message, which has higher precedence than any binary message. Literal constants may have a sign (which is not an operation, but part of the constant). |
||
<lang smalltalk> |
<lang smalltalk>a := 2. |
||
a := 2. |
|||
b := 3. |
b := 3. |
||
Transcript show:'-5**2 => '; showCR: -5**2. |
Transcript show:'-5**2 => '; showCR: -5**2. |
||
Line 331: | Line 330: | ||
" Transcript show:'5**-b => '; showCR: 5**-b. -- invalid: syntax error "</lang> |
" Transcript show:'5**-b => '; showCR: 5**-b. -- invalid: syntax error "</lang> |
||
Using the "negated" message: |
Using the "negated" message: |
||
⚫ | |||
<lang smalltalk> |
|||
⚫ | |||
Transcript show:'5 negated**3 => '; showCR: 5 negated**3. |
Transcript show:'5 negated**3 => '; showCR: 5 negated**3. |
||
Transcript show:'5**2 negated => '; showCR: 5**2 negated. "negates 2" |
Transcript show:'5**2 negated => '; showCR: 5**2 negated. "negates 2" |
||
Line 345: | Line 343: | ||
Transcript show:'(-5**b) negated => '; showCR: (-5**b) negated. |
Transcript show:'(-5**b) negated => '; showCR: (-5**b) negated. |
||
Transcript show:'-5 negated**2 => '; showCR: -5 negated**2. "negates the negative 5" |
Transcript show:'-5 negated**2 => '; showCR: -5 negated**2. "negates the negative 5" |
||
Transcript show:'-5 negated**3 => '; showCR: -5 negated**3. |
Transcript show:'-5 negated**3 => '; showCR: -5 negated**3.</lang> |
||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |