API Reference › Builtin functions › fixed
function

fixed

fixed(x) -> fixed

Converts an integer into a fixed value (Ludic's Q16.16 fixed-point type), so it can take part in fractional arithmetic. fixed is how you carry deterministic sub-pixel precision for smooth movement and physics-like accumulation; a float or double converts too, truncated toward zero to Q16.16. Use fixed when you need to combine an int with fixed-point values or divide to get a fraction — for example fixed(1) / fixed(4) is 0.25. Convert back to a whole number for drawing with flr.

Parameters

xthe integer (or float) to convert

Example

program SmoothAccumulate {
  handler ComputeStep phase Start {
    let full_speed = fixed(3)
    let half_speed = full_speed / fixed(2)
    let two_steps = half_speed + half_speed
    print(floor(two_steps))
  }
}
← All symbols