[go-nuts] Re: Carting int to bool and the reverse for bit hacking ?

2020-11-21 Thread christoph...@gmail.com
Thank you for the responses. Unfortunately, they all comment on the given use case. The real question is if we should add a function in math/bits that performs the operation. The function would be func notZero(x int) int { if x == 0 { return 0 } return 1 } Regarding code

[go-nuts] Re: Carting int to bool and the reverse for bit hacking ?

2020-11-21 Thread b.ca...@pobox.com
That's fantastic. Paste in int Test0(int v, int v1, int v2, int v3) { return v == v1 || v == v2 || v == v3; } and then the the compiler options to -O3. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and sto

[go-nuts] Re: Carting int to bool and the reverse for bit hacking ?

2020-11-20 Thread silas poulson
On Friday, November 20, 2020 at 11:01:01 AM UTC b.ca...@pobox.com wrote: >I think the moral is: don't waste your time trying to outsmart the compiler. Would like to reiterate this - Godblot is an amazing tool for showing just how much you're compiler does for you -- You r

[go-nuts] Re: Carting int to bool and the reverse for bit hacking ?

2020-11-20 Thread b.ca...@pobox.com
On Friday, 20 November 2020 at 09:26:57 UTC christoph...@gmail.com wrote: > The use case I have to test if an integer is in a quite small constant set > of integers. With bool <-> int conversion, we can use binary operation like > this for instance which would be valid in C > > r := int(bool(v^v

[go-nuts] Re: Carting int to bool and the reverse for bit hacking ?

2020-11-20 Thread b.ca...@pobox.com
On Friday, 20 November 2020 at 09:26:57 UTC christoph...@gmail.com wrote: > A handy feature of bool <-> int conversion is that true is converted to 1 > and any integer different of zero to true. As a consequence, when we write > int(bool(x)) we get 0 when x is 0, and 1 when x is not 0. > I don'