SofaBuffers C/C++ 0.12.0
API Documentation
Loading...
Searching...
No Matches
floats.hpp File Reference

SofaBuffers C++ - bit-pattern equality for float arrays. More...

#include <cstddef>
#include <cstring>
#include <iterator>
#include <type_traits>
Include dependency graph for floats.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  sofab
 

Functions

template<typename T >
bool sofab::bitsEqual (const T *a, std::size_t na, const T *b, std::size_t nb) noexcept
 True iff both float arrays have the same length and the same bit pattern at every index.
 
template<typename A , typename B >
bool sofab::bitsEqual (const A &a, const B &b) noexcept
 Container form of bitsEqual: anything contiguous that std::data / std::size accept and that holds float or double.
 

Detailed Description

SofaBuffers C++ - bit-pattern equality for float arrays.

Part of the static-helper layer (see seq.hpp): code whose shape is the same for every schema, so it lives here once instead of being emitted into every generated header.

A generated encoder omits a field iff its value equals its declared default (MESSAGE_SPEC §2), and floats round-trip bit for bit (CORELIB_PLAN §4.6). "Equals" for a float array is therefore a comparison of IEEE-754 bit patterns, never of values: -0.0 differs from +0.0, and a NaN equals another NaN only when every bit, payload included, is identical. The container operator== (an elementwise IEEE ==) gets both wrong and would drop a -0.0 element that has to reach the wire.

The helper is header-only, inline and stateless: a translation unit that does not call it pays 0 bytes, and the C library is untouched.

Include sofab/sofab.hpp; it pulls this in. Including this header alone works too and means the same thing.

SPDX-License-Identifier: MIT

Definition in file floats.hpp.