nordlow / gmp-d

D-language high-level wrapper for GNU MP (GMP) library
14 stars 6 forks source link

Add left shift (`<<=`) operator #11

Closed Luhrel closed 2 years ago

nordlow commented 2 years ago

Thanks!

nordlow commented 2 years ago

What about adding support for

  1. signed integer rhs-parameter to << and <<=
  2. >> and >>= operator

both calling truncating (integer) divide by two, @Luhrel.

For the sake of making semantics of bit-shift operators even more conformant with builtin integer types.

Division already mimics truncating division as, for instance,

    assert(27.Z / 10.Z  == 2);
    assert(27.Z /   10   == 2);
    assert(27.Z /   10UL == 2);

What do you think @9il?

9il commented 2 years ago

I would rather go with methods like mulPow2 to make code more obvious.

nordlow commented 2 years ago

I would rather go with methods like mulPow2 to make code more obvious.

Ok. But that makes code less substitutable and less generic.

9il commented 2 years ago

The operators are good as well. That isn't something critical.

Luhrel commented 2 years ago

What about adding support for

1. signed integer `rhs`-parameter to `<<` and `<<=`

2. `>>` and `>>=` operator

both calling truncating (integer) divide by two, @Luhrel.

It's a good idea.