Menu

#41 Bit slicing without upper bound looses length information

Development
closed-invalid
None
5
2013-09-15
2013-08-25
No

I have been playing around with MyHDL the last couple of days. There are some things I find rather weird. One of these is the following:

In [1]: import myhdl
In [2]: a = myhdl.intbv(0)[10:]

In [3]: len(a)
Out[3]: 10

In [4]: len(a[:3])
Out[4]: 0

This seems weird, especially as using an open range (instead of an explicit 0) works fine too.

I attached a patch, which makes this work as I expected it:
len(a[:3]) == 7

1 Attachments

Discussion

  • Jan Decaluwe

    Jan Decaluwe - 2013-09-15
    • status: open --> closed-invalid

    Slicing refers to bits of the underlying integer value, regardless of bounds. It is then logical that an open upper bound means "all" the bits (an infinite number). len() == 0 means "undefined". "None" might be better but I think this was convenient at some point.

     

    Last edit: Jan Decaluwe 2013-09-15
  • Jan Decaluwe

    Jan Decaluwe - 2013-09-15
    • assigned_to: Jan Decaluwe
     

Log in to post a comment.

Auth0 Logo