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.

Newcomers DBPro Corner / Problem with Double Floats

Author
Message
AKJ
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location:
Posted: 4th Apr 2003 18:52
I am writing a program for which I need to use Double Floats, but I keep getting accuracy loss.

For example in the code:


I get a result of 10.10000038146973 and not 10.1 (to 16 sig. digits).

What must I do to get full Double Float accuracy?
Anthony Jordan
Nottingham, UK
Richard Davey
Retired Moderator
22
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 4th Apr 2003 20:44
You can try this:



But you'll get the same value in Z (although quite why it's wrong I don't know).

Cheers,

Rich

"Gentlemen, we are about to short-circuit the Universe!"
DB Team / Atari ST / DarkForge / Retro Gaming
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Apr 2003 21:37
It's all to do with floating point representation. Some numbers just cannot be stored accurately using floating point.

It's too complicated for me to explain, but if you really do need an explanation : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_why_floating_point_numbers_may_lose_precision.asp

In fact, the example shown right at the end actually explains your 10.1 problem.
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 4th Apr 2003 22:16 Edited at: 4th Apr 2003 22:17
Double Integers don't seem to work too well either.

This test will bit test both Integers and Double Integers (with the same value) and output the result.



If they worked, Double Integers would very handy for storing information on an 8x8 game board whether it be chess, checkers, othello (reversi) etc.

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Apr 2003 23:20
Ahh, but that's different - thats a DBPro compiler bug

If you pass 'test2' to 'Show32Bit' it actually displays the correct result in 32 bits.
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 4th Apr 2003 23:36
Dang! That's annoying, more bugs to squish. I take it Lee is already aware of this one. Oh well, I'll just have to wait for Lee to get the bug spray out and kill that one off

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.

Login to post a reply

Server time is: 2024-11-24 08:31:58
Your offset time is: 2024-11-24 08:31:58