Re: Integer arithmetic, multiplication overflow



On Wed, 08 Jun 2005 22:12:32 +0100, JEMebius wrote:

> If the result register of an integer multiplication instruction is twice
> as wide as the factor registers then overflow will never occur.
> ...

Yes, but lets try to detach it from this context.
For example in case of addition it's simple:
A+B > X => A+B overflows.
A+B - X = X - ((X-A) + (X-B)) - and all the terms can be
computed without overflow. form that point it is easy
to design general addition / subtraction algorithm
for any base, fixed precision arithmetic, and for example
having 32-bit integers build 2^32 based representation.
I am just trying to complete it with multiplication.
Shouldn't be that difficult I guess.
.



Relevant Pages

  • Re: Integer arithmetic, multiplication overflow
    ... >> If the result register of an integer multiplication instruction is twice ... >> as wide as the factor registers then overflow will never occur. ...
    (sci.math)
  • Re: interrupting for overflow and loop termination
    ... > only this int can ever overflow. ... maybe all you need is a sticky overflow bit. ... When a user-level instruction X caused an exception, ... The CAUSE register was set to indicate the reason. ...
    (comp.arch)
  • Re: Formatting in assembly
    ... not the overflow of assembly "mul" (multiplication is not intended ... The result is stored in register AX, register pair DX:AX, or register ... If the high-order bits of the product are 0, the CF and OF flags are ...
    (alt.lang.asm)
  • Re: Yet Another Spinoza Challenge
    ... Undefined behaviour is to make it easy to write optimising compilers. ... By saying "the behaviour on overflow is undefined" ... both the compilers can simply emit the code register a = register b + ...
    (comp.lang.c)
  • Re: Ranges and (non)static constraints
    ... Robert A Duff wrote: ... seems reasonable for a type that matches the machine's register size ... than some number of Mumble objects, or an array of them, we can be sure ... this count will not overflow. ...
    (comp.lang.ada)