@Vaibhav: Your method b doesn't work for floating point numbers
because they have finite precision. E.g.,as an extreme example, try it
on a = 1 and b = 1d-25. When you form a+b, the result is 1, not 1 +
1d-25. Then 1 - 1d-25 gives 1 (which is correct), and 1 - 1 = 0. The
latter should be 1d-25, so you have a total loss of precision in that
number. More common would be just a partial loss of precision.

Dave

On Jul 10, 3:55 pm, vaibhav shukla <vaibhav200...@gmail.com> wrote:
> On Mon, Jul 11, 2011 at 1:51 AM, aanchal goyal 
> <goyal.aanch...@gmail.com>wrote:
>
> > These are the various ways to swap 2 variables
> > a) Using temporary Variable
>
>        always inefficient. using extra memory.
>
> > b) Usnig some Arithmentic operation
>
>        works for all numbers even floating points
>       a and b are two no. to swap : a=a+b;
>                                                  b=a-b;
>                                                   a=a-b;
>    always works
>
> > c) Using bitwise XOR operation
>
>    since bitwise results an error in floating point numbers so this method
> also fails.
>  hence (b) is better among the three.what say ?
>
>
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
>   best wishes!!
> Vaibhav Shukla
>     DU-MCA

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to