[fpc-devel] Division nodes

J. Gareth Moreton gareth at moreton-family.com
Wed May 17 10:51:06 CEST 2023


Logically yes, but using 16-bit as an example, min_int is -32,768, and 
signed 16-bit integers range from -32,768 to 32,767. So -32,768 ÷ -1 = 
32,768, which is out of range.  This is where the problem lies.

Internally, negation involves inverting all of the bits and then adding 
1 (essentially how you subtract a number using two's complement), so 
min_int, which is 1000000000000000, becomes 0111111111111111 and then, 
after incrementing, 1000000000000000, which is min_int again.

Kit

On 16/05/2023 13:13, Jean SUZINEAU via fpc-devel wrote:
> Le 16/05/2023 à 01:47, Stefan Glienke via fpc-devel a écrit :
>> min_int div -1
>
> "min_int div -1"  should give  "- min_int" ?
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>


More information about the fpc-devel mailing list