On Wed, Nov 30, 2022 at 03:07:44AM +, thebluepandabear via
Digitalmars-d-learn wrote:
> I am reading through Ali's book about D, and he gives the following
> examples for an overflow:
[...]
> The result overflows and is 1705032704.
>
> Also for the second example, it overflows and comes up wi
On Wednesday, 30 November 2022 at 11:40:36 UTC, thebluepandabear
wrote:
then the narrower value is converted to the wider type
**C.** If the signed type is wider than the unsigned type,
then the unsigned value is converted to the signed type
**D.** Otherwise the signed type is converted to the u
On 11/29/22 19:07, thebluepandabear wrote:
> But the book doesn't talk about why the D compiler came up with these
> results
The compiler doesn't do anything special. It's all about the lack of
bits to store the value. If the result needs 33 bits but the type has
only 32 bits, the contribution
then the narrower value is converted to the wider type
**C.** If the signed type is wider than the unsigned type, then
the unsigned value is converted to the signed type
**D.** Otherwise the signed type is converted to the unsigned
type
SDB@79
I didn't ask about casting...
On Wednesday, 30 November 2022 at 03:07:44 UTC, thebluepandabear
wrote:
I am curious as to what formula the D compiler uses for
calculating 'overflowed' values, if such thing exists? :)
Regards,
thebluepandabear
**Source:**
http://ddili.org/ders/d.en/cast.html?#ix_cast.arithmetic%20convers
On Wednesday, 30 November 2022 at 03:19:49 UTC, Basile B. wrote:
writeln((30LU + 30LU) % uint.max);
It's actually
writeln((30LU + 30LU) % (uint.max.to!ulong +
1));
or
writeln((30LU + 30LU) & uint.max);
On Wednesday, 30 November 2022 at 03:19:49 UTC, Basile B. wrote:
[...]
It's always a wraparound (think modulo) but your examples with
negative number can be explained because there are hidden
unsigned to signed implicit convertions.
That the only special things D does.
forgot to say, you can
On Wednesday, 30 November 2022 at 03:07:44 UTC, thebluepandabear
wrote:
I am reading through Ali's book about D, and he gives the
following examples for an overflow:
```D
import std.stdio;
void main() {
// 3 billion each
uint number_1 = 30;
uint number_2 = 30;
}
writeln("maximum
I am reading through Ali's book about D, and he gives the
following examples for an overflow:
```D
import std.stdio;
void main() {
// 3 billion each
uint number_1 = 30;
uint number_2 = 30;
}
writeln("maximum value of uint: ", uint.max);
writeln("
number_1: ", number_1);
writeln(