`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>
954 B
954 B
| id | name | category | kind | tokens | sig | tip | order |
|---|---|---|---|---|---|---|---|
| fn-float_bits | float_bits | builtins | builtin | float_bits float_from_bits double_bits double_from_bits | float_bits(x) -> int / float_from_bits(bits) -> float | A float's IEEE bit pattern as an int, and back. | 53 |
float_bits(x) returns the 32 bits of a float as an int, and float_from_bits(bits) reads them back. double_bits / double_from_bits do the same for a double with a long. Use them where a float has to travel as raw data: a file format, a network packet, or a words buffer shared with code that still stores bit patterns.
Parameters:
x— the float to encode (float_bits), or the bits to decode (float_from_bits)
program Bits {
entry {
print(float_bits(1.0)) # 1065353216 (0x3F800000)
print(float_from_bits(0x40000000)) # 2.0
}
}