`float` (32-bit) and `double` (64-bit) with + - * / %, comparisons and unary minus. Decimal literals take their type from context and stay `fixed` elsewhere; int and long promote implicitly (LUDIC_WARN_FLOAT_PROMOTE=1 lists every promotion). float(), double(), int(), long() and fixed() convert; floats(n)/doubles(n) buffers; float fields, globals, constants and parameters; Math.* computes in float for float arguments; string/print write the shortest round-tripping decimal; float_bits/float_from_bits expose the bits. @deterministic code may not use floats. The f_* runtime helpers stay as they are. Editors know the new type words; the JetBrains plugin is 1.5.0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 KiB
1 KiB
| id | name | category | kind | tokens | sig | tip | order |
|---|---|---|---|---|---|---|---|
| fn-fixed | fixed | builtins | builtin | fixed | fixed(x) -> fixed | Convert an int (or a float) into a Q16.16 fixed-point value. | 50 |
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:
x— the integer (or float) to convert
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))
}
}