RE: associativity of ** operator

From: Bresticker, Shalom <shalom.bresticker_at_.....>
Date: Mon Oct 26 2009 - 21:59:12 PDT
Marq,

Writing 2**3**2 is not the same as writing on paper 2 followed by a superscripted 3 followed by a double-superscripted 2.

Those superscripts define an implicit associativity that does not appear when written linearly.

In these programming languages, it is a matter of definition.

In any case, changing the associativity now would cause a problem of backwards compatibility, which is the main reason it won't be changed in SystemVerilog (There won't be any more 1364 as it has been merged into SystemVerilog.).

I also don't see why you think that with left-to-right associativity it becomes equivalent to * except for the left-most operator. If that were the case, then 2**3**2 would give you (2**3)*2 = 16, not 64.

Regards,
Shalom 

> In LRM 2.3.1 I believe there is a mistake in operator 
> associativity. According to section 4.2.2 all operators 
> associate left to right except the contional operator. This 
> is the wrong choice in the case of the exponentiation 
> operator '**' because this operator should also associate 
> right to left. With left-to-right associativity this operator 
> becomes equivalent to the multiplication operator except for 
> the leftmost operand.
> 
> Here is a small example to show the difference:
> 
> 2**3**2 = ?
> 
> left-to-right associativity:
> 
> 2**3**2 = (2**3)**2 = 8**2 = 64 = 2**(3*2)
> 
> right-to-left associativity:
> 
> 2**3**2 = 2**(3**2) = 2**9 = 512
> 
> This should probably be changed in IEEE 1364 (Verilog) and 
> IEEE 1800 (SystemVerilog) as well.
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon Oct 26 22:01:28 2009

This archive was generated by hypermail 2.1.8 : Mon Oct 26 2009 - 22:01:53 PDT