On 2008-05-12 17:59, bintom wrote:
> On May 12, 8:23 pm, Lionel B <m...@[EMAIL PROTECTED]
> wrote:
>> On Mon, 12 May 2008 08:09:47 -0700, bintom wrote:
>> > I ran the following simple code in C++ and got unexpected results:
>>
>> > float f = 139.4;
>> > cout << f;
>>
>> > Output:
>> > 139.399994;
>>
>> > if( f == 139.4)
>> > cout << "Expected result";
>> > else
>> > cout << "Unexpected result";
>>
>> > Output:
>> > Unexpected reult
>>
>> [...]
>>
>> > Doesn't this look bad on C++'s resume?
>>
>> No, it looks bad on *your* resume ;-)
>>
>> http://www.para****ft.com/c++-faq-lite/newbie.html#faq-29.16
Please do not quote signatures.
> Thanks Lionel for directing me to the link, but my question remains
> unanswered. Should it be a computer science issue as it says on the
> site, VB should've produced a similar (inaccurate) result. I'm just
> trying to defend my resume.
You are comparing apples to pears, f is a float while 13.4 is a double
(an advice, always turn up the warning levels and fix as many of them as
you can), try this code and see what it does:
#include <iostream>
int main()
{
float f = 139.4f;
std::cout << f << "\n";
if( f == 139.4f)
std::cout << "Expected result\n";
else
std::cout << "Unexpected result\n";
}
--
Erik Wikström


|