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 / INT() plays with me, is this right or not? and why?

Author
Message
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 21st Oct 2011 14:35
Well, MY dark basic keeps telling me that this one:

-6.99999952316

Equals -6 converted to integer.

Why? Shouldn't it be -7?



-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 21st Oct 2011 14:39
Int apparently rounds down.

print int(6.9)

returns "6" on my Laptop.

Looking at the help files, this is the expected behaviour?

Quote: "
INT
This command will return the largest integer before the decimal point of a real number.

"


I'd also like to point out that DBP floats are only accurate to 7 significant figures.

Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 21st Oct 2011 14:44
That's a number calculated by DB, not me.

Well awesome i even have to write my own function for rounding numbers, we go PRO NOW!!!

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Oct 2011 14:50
I noticed on someones thread a similar question. Something to do with floor() and ceil()...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 21st Oct 2011 15:00


Hope this helps

Red Eye
17
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 21st Oct 2011 15:00 Edited at: 21st Oct 2011 15:01
Quote: "Well awesome i even have to write my own function for rounding numbers, we go PRO NOW!!!"




I am no a dbpro coder so i dont know if the above is correct, yet in C++ I use the same formula.

EDIT: Post above was first, congrats! YOU BEAT ME! OMG

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Oct 2011 19:58
Quote: "Int apparently rounds down."


It doesn't. It rounds towards zero - just as the Help file rather clumsily says.
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 21st Oct 2011 20:15
@Green Gandalf:

Yeah, it was just an initial observation when I tried int(6.9)

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Oct 2011 01:11
Just use "floor(x#+0.5)"

[b]

Login to post a reply

Server time is: 2026-07-10 04:20:28
Your offset time is: 2026-07-10 04:20:28