Re: Integer arithmetic, multiplication overflow
- From: Tomek <t.koziara@xxxxxxxxx>
- Date: Fri, 10 Jun 2005 14:01:55 +0100
On Fri, 10 Jun 2005 01:49:45 +0000, Timothy Little wrote:
> Tomek wrote:
>> 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.
>
> I can see why (X-A) and (X-B) will never overflow, but how does this
> ensure that their sum doesn't overflow before you subtract it from X?
> Are you proposing to first check whether A+B would overflow, and only
> compute A+B - X if A+B > X?
>
>
> - Tim
Of course - this is useful only if we first check if A+B overflows.
The thing I was in particular wondering about was how to construct
general (X+1)-based integer operations having some working b-based
arithmetic, in which X is the biggest number. I mean - using only basic
arithmetic operations from b-based system, no bit shifts, tricks and so.
Schrager's algorithm, as suggested by Keith Duggar is helpful, but I am
not sure if it is enough - and actually, I have stopped wondering
and started to do the bits shifts ... :)
- Tomek
.
- References:
- Integer arithmetic, multiplication overflow
- From: Tomek
- Re: Integer arithmetic, multiplication overflow
- From: JEMebius
- Re: Integer arithmetic, multiplication overflow
- From: Tomek
- Re: Integer arithmetic, multiplication overflow
- From: Timothy Little
- Integer arithmetic, multiplication overflow
- Prev by Date: Re: ??? Quaternions ???---
- Next by Date: Attaction of Fixed Points
- Previous by thread: Re: Integer arithmetic, multiplication overflow
- Next by thread: Re: Number bases in an arbitrary field - question?
- Index(es):
Relevant Pages
|