refactor(lang): rename builtins flr->floor and fx->fixed
De-abbreviate the two bare fixed-point conversion builtins:
flr(f) -> int -> floor(f) -> int (fixed -> int, flooring)
fx(i) -> fixed -> fixed(i) -> fixed (int -> fixed; mirrors how the
stringify builtin is `string`)
Updates the compiler dispatch, all call sites, the grammars/LSP/JetBrains
tokens, and the docs (fn-flr -> fn-floor, fn-fx -> fn-fixed). Reseeded;
C-free fixpoint holds; all suites green (45/24/29); site + check.py OK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
effb3f637f
commit
2e0047514b
19 changed files with 80 additions and 80 deletions
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
id: fn-fx
|
||||
name: fx
|
||||
id: fn-fixed
|
||||
name: fixed
|
||||
category: builtins
|
||||
kind: builtin
|
||||
tokens: fx
|
||||
sig: fx(n) -> fixed
|
||||
tokens: fixed
|
||||
sig: fixed(n) -> fixed
|
||||
tip: Lift an integer into a Q16.16 fixed-point value.
|
||||
order: 50
|
||||
---
|
||||
|
||||
Converts an integer into a <code>fixed</code> value (Ludic's Q16.16 fixed-point type), so it can take part in fractional arithmetic. Ludic has no floating point; <code>fixed</code> is how you carry sub-pixel precision for smooth movement and physics-like accumulation. Use <code>fx</code> when you need to combine an <code>int</code> with fixed-point values or divide to get a fraction — for example <code>fx(1) / fx(4)</code> is <code>0.25</code>. Convert back to a whole number for drawing with <code>flr</code>.
|
||||
Converts an integer into a <code>fixed</code> value (Ludic's Q16.16 fixed-point type), so it can take part in fractional arithmetic. Ludic has no floating point; <code>fixed</code> is how you carry sub-pixel precision for smooth movement and physics-like accumulation. Use <code>fixed</code> when you need to combine an <code>int</code> with fixed-point values or divide to get a fraction — for example <code>fixed(1) / fixed(4)</code> is <code>0.25</code>. Convert back to a whole number for drawing with <code>flr</code>.
|
||||
|
||||
Parameters:
|
||||
- `n` — the integer to lift into fixed-point
|
||||
|
|
@ -17,10 +17,10 @@ Parameters:
|
|||
```ludic
|
||||
program SmoothAccumulate {
|
||||
handler ComputeStep phase Start {
|
||||
let full_speed = fx(3)
|
||||
let half_speed = full_speed / fx(2)
|
||||
let full_speed = fixed(3)
|
||||
let half_speed = full_speed / fixed(2)
|
||||
let two_steps = half_speed + half_speed
|
||||
print(flr(two_steps))
|
||||
print(floor(two_steps))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
id: fn-flr
|
||||
name: flr
|
||||
id: fn-floor
|
||||
name: floor
|
||||
category: builtins
|
||||
kind: builtin
|
||||
tokens: flr
|
||||
sig: flr(x) -> int
|
||||
tokens: floor
|
||||
sig: floor(x) -> int
|
||||
tip: Floor a fixed-point value down to the nearest integer.
|
||||
order: 50
|
||||
---
|
||||
|
||||
Converts a <code>fixed</code> (Q16.16) value back to an <code>int</code> by discarding the fractional part, rounding toward negative infinity. It is the counterpart to <code>fx</code>: you accumulate motion in fixed-point for sub-pixel smoothness, then <code>flr</code> the result to get the whole-pixel column or row to draw at. Because it floors rather than rounds, <code>flr(fx(3) / fx(2))</code> is <code>1</code>, not <code>2</code>. Use it wherever a fixed value must become an integer coordinate, count, or index.
|
||||
Converts a <code>fixed</code> (Q16.16) value back to an <code>int</code> by discarding the fractional part, rounding toward negative infinity. It is the counterpart to <code>fx</code>: you accumulate motion in fixed-point for sub-pixel smoothness, then <code>floor</code> the result to get the whole-pixel column or row to draw at. Because it floors rather than rounds, <code>floor(fixed(3) / fixed(2))</code> is <code>1</code>, not <code>2</code>. Use it wherever a fixed value must become an integer coordinate, count, or index.
|
||||
|
||||
Parameters:
|
||||
- `x` — the fixed-point value to floor
|
||||
|
|
@ -20,8 +20,8 @@ program FixedToPixels {
|
|||
|
||||
handler DrawWorld phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
let smooth_column = fx(5) + fx(1) / fx(2)
|
||||
let pixel_x = flr(smooth_column) * TILE_SIZE
|
||||
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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue