basic question

BlitzMax Forums/BlitzMax Beginners Area/basic question

Ashes(Posted March) [#1]
i have the following code:

Local sum:Float
Local a:Float = 25.6

sum = (1 / 2) * a

Print sum 'sum is 0


Why does the compiler treat (1/2) as an integer?

If I write

 sum=(1.0/2.0)*a 


I get a good float result.


GW(Posted March) [#2]
because 1 and 2 are integers and 1.0 and 2.0 are floats


Floyd(Posted March) [#3]
I don't know all the rules, or even where to find them, for arithmetic with mixed operand types. But when both operands of the same type the result is also of that type.

So ( 1 / 2 ) is ( integer operator integer ) and the result is integer.


FireballStarfish(Posted March) [#4]
You can find them in the BlitzMax help under Language/Data types.
What isn't mentioned there is that the ^ operator is an exception, it will always return Double.


Ashes(Posted March) [#5]
@GW - yes, I get that they are ints, the question was why? I am guessing that either there are cases where one might need them as ints but I cant think of any or its a rule required for better blitzmax operations.

I looked into the data types section of blitzmax help and found no reference to actual numbers being floats or ints. Maybe 1 being int and 1.0 being float is common sense for programmers.

Thanks for the answers.


Ashes(Posted March) [#6]
The literal types are specified in the literals section of the help... we're learning.

Is there any way to define a function or method that returns no value?

For example

Method DrawStuff:Void(img:TImage,coord:TPoint)
  DrawImage (img,coord.x,coord.y)
End Method 




Derron(Posted March) [#7]
Void is possible with Brucey's BMX-NG.

With vanilla you will have to leave out the return type.

Function test(param:int)
...
End Function


Bye
Ron


col(Posted March) [#8]
Also I'd recommend to always use either 'Strict' or 'SuperStrict'. It will save you some head scratching later.


Ashes(Posted March) [#9]
@Derron, I will look into BMX-NG after I finish the current project. Thanks for the info.

@Col Yes, I'm always using SuperStrict it's great. I'm also using BLIDE which avoids a lot of head aches as well.