A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308
Guillaume Piolat
first.name at gmail.com
Thu Aug 13 21:09:41 UTC 2020
On Thursday, 13 August 2020 at 07:22:18 UTC, mw wrote:
>
> void main() {
> long a = -5000;
> size_t b = 2;
> long c = a / b;
> writeln(c);
> }
>
>
> $ dmd divbug.d
> $ ./divbug
> 9223372036854773308
>
Feels correct to me !
When you have an unsigned and signed integer mixed with a binary
operator, the operands are converted to unsigned.
This is how it works in C and C++ and we wouldn't be able to port
C code to D if this were to be changed.
More information about the Digitalmars-d
mailing list