basic question
BlitzMax Forums/BlitzMax Beginners Area/basic question
| ||
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. |
| ||
because 1 and 2 are integers and 1.0 and 2.0 are floats |
| ||
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. |
| ||
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. |
| ||
@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. |
| ||
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 |
| ||
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 |
| ||
Also I'd recommend to always use either 'Strict' or 'SuperStrict'. It will save you some head scratching later. |
| ||
@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. |