Killing integer division problems?

jmh530 john.michael.hall at gmail.com
Tue Aug 4 12:53:24 UTC 2020


On Tuesday, 4 August 2020 at 12:34:37 UTC, burt wrote:
> [snip]
>
> Would such a change require a DIP? Could a -preview/-transition 
> flag be added to warn me about integer divisions? What do you 
> think?

The problem is you have stuff like
```d
int x = 2;
int y = 4 / x;
```
and now you would be force someone to write a cast.

That's a big enough change that it would require a DIP. Though 
I've been hit by the same thing in the past, I would be a bit 
skeptical you could get it through since a lot of code depends on 
that.

You could also always use something like below instead of the 
operator overloading.
double divide(T, U)(T x, U y)
     if (isIntegral!T && isIntegral!U)
{
     return cast(double) / cast(double) y;
}




More information about the Digitalmars-d mailing list