Re: bitwise NOT

2020-01-14 Thread Todd Chester via perl6-users
On Tue, Jan 14, 2020 at 7:45 AM Paul Procacci > wrote:


 >> What is the syntax for a twos complement anyway?

I'm not sure I understand the question.
Two's compliment is +^ ... the routine you've been using.

On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users
mailto:perl6-users@perl.org>> wrote:

 >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
 >> mailto:perl6-users@perl.org>
>> wrote:
 >>
 >> Hi All,
 >>
 >> This works,
 >>
 >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
$d.base(16);'
 >>  5A
 >>
 >> But this does not:
 >>
 >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
 >>  -A6
 >>
 >> 1) who turned it into an negative integer?
 >>
 >> 2) how do I turn it back?
 >>
 >> Many thanks,
 >> -T

On 2020-01-13 21:18, Paul Procacci wrote:
 > If you read the signature for +^, you'll notice it returns an
Int.
 >
 > In your first working example, you're taking a uint8 with
binary value
 > 10100101, zero extending it to 64 bits via +^, applying a two's
 > compliment, and then assigning bits [0:7] to another uint8
which at that
 > point contains the binary value of 01011010 (or hex value 0x5A).
 > In your second example that isn't working, you're taking
uint8 with
 > binary value 10100101, zero extending it to 64 bits via +^,
applying a
 > two's compliment, and then displaying this *Int* (64 bits) as
hex.[1]
 > To turn it back you need to mask off bits [8:63] with: say
((+^$e) +&
 > 0x0FF).base(16);" [2]
 >
 > [1] I'd show you the 64 bit value but it's a bunch of 1's
followed by
 > the value -0xA6.
 > [2] Note, since the type has been promoted to an Int there'
no going
 > back to uint8 without an explicit assignment (afaik)
 >

That explains it.  Thank you.

I used uint8 to keep the ones to a mild torrent!

If I am remembering correctly, 0xA5 going to 0x5A is
a ones compliment.

What is the syntax for a twos complement anyway?





On 2020-01-14 05:14, Gerard ONeill wrote:
A negative number (-A5) is the twos compliment of the positive number.  
A ones compliment is all the bits flipped.  A twos compliment is a ones 
compliment plus one.  So a ones compliment of (A5) is (-A5 - 1), which 
is -A6.


So presumably, the twos compliment operator is (-). And I suppose for 
consistency, +-A5 gives you -A5, which makes +- the twos compliment 
bitwise operator..




It is a pain to keep the variables from being "Coerced to Int",
but this pretty much shows it

$ p6 'my byte $x = 0xA5; say $x.base(16), " original";
  my byte $y = +^$x; say $y.base(16), " ones compliment";
  my byte $z = $x + $y + 1;
  say $z.base(16), "  original + 2s compliment";'

A5 original
5A ones compliment
0  original + 2s compliment


Re: Bug in the documentation

2020-01-14 Thread JJ Merelo
I already did. It's a rather nasty bug in the graph generation module. Will
take some time.

El mar., 14 ene. 2020 a las 18:16, ToddAndMargo ()
escribió:

>
> >> El lun., 13 ene. 2020 22:33, ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> escribió:
> >>
> >> Hi All,
> >>
> >> https://docs.raku.org/type/UInt
> >>
> >> Type Graph
> >> Type relations for 404
> >>
> >> The chart is 404 missing
> >>
> >> To fix this, Raku can use the chart from
> >> https://docs.perl6.org/type/UInt
> >> https://docs.perl6.org/images/type-graph-UInt.svg
> >>
> >> Picky, Picky, Picky
> >>
> >> :-)
> >>
> >> -T
>
>
>
> On 2020-01-14 01:15, JJ Merelo wrote:
> > I'd be grateful if you (or someone) raised this issue in the doc repo.
> >
>
> Hi JJ,
>
> Off list:
>
> I have a rule against posting to that repo.
>
> I am so far behind in office work that I
> can not waste one extra minute on posting
> to a form that will NOT-A-BUG me.
>
> Do I have you word that you won't shoot me
> down if I post this?
>
> -T
>
>
>
>

-- 
JJ


Re: Bug in the documentation

2020-01-14 Thread JJ Merelo
I'd be grateful if you (or someone) raised this issue in the doc repo.

El lun., 13 ene. 2020 22:33, ToddAndMargo via perl6-users <
perl6-users@perl.org> escribió:

> Hi All,
>
> https://docs.raku.org/type/UInt
>
> Type Graph
> Type relations for 404
>
> The chart is 404 missing
>
> To fix this, Raku can use the chart from
> https://docs.perl6.org/type/UInt
> https://docs.perl6.org/images/type-graph-UInt.svg
>
> Picky, Picky, Picky
>
> :-)
>
> -T
>


Re: Bug to report: cardinal called an integer

2020-01-14 Thread JJ Merelo
El mar., 14 ene. 2020 1:24, ToddAndMargo via perl6-users <
perl6-users@perl.org> escribió:

> On 2020-01-13 15:16, Laurent Rosenfeld via perl6-users wrote:
> > Your own record over the last years shows that you very often don't
> > understand documentation (and I actually sometimes wonder whether you're
> > even really interested in trying to understand it).
>
> Actually, I go there a lot and I tear my hair out.
> They are the antithesis of how Perl 5 wrote their
> documentation (the only part of Perl 5 I like better
> than Perl 6).
>

Never miss a good chance to bash documentation...

>
> > Your disdain for the documentation just confirms that.
>
> The documentation needs work.  Several involved in
> the documentation process have mentioned this in
> several places.  It is not like it is a secret.
> I have tried to contribute to it before, but I
> can't get past JJ.
>

I, the sole gatekeeper of documentation lore, banish you from ever entering
my realm. Vade retro!

I mean, really...

>
> And why do you think I am constantly find errors
> in the documentation.  Because I ignore them?
>
> By the way, "C String" REQUIRES a nul at the end:
> an error in the NativeCall documentation.
>

No, it does not. And even if it did, it should better go to the C, not
Raku, documentation

>
>
> > But since you
> > also explained very clearly times and again in the past that you don't
> > want to read books or tutorials either, I also wonder whether you're
> > interested in learning the language. I mean, *really* interested, to the
> > point of making *real* efforts in that direction.
>
> You have no idea what I go through.  You will if
> you ever get to see my paper on NativeCall and
> Win API.
>
>
> > The way you consistently mixed up uint and Uint in the last hours,
> > despite having been warned about this mistake, also shows a lack of
> > proper consideration for the documentation.
>
> Now that is a mystery to me.  The documentation for UInt
> does not mention uint.   But UInt and uint act exactly
> the same and have exactly the same properties.  But
> somehow they are different.  Since you know more than
> I about Raku, please teach me the different.
>
> Maybe I presume too much thinking this is yet another
> error/oversight in the documentation.  Neither UInt
> or uint even show up on
>
> https://docs.raku.org/images/type-graph-Numeric.svg
>
>
> >
> > The way you obstinately use the word  "cardinal" these last days also
> > shows it, since there is simply no such thing as cardinals in the Raku
> > types, subsets, or whatever, and, even though some languages have used
> > it in the past (and, yes, I have also used Modula-2 in a quite distant
> > past), "cardinal" is certainly NOT a common IT concept (I mean in the
> > way integer, unsigned integer, or float are common concepts, often
> > defined by CPU manufacturers). Granted, most people here probably have a
> > good understanding of the word "cardinal," but it's essentially a math
> > concept, and has no precise definition in a programming language, unless
> > of course the programming language in question does define it, which
> > Raku doesn't. Yes, cardinals may be loosely described as integers equal
> > to or larger than zero, but that doesn't make a definition and that
> > tells us nothing about their range or maximal value, or about the
> > methods that can be invoked on them, and so on.
>
> "cardinal" is a generic arithmetic and programming term.
> It does not denote how many bit or bytes or whose CPU
> calls what.  And it is only uncommon if you have not
> heard it before.  And with your programming experience,
> you should know the difference between generic
> programming terms and language specific terms.
>
> > So, please, stop using the word "cardinal,", which is just improper,
> > useless and essentially meaningless in the context of thee Raku
> > language. Please use the types, subsets and other concept properly
> > defined in Raku.
>
> Look at what I write closely.  When I use a generic term like cardinal,
> I always put the Raku term in parenthesis.  If
> this is not understandable to others, then it is a technical
> writing issue on my part, not an ignorance of the
> specifics any programming language.
>
> I have been doing a lot with NativeCall and WinAPI
> functions the last several weeks, so I have been
> using a lot of generic terms and have had to learn C++
> terms the hard way and how they map to Raku types.
> (This is all in my paper.)  NativeCalls documentation
> is almost, but not completely, useless.
>
> By the way DWORD is a form of cardinal and are best
> emulated as uint16.  You run into trouble with int16.
> Did you notice that I said "form of a"?
>
> I do the same thing with the generic term "Pointer", which
> by the way can mean a lot of things.  Not all pointers
> are C Pointers, such as Perl 5's "references", which is
> what the parenthesis are for.  So when you use the term
> "Pointer" you have to say what kind of pointer your
> 

