API Reference › Builtin functions › floor
function

floor

floor(x) -> int

Converts a fixed (Q16.16) value back to an int by discarding the fractional part, rounding toward negative infinity. It is the counterpart to fx: you accumulate motion in fixed-point for sub-pixel smoothness, then floor the result to get the whole-pixel column or row to draw at. Because it floors rather than rounds, floor(fixed(3) / fixed(2)) is 1, not 2. Use it wherever a fixed value must become an integer coordinate, count, or index.

Parameters

xthe fixed-point value to floor

Example

program FixedToPixels {
  const TILE_SIZE: int = 16

  handler DrawWorld phase Render {
    Screen.clear(Color.MidnightBlue)
    let smooth_column = fixed(5) + fixed(1) / fixed(2)
    let pixel_x = floor(smooth_column) * TILE_SIZE
    Screen.fill_rectangle(x: pixel_x, y: 32, width: TILE_SIZE, height: TILE_SIZE, color: Color.LimeGreen)
    Screen.show()
  }
}
← All symbols