logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: swapping two numbers: msg#00008

Subject: Re: swapping two numbers
On Sun, Jun 25, 2006 at 12:31:19AM -0700, Larry Rosler wrote:
> > From: Philippe "BooK" Bruhat
> > Sent: Saturday, June 24, 2006 04:10
> > To: fwp@xxxxxxxx
> > Subject: Re: swapping two numbers
> >
> >
> > Le vendredi 23 juin 2006 ? 17:40, Samy Kamkar ?crivait:
> > > Although x could overflow in this case, where it wouldn't with an xor,
> > > right?
> >
> > I've quickly tried to overflow it, but I didn't manage to break it.
> > It looks like even if you overflow x with the first addition, you
> > cross the border in the other direction when doing the substraction.
> >
> > --
> >  Philippe "BooK" Bruhat
> 
> The issue has nothing to do with overflow; everything to do with loss of
> precision.  Subtraction of two nearly equal numbers, or addition of two
> numbers of opposite sign and nearly equal magnitude) followed by a second
> similar computation can produce results with few or no significant bits.
> 
> The only correct way to perform these in-place swap operations is to treat
> the operands as bit patterns and use the xor operation.

I disagree.

If we are talking about non-integers (or integers whose magnitude
exceeds the available precision), xor isn't even a possibility in pure
perl; +/- is the only possiblity, with the loss-of-precision you
mention restricting which values it will perfectly work for.

But if we are talking about integers, so long as the intermediate
values stay in a fully representable range (usually 53 bits) there's
no problem with the +/- approach; the xor approach, on the other hand,
will only work correctly with operands representable as unsigned ints
of the size chosen by perl's configure (under no integer) or signed
ints (under use integer).

Either way, xor is the loser.



Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
db.firebase.por...    text.xml.xalan....    qnx.openqnx.dev...    user-groups.zar...    internationaliz...    kde.devel.konve...    finance.e-gold....    emacs.latex.pre...    gis.therion/200...    web.webmin.gene...    yellowdog.gener...    vserver/2003-08...    redhat.release....    sysutils.tivoli...    xfree86.expert/...    mail.becky.user...    hardware.netapp...    netbsd.ports.xe...    python.distutil...    boot-loaders.gr...    culture.interne...    java.springfram...    activedir/2006-...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe