Table of Contents

Class FloatBits

Namespace
sofab
Assembly
SofaBuffers.dll

Bit-pattern equality for fp32 / fp64 arrays — the comparison a generated encoder makes between a field and its declared default.

public static class FloatBits
Inheritance
FloatBits
Inherited Members

Remarks

A field is omitted from the wire iff it equals its default (MESSAGE_SPEC §2), and floats round-trip bit for bit (CORELIB_PLAN §4.6). "Equals" is therefore a comparison of IEEE-754 bit patterns, not the IEEE == that SequenceEqual<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) performs: under ==, -0.0 equals +0.0 (so a -0.0 element would be dropped as a default) and a NaN equals nothing, itself included. Here +0.0 and -0.0 differ, and a NaN equals another NaN exactly when every bit, payload included, is the same.

The code has the same shape for every schema — the element type is the only thing that varies — so it lives in the corelib rather than being emitted into every generated source tree (generator#636, #587). Both overloads take ReadOnlySpan<T>, so a generated call passes the field array and a constant default array alike (arrays convert implicitly). Neither allocates or mutates.

Methods

BitsEqual(ReadOnlySpan<double>, ReadOnlySpan<double>)

True iff both spans have the same length and every element pair has the same 64-bit IEEE-754 bit pattern.

public static bool BitsEqual(ReadOnlySpan<double> a, ReadOnlySpan<double> b)

Parameters

a ReadOnlySpan<double>

The first array (the field).

b ReadOnlySpan<double>

The second array (the default).

Returns

bool

Whether the two arrays are bit-for-bit identical.

BitsEqual(ReadOnlySpan<float>, ReadOnlySpan<float>)

True iff both spans have the same length and every element pair has the same 32-bit IEEE-754 bit pattern.

public static bool BitsEqual(ReadOnlySpan<float> a, ReadOnlySpan<float> b)

Parameters

a ReadOnlySpan<float>

The first array (the field).

b ReadOnlySpan<float>

The second array (the default).

Returns

bool

Whether the two arrays are bit-for-bit identical.