Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

why the output is yes no instead of no no #include int main() { float f1=14.375; float f2=14.385; if(f1==14.375) printf("yes\n"); else {printf("no\n"); if(f2==14.385) printf("yes\n"); else printf("no\n"); return 0; }

OpenStudy (e.mccormick):

dpaste, pastebin, or github's gist makes the code OH so much easier to read... http://dpaste.com/1275611/ All numbers are stored in binary by the computer. That is why. Now to explain: Say that I have \(\frac{1}{3}\) and \(\frac{1}{6}\) and I say to save them to three decimal places. \(\frac{1}{3}\approx .333\) and \(\frac{1}{6}\approx .167\). Now, lets do some basic math! \(\frac{1}{3}=2\times \frac{1}{6}\) \(.333\ne 2\times .167\) This is a rounding error in ten base decimal math. What you are seeing in your program is a rounding error in base two (binary) floating point math.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!