On Mon, 03 Feb 2020, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> Did Larry put a sneaky way to tell how many bytes
> a UInt/Int is using?
> 

The number of bits required to store an Int is, for positive numbers,
the same as the index of their most significant bit, which is available
via Int.msb. From the bits, you can calculate the bytes.

How much memory the implementation actually allocates is "none of your
business" I suppose. And you get to decide how you want to treat zero and
negative integers (the latter probably by taking their absolute value).
Maybe you always want to add an imaginary sign bit as well.

Also please note that UInt is not a datatype and there is no storage
associated with it. UInt is the name of a property that a pre-existing
Int object can satisfy or not, namely being greater than or equal to
zero. There are no objects of type UInt. There are only Int objects
that smartmatch UInt or variables with a UInt constraint.

Regards,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

Reply via email to