Integer overflow and underflow semantics

Era Scarecrow rtcvb32 at yahoo.com
Fri May 4 22:32:08 PDT 2012


On Saturday, 5 May 2012 at 04:57:48 UTC, Alex Rønne Petersen 
wrote:
> Hi,
>
> I don't think the language really makes it clear whether 
> overflows and underflows are well-defined. Do we guarantee that 
> for any integral type T, T.max + 1 == T.min and T.min - 1 == 
> T.max?
>
> This is relevant in particular for GDC and LDC since they 
> target a lot of weird architectures.

  Any systems that implement a carry flag likely works exactly 
like that. Carry flag is set or cleared after a math operation, 
allowing you to extend the size of your integer any level you 
want, like in oh the 6502?

  Might look something like this: Been a while but you should get 
the idea

  clc ;clear carry
loop_here:
  mov ax, [bx]
  adc [dx], ax
  inc bx
  inc dx
  dec cx
  cmp cx, 0
  jne loop_here

  ;if carry after this point then...
  jc overflow_warning



More information about the Digitalmars-d mailing list