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.

DarkBASIC Professional Discussion / Possible DBPro bug, or possibly I'm just stupid

Author
Message
mef
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location: Canada
Posted: 11th Apr 2003 23:12 Edited at: 11th Apr 2003 23:18
Howdy all,

I am a beginner with DBpro having just recently purchased it and the first program I've written isn't working as it should. Basically the problem is that there is a real number variable called turnRate# that is only ever modified by incrementing or decrementing it by a constant value, DIFF# (inc turnRate#, DIFF# and dec turnRate#, DIFF#). turnRate# is initialized at 0.0 and DIFF# is a constant 0.1. Now, if turnRate# is only ever incremented or decremented by 0.1, its value should only ever be a positive or negative multiple of 0.1, right? Well when I run this code, the value of turnRate# is sometimes 1.49012e-008, sometimes 0.0999999.

Can anyone figure out the problem, or is this a compiler bug?

code snippet below.

mef

mef
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location: Canada
Posted: 11th Apr 2003 23:17 Edited at: 11th Apr 2003 23:17
Sorry, forgot to include my software/hardware specs:

DBPro patch 4
AMD Athlon tbird-a core 1800+ @ 1.53ghz
Aopen AK75
384mb ddr-2100 ram
ATI Radeon 8500 LE w/64mb DDR
Windows XP Professional SP1

thanks again.

mef

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Apr 2003 23:40
PRINT DIFF# and PRINT STR$(DIFF#) will return somewhat different values, the latter being more accurate. In addition it is generally limited to printing around 8dp. On top of that floating-point numbers cant represent some numbers - this applies to all languages...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Apr 2003 23:49
Look on this post, and follow the link you find there - more explanation than you ever need

http://www.darkbasicpro.com/apollo/view.php?t=8366&b=7
mef
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location: Canada
Posted: 11th Apr 2003 23:56
That's all well and good, but doesn't the fact that it's only ever changing by 0.1 and yet sometimes has non 0.1 multiple values strike you as odd?

For an example, compile the code and hold the left arrow key for two seconds, then release. The turnValue# will decrement, then increment but instead of sitting on 0, it will waver between two numbers that are very close to zero.

Another odd thing about this bug is that if you change DIFF# to another value, say 0.5, it will work properly, but 0.2 has the same bug.

mef

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Apr 2003 00:11
Nope, it's not suprising to me at all.

0.1 is not representable by the floating point within your processor, nor is 0.2, but 0.5 is. This is for the same reason that a third or a seventh is not representable in decimal.

The compiler used to produce the DLL core of DBPro was Visual C++ 6, which uses (by default) a 'fast and close enough' type approach to floating point calculations.

Using the more precise setting could cause a large slowdown for all floating point operations in DBPro, and not *significantly* improve the precision. Bear in mind that most 3D operations are implemented in floating point.
mef
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location: Canada
Posted: 12th Apr 2003 00:21
Hmm. Im not sure if that thread concludes that it's a compiler bug or just the nature of floats.

Anyways, I fixed it with a simple if statement which assigns 0.1 to the variable if the variable's value is between 0 and 0.1.

thanks for the help!

mef

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Apr 2003 00:32
It's just the nature of floats
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 12th Apr 2003 02:40
I think there is a problem with PRINT and PRINT STR$ often giving different precision, but Lee doesn't seem to agree...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!

Login to post a reply

Server time is: 2026-07-11 12:00:39
Your offset time is: 2026-07-11 12:00:39