Re: bitwise NOT

2020-01-14 Thread Paul Procacci
 >> What is the syntax for a twos complement anyway?

I'm not sure I understand the question.
Two's compliment is +^ ... the routine you've been using.

On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> This works,
> >>
> >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
> $d.base(16);'
> >>  5A
> >>
> >> But this does not:
> >>
> >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
> >>  -A6
> >>
> >> 1) who turned it into an negative integer?
> >>
> >> 2) how do I turn it back?
> >>
> >> Many thanks,
> >> -T
>
> On 2020-01-13 21:18, Paul Procacci wrote:
> > If you read the signature for +^, you'll notice it returns an Int.
> >
> > In your first working example, you're taking a uint8 with binary value
> > 10100101, zero extending it to 64 bits via +^, applying a two's
> > compliment, and then assigning bits [0:7] to another uint8 which at that
> > point contains the binary value of 01011010 (or hex value 0x5A).
> > In your second example that isn't working, you're taking uint8 with
> > binary value 10100101, zero extending it to 64 bits via +^, applying a
> > two's compliment, and then displaying this *Int* (64 bits) as hex.[1]
> > To turn it back you need to mask off bits [8:63] with: say ((+^$e) +&
> > 0x0FF).base(16);" [2]
> >
> > [1] I'd show you the 64 bit value but it's a bunch of 1's followed by
> > the value -0xA6.
> > [2] Note, since the type has been promoted to an Int there' no going
> > back to uint8 without an explicit assignment (afaik)
> >
>
> That explains it.  Thank you.
>
> I used uint8 to keep the ones to a mild torrent!
>
> If I am remembering correctly, 0xA5 going to 0x5A is
> a ones compliment.
>
> What is the syntax for a twos complement anyway?
>


-- 
__

:(){ :|:& };:


Re: bitwise NOT

2020-01-14 Thread Gerard ONeill
A negative number (-A5) is the twos compliment of the positive number.  A
ones compliment is all the bits flipped.  A twos compliment is a ones
compliment plus one.  So a ones compliment of (A5) is (-A5 - 1), which is
-A6.

So presumably, the twos compliment operator is (-). And I suppose for
consistency, +-A5 gives you -A5, which makes +- the twos compliment bitwise
operator..

On Tue, Jan 14, 2020 at 7:45 AM Paul Procacci  wrote:

> >> What is the syntax for a twos complement anyway?
>
> I'm not sure I understand the question.
> Two's compliment is +^ ... the routine you've been using.
>
> On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
>> >> mailto:perl6-users@perl.org>> wrote:
>> >>
>> >> Hi All,
>> >>
>> >> This works,
>> >>
>> >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
>> $d.base(16);'
>> >>  5A
>> >>
>> >> But this does not:
>> >>
>> >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
>> >>  -A6
>> >>
>> >> 1) who turned it into an negative integer?
>> >>
>> >> 2) how do I turn it back?
>> >>
>> >> Many thanks,
>> >> -T
>>
>> On 2020-01-13 21:18, Paul Procacci wrote:
>> > If you read the signature for +^, you'll notice it returns an Int.
>> >
>> > In your first working example, you're taking a uint8 with binary value
>> > 10100101, zero extending it to 64 bits via +^, applying a two's
>> > compliment, and then assigning bits [0:7] to another uint8 which at
>> that
>> > point contains the binary value of 01011010 (or hex value 0x5A).
>> > In your second example that isn't working, you're taking uint8 with
>> > binary value 10100101, zero extending it to 64 bits via +^, applying a
>> > two's compliment, and then displaying this *Int* (64 bits) as hex.[1]
>> > To turn it back you need to mask off bits [8:63] with: say ((+^$e) +&
>> > 0x0FF).base(16);" [2]
>> >
>> > [1] I'd show you the 64 bit value but it's a bunch of 1's followed by
>> > the value -0xA6.
>> > [2] Note, since the type has been promoted to an Int there' no going
>> > back to uint8 without an explicit assignment (afaik)
>> >
>>
>> That explains it.  Thank you.
>>
>> I used uint8 to keep the ones to a mild torrent!
>>
>> If I am remembering correctly, 0xA5 going to 0x5A is
>> a ones compliment.
>>
>> What is the syntax for a twos complement anyway?
>
>
>>
>
> --
> __
>
> :(){ :|:& };:
>