473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

a=0.7 resolves to a<0.7?

I declared a=0.7,but when I checked with if else it goes to statement a<0.7,why?
Oct 23 '10 #1
2 1188
weaknessforcats
9,208 Expert Mod 8TB
You don't post your if/else statement.

I suspect you are running into rounding.

You should compare your floating point numbers +/- using an allowable precision:

Expand|Select|Wrap|Line Numbers
  1. if ( (a - .000001) < 0.7)
  2. etc...
Oct 24 '10 #2
donbock
2,426 Expert 2GB
Read what every computer scientist should know about floating-point arithmetic.

By the way, a better way to compare floating-point numbers for equality within a precision threshold is more like this:
Expand|Select|Wrap|Line Numbers
  1. if (fabs(variable - desiredValue) < threshold)
  2. ...
Refer to C FAQ 14.5 for the best way to do it.
Oct 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dan Jacobson | last post by:
Using <A name="x_y-z"></A>, I even get nervous about the _ and -. w3-recs/RECS/html4/struct/links.html seems to say all of ascii is cool and beyond. Anyway, just what is the safe range for...
6
by: Marcelo | last post by:
Hello! I am developping a Visual C++ .NET multiple forms application, which uses FTP connection. When I use more than one form, and include the <afxinet.h> library (necessary for FTP connection),...
1
by: anoop | last post by:
Hello, I am working on ASP .Net 2.0. I created a .aspx file named as enter_department_info.aspx and its code behind file as enter_department_info.aspx.vb which is written as codefile in asp.net...
10
by: Piotr | last post by:
I have a class 'Statistics' which has a private attribute ' vector<int>* _x;' And in the destructor of the Statistics, I have this code to free the memory: Statistics::~Statistics() { if...
10
by: Szabolcs Horvát | last post by:
Consider the attached example program: an object of type 'A' is inserted into a 'map<int, Am;'. Why does 'm;' call the copy constructor of 'A' twice in addition to a constructor call? The...
1
by: rdemyan via AccessMonster.com | last post by:
I have the following SQL statement in code: strSQL = "SELECT * FROM TABLEA WHERE F2 = 'SITE' This returns the record that I expect. However: the following does not strSQL = "SELECT *...
2
by: Steve JORDI | last post by:
Hi, I'm having a little trouble trying to update a page content when the user clicks a check box. Basically, I need to reload a page to update its content depending on that checkbox status. I...
1
by: widevision7 | last post by:
I have a web page that uses the following JavaScript to hide a <div> unless the checkbox is checked: <script type="text/javascript"> function showMe (it, box) { var vis = (box.checked) ? "block"...
1
by: sumanmshan | last post by:
Hi everyone, This is my first post to this forum, hope I would get a reply quickly :-) Iam using loadXML(xmlString) and it is always returning "false". My code looks like this : if...
3
by: SKbirdie | last post by:
I am writting a large if / else tree in an existing website. My include libraries have to be put into the html program using a scripting language called SpeedScript. These includes bring in the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.