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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:32:02+00:00 2026-05-21T03:32:02+00:00

In the following code, if x0 == x1 and y0 == y1, then it

  • 0

In the following code, if x0 == x1 and y0 == y1, then it should tell me so. In the example I’m using, they are. However, Python is only saying the x values are equal, not the y.

Here’s the code:

print "arc2x0 = ", arc2x0, ", arc2x1 = ", arc2x1
print "arc2y0 = ", arc2y0, ", arc2y1 = ", arc2y1

if arc2x0 == arc2x1:
    print "x0 == x1"
else:
    print "x0 != x1"

if arc2y0 == arc2y1:
    print "y0 == y1"
else:
    print "y0 != y1"

And here’s the output:

arc2x0 =  5 , arc2x1 =  5.0
arc2y0 =  -4.16026900507 , arc2y1 =  -4.16026900507
x0 == x1
y0 != y1

Any idea why the y values are testing as equal? These values are calculated in the same way. Maybe there’s more precision beyond what I’m seeing that isn’t equal? Any way to print that precision or any other ideas on how to debug this?

  • 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-21T03:32:02+00:00Added an answer on May 21, 2026 at 3:32 am

    Yes there is more precision beyond what you’re seeing. The problem is that the == operator should not usually be used with floats. Floating point numbers have limited precision and accumulate rounding error, and imprecision from not being able to store all decimal values precisely. e.g.

    >>> print '%.18f' % 0.1
    0.100000000000000006
    
    >>> 0.4 - 0.3 == 0.1
    False
    

    The best way to compare floats for equality is to compare if they are nearly equal:

    def nearly_equal(x, y, epsilon=1e-7):
        return abs(x - y) < epsilon
    

    By comparing if the difference between floats is less than an epsilon value, which indicates how close is considered close enough to be equal.

    You can always use the decimal.Decimal type to avoid these problems.

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

Sidebar

Related Questions

I'm using the following code to post to the server which is then sent
I have added a UIScrollVIew using IB. Then using the following code i add
Insofar as I can tell, the following code should work, creating a <div> element,
The following code gets a JSON object and then spits its contents out into
Following code iterates through many data-rows, calcs some score per row and then sorts
I have used the following code to set cookie and then redirect. String level=(String)
i've got the following code which runs a bat file. the bat file then
I expect the following code to unload a javascipt jqgrid, then load another grid
Assuming A.sql contains the following code, then second Select query won’t be executed due
I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is

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.