Lahey Support
08-15-2003, 01:19 AM
This method is subject to several problems. Overflow, underflow, and loss of
precision
can lead to situations where the three statements below would not swap A and
B.
Michael White's method of exclusive ORing the 2 two variables to be swapped
does not suffer from this problem since is a bit wise operation with no
consideration
of arithmetic. Michael's method would work on any data type except for the
fact that
the Fortran IEOR intrinsic function only works on integers.
Steven Humphreys
Sandia National Laboratories
-----Original Message-----
From: Jacek Magiera [address removed]
Sent: Monday, February 01, 1999 2:53 AM
To: [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...
precision
can lead to situations where the three statements below would not swap A and
B.
Michael White's method of exclusive ORing the 2 two variables to be swapped
does not suffer from this problem since is a bit wise operation with no
consideration
of arithmetic. Michael's method would work on any data type except for the
fact that
the Fortran IEOR intrinsic function only works on integers.
Steven Humphreys
Sandia National Laboratories
-----Original Message-----
From: Jacek Magiera [address removed]
Sent: Monday, February 01, 1999 2:53 AM
To: [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...