It is possible to substract 5 from 3 unsigned integer

Johan j at j.nl
Tue Oct 6 21:07:13 UTC 2020


On Tuesday, 6 October 2020 at 18:24:14 UTC, Alaindevos wrote:
> There are two subtractions possible.
> A machine-one which can be architecture dependent, does not 
> have the same results on all computers, and behaves like a 
> modulus in mathematics.
> A logical one. For the last one higher classes might be needed.

The (signed and unsigned) integer wrap around is well-defined in 
D, and is architecture independent. That means for example that 
if a specific architecture does not have a subtract instruction 
that wraps around according to what D specifies, then the 
compiler will generate the necessary instructions such that still 
int.min - 1 == int.max. That's similar to how integer 
multiplication 'just works' on architectures that do not have a 
multiply instruction.

-Johan



More information about the Digitalmars-d-learn mailing list