?

Log in

No account? Create an account

The Toybox

people for the conservation of limited amounts of indignation


Previous Entry Share Next Entry
lo, there is school. and stuff
children of dune - leto 1
seperis
So, got the test results back for C++.



So I kept my A; the written test was an 88, the lab practical 100. We went over the answers and one of the questions was odd enough that he may give us that one anyway, is currently looking it over.

It was as follows:

You should never compare two float point numbers. T/F

I said false, because if they are the same data type, you should be able to, and I assumed when he said float, he meant the actual data-type float point. However, float can also refer to double, and that's where everyone blinked and went huh? Becuase if he'd written: You should never compare a double and a float point, then of course true.

So hopeful.

The lab one was nice; no comments, just a happy number, which is a good sign, in that I didn't make any careless mistakes, it compiled properly, and it was clean.

I am not smug; I mean, my lecture was not great and that makes me sad. A couple of things were carelessness, one was just incredibly annoying in that I *changed it*, and the others were hmm.

Chemistry makes me want to die. That is all I will say about that one. C++ totally makes up for it.


  • 1
As an aside, you should probably not use == on a float or double. Something about how many digits are actually stored in memory vs. how many are actually visible. This problem may have been corrected in more recent compilers, but we were always instructed not to do so. Though, one supposes you could cast to int for comparison purposes (if you haven't covered that yet, casting is making one variable type another using a function built into C++). Natch, that requires figuring out if your compiler rounds up, rounds down or just drops the decimal altogether. The modulus operator often works better because you then know exactly what it's doing.

Of course, > or < are still just fine. So of course you can compare two float point numbers. /geek

I learned that you should never compare floating point numbers with ==, because the actual representation in memory may be different even if the values are basically equal.

But comparing with <, <=, > or >= is of course possible.

Congrats on the A!

What they said. I use C++ all the time, and of course you can use everything except ==.

- Helen

  • 1