| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.100.1/docs/handbook/_sources/libraries/ieee_754.rst.txt |
.. _library_ieee_754:
ieee_754
The ieee_754 library is a support package for parsing and generating
IEEE 754 floating-point encodings shared by binary interchange libraries
such as message_pack, avro, protobuf, cbor, and
wkt_wkb.
To load all entities in this library, load the loader.lgt file:
::
| ?- logtalk_load(ieee_754(loader)).
To test this library predicates, load the tester.lgt file:
::
| ?- logtalk_load(ieee_754(tester)).
The library provides two parameterized implementation objects:
::
ieee_754(Precision, ByteOrder, NaNRepresentation)
ieee_754_fields(Precision, ByteOrder)
with the following parameter values:
Precision: half, single, or doubleByteOrder: big or littleNaNRepresentation: canonical or payloads
The parameterization keeps format-specific policy out of the shared
core. Advanced callers can use ieee_754_fields to inspect exact
sign, exponent, mantissa, finite binary-rational decompositions, and NaN
payload bits without going through backend float values.The intended term representation is:
@infinity@negative_infinity@not_a_numbernot_a_number(Bytes)
The not_a_number(Bytes) representation is only intended to be
accepted and produced by objects configured with
NaNRepresentation = payloads.
Under the payloads policy, decoding a canonical quiet NaN should
still yield @not_a_number. Non-canonical NaN encodings should decode
to not_a_number(Bytes) using canonical byte order for the selected
precision.
The high-level ieee_754/3 object API deliberately abstracts away the
IEEE 754 quiet-versus-signaling NaN distinction. In canonical mode,
all NaN encodings decode to @not_a_number. In payloads mode, the
designated canonical quiet NaN encoding decodes to @not_a_number
while all other NaN encodings decode to not_a_number(Bytes) for
roundtrip preservation. Callers that need exact NaN inspection should
use ieee_754_fields/2 object API.
The high-level value API is defined in ieee_754_protocol.lgt and
consists of:
bytes(Bytes) or bits(Bits) into a value
term.bytes(Bytes) or
bits(Bits).
The low-level exact field API is defined in
ieee_754_fields_protocol.lgt and consists of:
bytes(Bytes) or bits(Bits) as
zero, subnormal, normal, infinity, or
not_a_number.(-1)^Sign * Significand * 2^Exponent terms.quiet or
signaling.The intended shared semantics are:
ieee_754_fields API works from exact encodings and therefore
does not depend on backend float decomposition behavior