sofab.float_arrays module¶
The static helper layer: bit-pattern equality of float arrays.
A float array field is omitted on the wire iff its value equals its default
(MESSAGE_SPEC §2), and floats round-trip bit-for-bit (CORELIB_PLAN §4.6). The
comparison that decides the omission therefore has to be a comparison of bit
patterns, not IEEE ==: the array [-0.0, 1.5] is not the default
[0.0, 1.5], and dropping it would lose the sign of the zero.
The helper is the same for every schema – its schema dependence is only the two sequences it is handed – so it lives here, written once, and generated code calls it with the field’s list and a constant default list.
float_array_bits_equal() returns True iff the lengths are equal and,
at every index, the 64-bit IEEE-754 pattern of the held double is identical:
+0.0and-0.0are different;a NaN equals another NaN only when the patterns match, payload included;
there is no IEEE
==anywhere, sonanis equal to itself.
Python holds every float, fp32 fields included, as a double, so the pattern
compared is that of the held double for both element widths. (The fp32
signaling-NaN raw-bytes path of CORELIB_PLAN §6.5 is separate and untouched.)
An int element is compared as the double it converts to, which is what the
encoder would write for it; one outside the double range is not a
float at all and raises struct.error.
It works under both engines: it is plain Python and never touches the codec.
- sofab.float_arrays.float_array_bits_equal(a, b)[source]¶
Whether
aandbhave the same length and identical double bit patterns.- Parameters:
a (Sequence[float])
b (Sequence[float])
- Return type:
bool
- class sofab.float_arrays.FloatArrayDefault(values)[source]¶
Bases:
objectA float array field’s declared default, compared bit for bit.
Built once per field;
matches()is then the omission test generated code runs on every serialize.matches(a)is true iffahas the default’s length and every element matches (see the element rule above):+0.0and-0.0differ, a NaN matches only the identical NaN, anintmatches the double it equals. Any sequence is accepted; alisttakes the fast path.valuesis the default, as a tuple of floats.- Parameters:
values (tuple[float, ...])
- values: tuple[float, ...]¶
- matches: Callable[[Sequence[float]], bool]¶