[sv-bc] RE: associativity of ** operator

From: Brad Pierce <Brad.Pierce_at_.....>
Date: Mon Oct 26 2009 - 23:32:23 PDT
Right-associativity would be more conventional for **.

Left-associativity degenerates to the following identity
 
            (x**y)**z = x**(y*z)

For example, consider (2**3)**5

    2 ** 3 = 

        2 * 2 * 2

   (2 ** 3) ** 5 =

        2 * 2 * 2 
     * 2 * 2 * 2   
     * 2 * 2 * 2 
     * 2 * 2 * 2 
     * 2 * 2 * 2 

Notice there are 3*5 factors of 2.

-- Brad

________________________________________
From: owner-sv-bc@eda.org [owner-sv-bc@eda.org] On Behalf Of Bresticker, Shalom [shalom.bresticker@intel.com]
Sent: Monday, October 26, 2009 9:59 PM
To: Marq Kole; verilog-ams@server.eda.org
Cc: sv-bc@server.eda.org
Subject: [sv-bc] RE: associativity of ** operator

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.
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon Oct 26 23:34:36 2009

This archive was generated by hypermail 2.1.8 : Mon Oct 26 2009 - 23:35:39 PDT