| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.101.0/library/ieee_754/NOTES.md |
This file is part of Logtalk https://logtalk.org/ SPDX-FileCopyrightText: 1998-2026 Paulo Moura <pmoura@logtalk.org> SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
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:
half, single, or doublebig or littlecanonical 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:
not_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