SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
Loading...
Searching...
No Matches
bits_equal.hpp File Reference

Bit-pattern equality for float arrays (sofab::bitsEqual). More...

#include <concepts>
#include <cstddef>
#include <cstring>
#include <initializer_list>
#include <ranges>
#include <span>
#include <type_traits>
Include dependency graph for bits_equal.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  sofab
 
namespace  sofab::detail
 Implementation details of the wire format; not part of the public API.
 

Concepts

concept  sofab::detail::FloatElement
 float or double, the two element types of an fp array.
 

Functions

template<FloatElement T>
bool sofab::detail::bitsEqualSpan (std::span< const T > a, std::span< const T > b) noexcept
 Length check, then one block compare of the object representation.
 
template<std::ranges::contiguous_range A, std::ranges::contiguous_range B>
requires std::ranges::sized_range<A> && std::ranges::sized_range<B> && detail::FloatElement<std::remove_cv_t<std::ranges::range_value_t<A>>> && std::same_as<std::remove_cv_t<std::ranges::range_value_t<A>>, std::remove_cv_t<std::ranges::range_value_t<B>>>
bool sofab::bitsEqual (const A &a, const B &b) noexcept
 True iff a and b have the same length and every element pair has the same IEEE-754 bit pattern.
 
template<detail::FloatElement T, std::ranges::contiguous_range A>
requires std::ranges::sized_range<A> && std::same_as<std::remove_cv_t<std::ranges::range_value_t<A>>, T>
bool sofab::bitsEqual (const A &a, std::initializer_list< T > b) noexcept
 Braced-list default: bitsEqual(field, {0.0f, 1.5f}).
 

Detailed Description

Bit-pattern equality for float arrays (sofab::bitsEqual).

A generated encoder omits a field iff its value equals its declared default (MESSAGE_SPEC §2), and CORELIB_PLAN §4.6 makes floats round-trip bit for bit. An IEEE == over the elements contradicts both: -0.0 == +0.0, so an array [-0.0, 1.5] would be taken for the default [0.0, 1.5] and its first element dropped, and NaN != NaN would write a default array that holds a NaN.

bitsEqual is the comparison the omission test needs: equal length and, at every index, an identical IEEE-754 bit pattern (32 bits for float, 64 for double). +0.0 and -0.0 differ; two NaNs are equal exactly when their bit patterns, payload included, are identical. No IEEE == is involved.

Schema-independent by construction: the element type is a template argument and the bound is the argument's own length, so generated code calls it instead of emitting a loop per field.

SPDX-License-Identifier: MIT

Definition in file bits_equal.hpp.