•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,795 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 542 | Replies: 4 | Solved
![]() |
•
•
Join Date: Oct 2006
Posts: 130
Reputation:
Rep Power: 3
Solved Threads: 1
Hey everyone,
I was wondering if someone could explain to me the following bit of code. I understand != in logic but i dont know how to read it like this:
Thanks
I was wondering if someone could explain to me the following bit of code. I understand != in logic but i dont know how to read it like this:
float y = 0.01, x = 0.005, z; z = 2 * x + (y != 0.001);
Thanks
•
•
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation:
Rep Power: 1
Solved Threads: 6
Actually, in C 0 always stands for false, but any other number stands for true (not only 1). I'm not sure about the other way, it is possible that for this direction C automatically returns 1 (instead of any number different from 0).
However, knowing C it might be that the expression (y != 0.001) returns 0 when false, but 0.001 when true?
You can just test the code by simply outputting what (y != 0.001) returns and work from there.
Black Box
However, knowing C it might be that the expression (y != 0.001) returns 0 when false, but 0.001 when true?
You can just test the code by simply outputting what (y != 0.001) returns and work from there.
Black Box
Careful, checking for inequality using float is not an exact science due to the way a real number is stored in memory.
Most like it ( y != 0.01 ) will return a 1.000000 even when it should have return a 0.000000 if you use a float type and not a double.
Last edited by Aia : Dec 2nd, 2007 at 3:10 pm.
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C Forum
- Previous Thread: coding for cpu scheduling algorithm using C
- Next Thread: Tutorial on hash tables



Linear Mode