MR> CD>> I would love to hear a good explanation as to why 3.142(double)
MR> CD>> != 3.142(float)
MR> JdBP> Try converting them from base 10 to base 2.
One of the first things I learned in my current C++ class was not to
compare a float equal or not equal to another value. IE don't do this:
float pi=3.142;
if(pi==3.142) then ....
This is because all values in a computer are stored in binary. So the
float is converted to binary for storage. When it is called on to be
used the computer reconverts it a float. This will often result in
a difference of .0000001 or whatever depending on the number of bits
used by the particular compiler. and they will not be equal when they
should. I was taught compare to a range AS:
float pi=3.142;
if ( ( pi >= 3.141 ) && ( pi <= 3.143 ) ) then
---
þ OLX 2.1 TD þ Waffle softly and carry abig stick. B. Clinton
---------------
* Origin: Reeboot - Rio Linda, Ca. - Http://www.reeboot.com (1:203/24)
|