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.

Newcomers DBPro Corner / is it me or is DB float/int usage a bit bananas?

Author
Message
Euphoria
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: United Kingdom
Posted: 10th Mar 2006 21:03
Am I missing something but am I right in saying you can't get a float from an equation containing only integers?



Results in number3# = 3

It would seem unless I reassign all the vars to floats (not great and un-neccessary) the only way round it is to do the following:



which produces the correct result...

Am I missing some magic usage of this or is the way DBP works its integer->float math just plain silly?....or maybe I should call it 'different', or perhaps 'special'
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Mar 2006 00:50 Edited at: 11th Mar 2006 00:50
It's not that special (it's the same for PlayBasic and Blitz for example).
The rule is simple, though
Integer / Integer = Integer
Float / Integer = Float
Integer / Float = Float
Float / Float = Float

Other than using a different symbol for integer divisions, there's no way for the compiler to tell whether you want to perform an integer or float devision (which are completely different kinds of operations for the CPU).

Euphoria
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: United Kingdom
Posted: 11th Mar 2006 23:59
Hmmm, ok maybe I am just looking at this wrong. I thought that maybe it would look at the datatype of the variable I am assigning (in this case number3#) and perform the appropriate method (integer or float) based on what I am asking for.

Thanks for the heads up...I'll have to try and not make to many assumptions like this, I only get disappointed.

cheerz!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 13th Mar 2006 23:16
Quote: "Hmmm, ok maybe I am just looking at this wrong. I thought that maybe it would look at the datatype of the variable I am assigning (in this case number3#) and perform the appropriate method (integer or float) based on what I am asking for."

Yes, generally that would make sense, but there are some problems that can occur when passing such expressions to (internal) functions, such as
MyString = Str$(5/2)
So should this be an integer, or float division?
For inbuilt functions DBpro uses overloading, ie. there is one Str$ function that requires an integer type argument, and another one that requires a float type argument, so the compiler has to decide what type the result of an expression is.

Login to post a reply

Server time is: 2024-11-27 23:41:03
Your offset time is: 2024-11-27 23:41:03