PDA

View Full Version : Re: [LF] [LF digest]


Lahey Support
08-15-2003, 12:19 AM
The A=A-B, B=B+A, A=B-A scheme for swapping two numbers (there are many
equivalent variations of this) does not work for real numbers due to
potential
loss of precision:
Let A=10.E10 and B=10.E-10; the routine returns A=0. and B=10.E10.

Tim Ray

List Server wrote:


> Date: Mon, 01 Feb 1999 10:53:10 +0100
> From: Jacek Magiera [address removed]
> Subject: Re: [LF] swaping
>
> Hi, what about a sequence like this:
>
> A = A - B
> B = B + A
> A = B - A ?
>
> It's variable type independent.
>
> Jacek Magiera,
> Division of Computational Mechanics
> Cracow University of Technology
> Cracow, POLAND
>
> "Al Salamah, Muhammad" wrote:
> >
> > Hi there
> > I and most of the people I work with face the problem of swapping
the
> > values of two variables without ever needing a third variable. Can
any body
> > offer a solution. Thanks.
> >
> > ************************************************
> > ************************************************
> > ** Muhammad Al Salamah **
> > ** KFUPM **
> > ** Box 382 **
> > ** Dhahran 31261 **
> > ** Saudi Arabia **
> > ** Phone No.: Residence +(966)38606045 **
> > ** Office +(966)38602541 **
> > ************************************************
> > ************************************************