Thread overview | |||||
---|---|---|---|---|---|
|
January 28, 2014 CoffeScript adds a modulo operator %% | ||||
---|---|---|---|---|
| ||||
The latest changes in the CoffeScript language have added a built-in "%%" operator: > Correct modulo operator %% (respects negatives) https://gist.github.com/aseemk/8637896 (In Python the % operator works in this correct way.) It's the same operator I suggested to add to D. Bye, bearophile |
February 04, 2014 Re: CoffeScript adds a modulo operator %% | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Tuesday, 28 January 2014 at 10:55:08 UTC, bearophile wrote:
> The latest changes in the CoffeScript language have added a built-in "%%" operator:
>
>> Correct modulo operator %% (respects negatives)
>
> https://gist.github.com/aseemk/8637896
>
> (In Python the % operator works in this correct way.)
>
> It's the same operator I suggested to add to D.
>
> Bye,
> bearophile
Wouldn't be better if the current implementation just extends to work with negatives instead of create a new one?
|
February 04, 2014 Re: CoffeScript adds a modulo operator %% | ||||
---|---|---|---|---|
| ||||
Posted in reply to Asman01 | Asman01:
> Wouldn't be better if the current implementation just extends to work with negatives instead of create a new one?
The % operator present in D works with negative numbers in a definite way, as in C99. But it has a semantics that in most cases is not the most useful one.
You can't change the semantics of the % D operator because of code breakage and breakage of compatibility with C99. But %% is one of the few ways to offer a new semantics.
For unsigned values or signed values that D knows statically have a positive value %% gets replaced by %.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation