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 / This is annoying...decimal doesn't show (when it really should)

Author
Message
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 16:26 Edited at: 1st Aug 2010 18:28
Hello,

When somebody declares a variable as a float, that number should then be able to be used in a mathematical equation to return a value with a decimal point RIGHT?

So what is wrong with "test_2" in this example?
Why does the variable show the wrong value?

[EDIT]
NEVER MIND THIS

I included an image so you don't necessarily have to compile it yourself




metal is not music but a way of life...all hail to the reigning king METALLICA!!!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 1st Aug 2010 16:29
if you divide 2 integers, the answer will be an integer.

Mugen Wizardry
User Banned
Posted: 1st Aug 2010 16:32


CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 16:33
Okay i understand that. I doesn't seem right tho...(not you,the math in DBPro)

The "answer" is obviously not a whole number. It shouldn't return one.

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Mugen Wizardry
User Banned
Posted: 1st Aug 2010 16:35
FIX



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 16:37
yeah i understand that. thanks. I still don't think that a person SHOULD have to manually enter a decimal point before the program can show one. do i make any sense here?

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Mugen Wizardry
User Banned
Posted: 1st Aug 2010 16:37
Ya

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 16:40 Edited at: 1st Aug 2010 16:42
It kinda stinks that i can't divide 2 whole numbers "integers" and get the proper return information, especially since i actually declared "test_2" a float anyway. well, it is what it is i suppose.
thank you for your quick and informative responses.

[EDIT]

By the way...about the code snippet thing, i don't know what to type
before and after my source to get it in the code snippet box

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2010 17:21 Edited at: 1st Aug 2010 17:22
Quote: "By the way...about the code snippet thing, i don't know what to type
before and after my source to get it in the code snippet box"


Three ways:

Method 1
--------
Type or paste your code into your message. Then select all the code you've just entered, and then click the code button. The code tags should be added at the start and end of what you've just entered.

Method 2
--------
Click the code button. This will place the starting code tag at the end of everything you've typed so far (this can be annoying if you are not at the end of your message ). Now click immediately after the code tag (this shouldn't be needed but is ) and type in or paste the code you wanted. When you've finished click the code button again.

If the code tags are placed in the wrong place in your message just use cut and paste.

Method 3
--------
You can type the tags manually, e.g. type the following WITHOUT THE *

[*code]
print "Hello World!"
[*/code]

There is another way, but master those first.
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 17:26
awesome! thanx! i haven't been on the forum in a while, so i spaced(forgot) how to do it! i was feelin' all "NOOBY" and stuff. haha thanks again.

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 1st Aug 2010 17:41
By nominating the type of either side of the math operation, we're giving a hint to the compiler of what type of math operation should be. If both side are integers, it'll use integer operations (div,add,sub,mult), if it's a mix of floats (the integer get recast as float internally), or they're both floats, then it'll use the FPU.

RedFlames
18
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 1st Aug 2010 17:57 Edited at: 1st Aug 2010 17:58
And another thing:
using [c0de lang=dbp] instead of [c0de]
will give you syntax hightlighting:


MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 18:25
@Kevin Picone
I see what you are saying. It is unfortunate that it works that way(in my opinion), because this (for example) wouldn't return
the information that i would want



@redflames : hehe thanks

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2010 18:47
Quote: "because this (for example) wouldn't return
the information that i would want"


But this would. Is the difference in coding such a big deal?

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 1st Aug 2010 19:21
MOP,

Quote: "
see what you are saying. It is unfortunate that it works that way(in my opinion), because this (for example) wouldn't return
the information that i would want
"


It's the price DBpro (and most BASIC's of this type) pay, for automatically casting the two sides of the operator for us. If it didn't, we'd need to explicitly cast the terms every time.

ie.
print MyFloat#/float(fps())

MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 1st Aug 2010 19:39 Edited at: 1st Aug 2010 19:42
No not really i guess...
but it doesn't matter because if i change this...



to this....



it works the way i want it to anyway.

haha what a whole lot of fuss over nothin' ... sorry people.
thanx for the help!


[EDIT]

...AND DON'T CALL ME A MOP!!!!!!!!!!!!!!!!!!

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Aug 2010 22:40
Quote: "It is unfortunate that it works that way(in my opinion), because this (for example) wouldn't return
the information that i would want"


Actually, I DO want integer division thanks

Integer division is just as useful as floating point division. Therefore, it is sensible to assume that we must tell the compiler which one we want. Using float arguments to do float division and integer arguments to do integer division seems to me like a reasonable way to specify which form of division we want to use.

[b]
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2010 23:42
Excellent point.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 2nd Aug 2010 01:23 Edited at: 2nd Aug 2010 01:31
Yeah, integer division can be really useful, especially if you know you don't need all that decimal crap. It can play a big role in more complicated algorithms, along with the modulus function.

The modulus function, in case you're wondering, basically gives the remainder after integer division, so:
9/2=4
9 mod 2 = 1
4*2+1=9
4+1/2=9/2

or in general, where you're dividing a by b with integer division
(a/b)*b + a mod b = a
if that makes any sense
The way DBPro handles this is the standard way all programming languages i've used (java, c++, DBPro) handle it, with the exception that dbpro doesn't have casting (the compiler does it for you... correct me if i'm wrong).

[edit]
Let me explain a useful bit of modulus/integer division coding.
Say you have an AI routine, that should only be updated every 100 milliseconds. So, you have an integer (or dword) that stores the time in ms since its been updated. Now, this value will rarely be exactly 100 ms, it may be 130 or so. If you had code like this:

that would be "rounded off", and after four updates, 130 ms apart, you would only have updated 4 times, when the total elapsed time was 520 ms.

Some pro-ish codering if you wanted it always to be updated the correct number of times would be this:



Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 2nd Aug 2010 05:53
alright,

i know how to work around what my specific problem was.

thanks guys

metal is not music but a way of life...all hail to the reigning king METALLICA!!!

Login to post a reply

Server time is: 2026-07-25 17:05:25
Your offset time is: 2026-07-25 17:05:25