Help to round floats to integers
BlitzMax Forums/BlitzMax Beginners Area/Help to round floats to integers
| ||
I need to be able to round a floating number down or up to the nearest integer. I did it this way with blitz3d; For i=1 To 20 x#=Ceil(ImageWidth (NumberList(i))/2.0) y#=Ceil(ImageHeight (NumberList(i))/2.0) HandleImage NumberList(i),x,y MaskImage NumberList(i),255,255,255 Next But don't know how to do it with Blitzmax's commands; Floor:Double( x:Double ) Ceil:Double( x:Double ) |
| ||
I don't understand. Floor() and Ceil() work exactly the same as in Blitz3D. |
| ||
Oh. Guess i got confused by the different looking syntax in the Bmax docs. Very well then. Thanks. |
| ||
Well, Blitz3D:Floor#(x#) BlitzMax: Floor:Double(x:Double) "Floor" is the function name. Functions, by default, return an Integer value. If you want to return something else, i.e. a Double (which is a more accurate Float), then you must specify it in the function declaration, hence, "Floor:Double". X:Double means that the function expects you to pass it a Double as a parameter, but note that you can pass it an Int, or a Float etc, and the function will cast it to a Double anyway. The X part is used internally by that function (X will refer to whatever value you pass to the function), but you don't need to worry about that. So to summarise, Floor:Double(x:Double) means that the function expects a Double value to be fed to it as a parameter, and will return a Double when the function has finished executing. Also, note that the # in the Blitz3D version means the value is a Float - Blitz3D did not have support for Double Precision values, which is likely what's confused you. |
| ||
While this was good to understand, I found the midhandle function which will be much simpler for centering the handle of those images. |