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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:07:30+00:00 2026-06-05T07:07:30+00:00

Possible Duplicate: Comparing floating point values How dangerous is it to compare floating point

  • 0

Possible Duplicate:
Comparing floating point values
How dangerous is it to compare floating point values?

I don’t understand, why comparison of real numbers is a bad practice in programming? Of course I understand that real numbers can be represented with some order of accuracy. Can you explain me a weighty reason not to compare this kind of numbers? Examples would be good, the articles are also welcome.
Thanks beforehand.

  • 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-06-05T07:07:31+00:00Added an answer on June 5, 2026 at 7:07 am

    From all the questions from under floating-accuracy tag on this site any discussion should probably start with a reference to this question: How dangerous is it to compare floating point values?

    And a reference thereof to “What Every Computer Scientist Should Know About Floating Point Arithmetic” by David Goldberg. Here is a short summary.

    1. Exact floating point results are not portable

    Floating point arithmetic is neither commutative nor associative. IEEE 754 standard that most compilers and platforms follow does not guarantee exact reproducibility of results. Also results will vary on different processors.

    2. Floating point comparison does not agree with mathematics

    Consider the following statement

      int i = 0; double x = 1.0;
      while (x != 0.0) { x = x/2 ; i++;}
    

    In real numbers this computation should never complete however in floating point it will terminate. The value of i depends on the underlying hardware. Using floating point comparison will make it more difficult to analyze the code.

    3. Why then is floating point comparison implemented in hardware?

    There are places where exact floating point equality is necessary. One is normalization of floating point numbers.

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

Sidebar

Related Questions

Possible Duplicate: Comparing Two Arrays Using Perl How can I print values which exist
Possible Duplicate: problem in comparing double values in C# I've read it elsewhere, but
Possible Duplicate: Comparing two arrays & get the values which are not common I
Possible Duplicate: comparing two strings with comma seperated values I am working in C++,
Possible Duplicate: How do I compare strings in Java? Am I am comparing strings
Possible Duplicate: Tool to compare large numbers of PDF files? I am in the
Possible Duplicate: How does Python compare string and int? I was doing some comparison
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: Comparing object properties in c# Let's say I have a POCO: public
Possible Duplicate: Comparing Strings in Cocoa Why is this code not recognising the NSString

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.