`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>
829 B
829 B
| id | name | category | kind | tokens | sig | tip | order |
|---|---|---|---|---|---|---|---|
| fn-float | float | builtins | builtin | float double | float(x) -> float / double(x) -> double | Convert any number to a float (or double). | 51 |
Converts an int, long, fixed, float or double to a float (or, with double(x), to a double). It is the one conversion that crosses from fixed-point to floating point: float(fixed(1)) / 4.0 is 0.25. A decimal literal converts exactly, so float(0.1) is the nearest float to 0.1, not the nearest Q16.16 value.
Parameters:
x— the number to convert
program Convert {
entry {
let half = fixed(1) / 2
print(float(half) * 3.0) # 1.5
print(double(7) / 2) # 3.5
}
}