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 / Trouble with increase function

Author
Message
Gorandodic
13
Years of Service
User Offline
Joined: 19th Jul 2012
Location:
Posted: 19th Jul 2012 13:46
Hello,

In the following example:


X should stay at 2.9, but it goes to 3.0.

But if we say
then it will work properly. Anything over 2.3 shows an incorect result.

Why is this so in Dark Basic only and how to solve it? It doesn't seem mathematically correct.

Thank you.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Jul 2012 15:59 Edited at: 19th Jul 2012 16:00
Because you should use x# which is a float. Replace all of the x with x#.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Jul 2012 16:14
I've found that out recently... You need to do it as two separate lines:



Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Jul 2012 16:33
Both of those suggestions don't work.



TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jul 2012 16:48
This is probably why:



It is always unwise to expect perfect precision in floats in languages like DBPro.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Jul 2012 16:53 Edited at: 19th Jul 2012 16:55
Quote: "Both of those suggestions don't work."


Yeah, you are right. This bug didn't used to be there. It's using < as <=. A lot of my programs use <, and in the past they have worked. But I did notice in my new project that I was 1 number higher than I was supposed to be.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Jul 2012 16:56
That's an awkward one and I'm glad it's been mentioned because for the last few days I've not been able to figure out why I'm getting incorrect results.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Jul 2012 16:59 Edited at: 19th Jul 2012 17:01
Yeah that was why I ended up with half a sphere in my Universe Generator, I had to go back an extra number that I wasn't supposed to.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jul 2012 17:19
Quote: "This bug didn't used to be there. It's using < as <=. "


It isn't a bug and DBPro is certainly not using < as <=. As I said in my previous post it's caused by the limited precision of floats. Just run my snippet and look at the final value printed - it's less than 2.9 even though it would be exactly 2.9 if perfect precision were used.

Remember that floats are sums of powers of 2. Ask yourself how many powers of 2 do you need to get the value 0.1 exactly?
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Jul 2012 17:30
It does seem though that whenever I do something like:


When I come to use for example pers1 and pers2, only pers2 is defined as a float, pers1 is an integer...

However I have just learned that str$(value, value) formats the result... I didn't know that...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Jul 2012 17:33 Edited at: 19th Jul 2012 17:40
Quote: "It isn't a bug and DBPro is certainly not using < as <=..."


Yeah the same error is in DB Classic. I can't believe that I never noticed before.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jul 2012 17:53
Quote: "It does seem though that whenever I do something like"


That's a completely different issue. The variable pers1 needs to be declared as a float as well.

I don't think the syntax you are trying to use is supported.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Jul 2012 19:02
@Green Gandalf - It figures, and after ages of wondering why it wasn't working... It was this thread that got me to realise.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-07 14:23:30
Your offset time is: 2026-07-07 14:23:30