`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>
858 B
858 B
| id | name | category | kind | tokens | sig | tip | order |
|---|---|---|---|---|---|---|---|
| fn-int | int | builtins | builtin | int long | int(x) -> int / long(x) -> long | Convert a number to a whole number, truncating toward zero. | 52 |
Converts a float, double, fixed or long to an int (or, with long(x), to a long). Floating-point values truncate toward zero, as in C: int(2.9) is 2 and int(-2.9) is -2. A fixed value rounds down, like floor. For other rounding use Math.floor, Math.ceil or Math.round.
Parameters:
x— the number to convert
program Whole {
entry {
let pixels: float = 12.75
print(int(pixels)) # 12
print(long(pixels * 1000.0)) # 12750
}
}