Jump to content
  • Advertisement
Sign in to follow this  
miodragsm

borland c++ builder 6 float error

This topic is 4871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm wondering why does borland c++ builder 6 turn my floats like 0.7f to 0.69999983... ?! i wrote float f = 0.7f; and debugger says 0.7 == 0.6999... ?! I dinn't notice this while working with MSVC !?

Share this post


Link to post
Share on other sites
Advertisement
OK, More concise answer from the C++ FAQ Lite says "On one C++ implementation, this prints 0.429993". I really dont care how compuer stores and represents number ( i knew this, exam ) and it's not the question. I want to know why Borland doesn't take care of this like MSVC does and if it can be tweaked in compiler setup...

Share this post


Link to post
Share on other sites
If you want it to print out 0.7, you have a variety of options that depend on where it's getting printed and what you're using to do the printing. If the debugger's display is all that is bugging you, I don't know what to suggest, other than read the documentation. (For example, in VC6, I know you can put a ", X" after the expression in the watch window to print it out in hex; there are probably other things available for fp-precision and such too.) But concerning non-debug related display, with printf()-style functions, you can always set the precision you want after the decimal place, and with std::stream objects, you can use the function setprecision().
float n = 0.7f;
printf("%.1hf\n", n);
std::cout << std::setprecision(1) << n << std::endl;

Share this post


Link to post
Share on other sites
The VS debugger shows 0.6999999 like it should, although cout apparently does round it. This is probably a side effect of precision...it rounds on that last digit, making the entire thing look like 0.7.

Personally, I think that should be the prefered behavior. Your variable doesn't equal 0.7 [it can't], so why should your debugger pretend it does? If its really a problem, your best bet would be to figure out to set the precision for your debugger, and set it to like 4 digits or something like that.

CM

Share this post


Link to post
Share on other sites
I was wrong about MSVC :( , it displays exactly like Borland debugger.
I've checked Delphi and it displays 0.7 for doubles ( not for reals ) Anyway, thanks everybody.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!