Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBC/DBP] Round Up Variables

Author
Message
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Nov 2007 22:06
Quote: "If 5 and 10 can be represented with floats, .5 and .1 can as well. The number itself is irrelevant in this situation since the decimal can be anywhere."


No, .1 cannot be represented exactly. Floats store their numbers as fractions with an exponent so the decimal point doesn't move anywhere, the fraction result is merely multiplied. You can read about it here: http://en.wikipedia.org/wiki/IEEE_754

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Nov 2007 22:49 Edited at: 28th Nov 2007 22:51
It can be represented exactly, the exponent moves the digits around the point so 1 can be displayed just as well as .1

@Latch
Thanks, I assumed the computer did the same thing anyway

"You must be someone's friend to make comments about them." - MySpace lied.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Nov 2007 23:06


This doesn't look exactly like 0.1 to me. That said, 0.1 should be just 1/10, however some more complex numbers will get inaccurate.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Nov 2007 23:17
hmm, I have noticed with some programs that adding/subtracting 0.1 around 0.0 has some funny results.

"You must be someone's friend to make comments about them." - MySpace lied.

Login to post a reply

Server time is: 2024-11-22 18:45:26
Your offset time is: 2024-11-22 18:45:26