www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Unsigned comparison operators

reply Cecil Ward <d cecilward.com> writes:
I love the D >>> operator and I use it a lot. So much safer than 
the chaos in C.

I would absolutely love to have unsigned comparison operators in 
D. Do you agree? What on earth would the syntax be like?

Yes, I could write a generic function or something, but the 
result would look ugly. And I would have to be very careful not 
to screw up type conversions (although i’m pretty sure there is 
some help available in the rtl to assist in getting the job done 
safely).
Sep 29 2017
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Friday, 29 September 2017 at 11:20:13 UTC, Cecil Ward wrote:
 I love the D >>> operator and I use it a lot. So much safer 
 than the chaos in C.

 I would absolutely love to have unsigned comparison operators 
 in D. Do you agree? What on earth would the syntax be like?

 Yes, I could write a generic function or something, but the 
 result would look ugly. And I would have to be very careful not 
 to screw up type conversions (although i’m pretty sure there is 
 some help available in the rtl to assist in getting the job 
 done safely).
I have a hard time imagining a use case. The reason why he have signed shift in the first place is to make the (n >> m) be equivalent to n * (2^^m)
Sep 29 2017
parent Cecil Ward <d cecilward.com> writes:
On Friday, 29 September 2017 at 14:13:07 UTC, Stefan Koch wrote:

 I have a hard time imagining a use case.
It just came up in a real application. It was a case of bit-twiddling, happened to come up during some weird 'arithmetic' when trying to write a jump-free replacement expression for a ? : because the compiler still generated jumps for a ? : when I didn't want it to. (A jump-less attempt at Bresenham's line algorithm.)
Oct 17 2017