Databases
sql.ieee
import sql.ieee
Zuri
sqldoes not re-export this module, so it is reached only by importing it directly.
Decodes IEEE 754 floating-point numbers from the bits a server sends.
PostgreSQL and MySQL both send a real or double precision value in
binary as its IEEE 754 bit pattern, in big-endian order for PostgreSQL
and little-endian order for MySQL. The adapters read the bits as
integers in the right order and pass them here, so the numbers come out
the same either way.
import sql.ieee { double_of, single_of }
echo double_of(0x3ff80000, 0)
echo single_of(0xc0200000)
ZuriEvery bit pattern is decoded, including both signed zeros, the subnormal numbers, both infinities and NaN, and the result is exactly the number that the pattern encodes.
Functions
double_of()
sql.ieee.double_of(high: number, low: number) -> number
ZuriThe double whose bit pattern is high followed by low.
The significand is at most 53 bits, which a double holds exactly, and scaling it by a power of two is also exact, so building a value from its fields gives exactly the number, not an approximation.
Parameters
high(number) — The upper 32 bits, from 0 to 4294967295: the sign, the exponent and the top 20 bits of the fraction.low(number) — The lower 32 bits of the fraction, from 0 to 4294967295.
Returns number
single_of()
sql.ieee.single_of(bits: number) -> number
ZuriThe single precision number whose bit pattern is bits, as a double,
which holds every single precision value exactly.
Parameters
bits(number) — The 32 bits, from 0 to 4294967295.
Returns number
2026, Richard Ore and Zuri contributors