tur/bits
bitwise operations not expressible as arithmetic in Turmeric.
Logical shifts, bit extraction, popcount, and byte-swap helpers.
Since: Phase B1
bit-shr
(bit-shr [x :int n :int] :int)
logical (unsigned) right shift of x by n bits.
| x | value to shift | |
| n | number of bit positions to shift right |
x shifted right by n bits (unsigned/logical shift; 0-fills high bits).
(bit-shr -1 1) ; => 9223372036854775807 (fills with 0, not sign bit)
Since: Phase B1
float->bits
(float->bits [x :float] :int)
reinterpret a float's IEEE-754 bit pattern as an :int.
This is the WRITE half of the int64 carrier round-trip. A cons cell, a variadic rest list and a HAMT slot all hold their elements in an :int-typed word, so a float stored there travels as its bits, not as a number.
Not a conversion: (float->bits 1.5) is 4609434218613702656, not 1. Use int->float / float->int (stdlib/math.tur) when you want the NUMBER. :: between an int and a float kind used to pick between these two readings silently and is now a compile error -- see docs/archive/ascribe-int-to-float-expression-ambiguity.md.
| x | the float whose bit pattern is wanted |
The 64 bits of x, as an :int.
(bits->float (float->bits 1.5)) ; => 1.5
Since: 2026-08-29
bits->float
(bits->float [b :int] :float)
reinterpret an :int's bit pattern as a float.
The READ half of the carrier round-trip, and the inverse of float->bits. Reading a float back out of a cons cell or a variadic rest list is exactly this: (bits->float (list-head c)).
Not a conversion: (bits->float 1) is 5e-324, a denormal, not 1.0. A denormal contributes nothing to a sum, which is what made the old (:: <int expr> :float) spelling of this misread as a DROPPED term rather than a garbage one. Use int->float (stdlib/math.tur) for the number.
| b | the 64 bits to read as a float |
The float those bits denote.
(bits->float (float->bits 2.25)) ; => 2.25
Since: 2026-08-29
println-float
(println-float [x :float decimals :int] :nil)
print a float with the specified number of decimal places.
| x | floating-point value to print | |
| decimals | number of decimal places (clamped to 0--17) |
:nil
(println-float 3.14159 6) ; prints "3.141590"
Since: Phase B1