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 / No real numbers :(

Author
Message
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 20th May 2011 16:04
This code produce a result of 2??? Shouldn't the hash mark make it a real number?

do
distance_to_crosshair# = ((5)/2)
print distance_to_crosshair#
loop

It produces 2 with and without the # :S

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 20th May 2011 16:20
Try using real numbers instead of integers for the sum

do
distance_to_crosshair# = ((5.0)/2.0)
print distance_to_crosshair#
loop

see if this helps
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 20th May 2011 17:03
It helped, but why?

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th May 2011 17:09
DBPro will not make any assumptions about the data your calculating - you have to specify the .0 to 'tell' DBPro that your calculating a real number instead of an integer. It might well just be a speed concern, because integer math is faster than real number math, so it might try and get away with using integers by default.

Health, Ammo, and bacon and eggs!
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 20th May 2011 17:14
It's the auto-casting rules. So operations between two integers always produce an integer result. Whereas operation between a mixtures of Integer and floats or all floats produce a float.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 20th May 2011 19:30
with integer division, the decimal part is rounded off. 5/3=1, 9/2=4, etc. This is actually really useful in computer science, but it's kinda confusing at first xD


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 21st May 2011 10:42
Allrighty, I already use integer variables to round of float variables#

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...

Login to post a reply

Server time is: 2026-07-10 18:01:54
Your offset time is: 2026-07-10 18:01:54