tur/bits
stdlib/bits.tur
bitwise operations not expressible as arithmetic in Turmeric.
Since: Phase B1
defn
bit-shr
(bit-shr [x :int n :int] :int)
logical (unsigned) right shift of x by n bits.
Parameters
| x | value to shift | |
| n | number of bit positions to shift right |
Returns
x shifted right by n bits (unsigned/logical shift; 0-fills high bits).
Example
(bit-shr -1 1) ; => 9223372036854775807 (fills with 0, not sign bit)
Since: Phase B1
defn
float->bits
(float->bits [x :float] :int)
reinterpret a float's IEEE-754 bit pattern as an :int.
Parameters
| x | the float whose bit pattern is wanted |
Returns
The 64 bits of x, as an :int.
Example
(bits->float (float->bits 1.5)) ; => 1.5
Since: 2026-08-29
defn
bits->float
(bits->float [b :int] :float)
reinterpret an :int's bit pattern as a float.
Parameters
| b | the 64 bits to read as a float |
Returns
The float those bits denote.
Example
(bits->float (float->bits 2.25)) ; => 2.25
Since: 2026-08-29
defn
println-float
(println-float [x :float decimals :int] :nil)
print a float with the specified number of decimal places.
Parameters
| x | floating-point value to print | |
| decimals | number of decimal places (clamped to 0--17) |
Returns
:nil
Example
(println-float 3.14159 6) ; prints "3.141590"
Since: Phase B1