Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6981637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:10:58+00:00 2026-05-27T18:10:58+00:00

Or… how do you XOR doubles without getting integer results? I am using Actionscript

  • 0

Or… how do you XOR doubles without getting integer results?

I am using Actionscript 3.0 and found the following:

var a:Number = 3.000000004;
var b:Number = 29.999999999;
trace ("a: " + a); //3.000000004
trace ("b: " + b); //29.999999999
a ^= b;
b ^= a;
a ^= b;
trace ("a: " + a); //29
trace ("b: " + b); //3

Clearly, the XOR operation is converting my Numbers into ints. I am a bit surprised by this and don’t exactly understand the reason behind it. But I do know that other bitwise operations will also change Number into int, so I am not that surprised.

Be that as it may, is there a way to XOR doubles (aka Numbers) without having them get truncated to integers? I used the above XOR originally for performance optimization (these number switches are executed millions of times in an array). I assumed if I skipped the temporary variable, I would see a speed increase. Alas, if the Number data gets changed to int, it is all for naught.

Just wondering if there is a solution to this or if I need to give up on XOR in this case.

(ps, I won’t be able to check this thread for a while, but appreciate any suggestions, knowledge, etc. in the meantime)

(pps, in case you are curious, this is the method I am trying to speed up if possible)

public static function reversePairs(values:Vector.<Number>):void {
    //1, 2, 3, 4, 5, 6 -> 5, 6, 3, 4, 1, 2
    var l:int = values.length;
    var n:int = l * 0.5;
    n -= n % 2;
    for (var a:int = 0; a < n; a++) {
        var b:int = (l - a) - 2 * ((a + 1) % 2);
        //we cannot use xor because it truncates the decimal value
        //values[a] ^= values[b];
        //values[b] ^= values[a];
        //values[a] ^= values[b];
        //we MUST use a temporary variable instead
        var c:Number = values[b];
        values[b] = values[a];
        values[a] = c;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:10:59+00:00Added an answer on May 27, 2026 at 6:10 pm

    The xor-swap operation is not an optimization. It’s a pessimization.

    It’s hard to think to any architecture in which that would be a good idea (four steps each one depending on the completion of the preceding one even assuming read-modify-write memory to memory as atomic… a truly horrible implementation of swap).

    The best way to do an exchange between two values in memory is most often a double-read followed by a double-write:

    reg1 = mem1; reg2 = mem2;
    mem1 = reg2; mem2 = reg1;
    

    each of those pairs can also be executed in parallel (the two reads are independent, and also the two writes are independent) so the operation can complete in two steps.
    Most optimizing compilers are able to recognize the idiomatic three-steps swap

    { type temp = x; x = y; y = t; }
    

    to generate the two step exhange code for that it this is the best way for the hardware.

    That said something “equivalent” for floating point to that bad xor-swap code can be obtained by using inplace subtraction -= instead of inplace xor ^=.

    It is however a true exchange only if accuracy problems don’t kick in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I'm using a plugin to show only the first 500 characters of a text...
Since AVD tools 16 I'm getting this warning: Replace ... with ellipsis character (...,
I'm getting � characters when I combine Codeigniter's character_limiter() with PHP's native strip_tags() .
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
what about this one: I want to format the currentTime displayed by a videoPlayer
English is not my native language. I need a software to spellcheck and correct
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.