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 7192137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:52:41+00:00 2026-05-28T19:52:41+00:00

Distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2) Is there a way to do this

  • 0

Distance between two points:

sqrt((x1-x2)^2 + (y1-y2)^2)

Is there a way to do this math faster in objective-C ?

EDIT: I think I need to clarify above. I wrote the formula above just to clarify what formula I am using to calculate the distance. ^ is not meant to represent xor – I just wanted to represent the mathematical formula without using any functions like pow or anything, so I meant to use ^ to “raise to the power off”. I was wondering if anyone knows if using bitwise operators, or otherwise writing code in assembly would give an optimized version. I am using the formula in an iPhone / iPad application.

  • 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-28T19:52:42+00:00Added an answer on May 28, 2026 at 7:52 pm

    No, if you need the exact distance you cannot beat that formula.

    Although to be clear ^ is not an operator for squaring a value, but a bit operator that does xor.

    you will need something like

    double dx = (x2-x1);
    double dy = (y2-y1);
    double dist = sqrt(dx*dx + dy*dy);
    

    If you can live with just the square (which is useful when you just want to do something like sort by distance, you can use the much more efficient

    double dx = (x2-x1);
    double dy = (y2-y1);
    double dist = dx*dx + dy*dy;
    

    These will be at least as good as a solution pow. At worst, pow() will use the stack and be less efficient, but maybe your compiler turns it into x*x for this case.

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

Sidebar

Related Questions

I need to create a class which calculates the distance between two points. I
Is there a way to get distance between two objects in meters? I'm trying
I need to calculate the distance between two points, but not in the regular
I am using this code to calculate the the distance between two points. I
I need to get the distance between two points from JavaScript to PHP using
What is the best way to calculate the distance between two points/Or we can
Hi I have the need to calculate the distance between two points having the
What's the best way to check for the euclidean distance between two points when
I'd like to work out the distance between two points. No map. No javascript.
I am trying to see if the calculated distance between two points is smaller

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.