diff --git a/doc/snippets/MagnumMath.cpp b/doc/snippets/MagnumMath.cpp index 5e2ca9b45..f9d3d9a80 100644 --- a/doc/snippets/MagnumMath.cpp +++ b/doc/snippets/MagnumMath.cpp @@ -877,6 +877,40 @@ Debug{} << Math::Vector3{a}; // prints {16968, 48552, 15993} /* [Half-usage-vector] */ } +{ +/* [unpack-template-explicit] */ +// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f +Float a = Math::unpack('\xFF'); + +// b = 1.0f +Float b = Math::unpack('\xFF'); +/* [unpack-template-explicit] */ +static_cast(a); +static_cast(b); +} + +{ +/* [unpack] */ +Float a = Math::unpack(8191); // 0.124987f +Float b = Math::unpack(8191); // 0.499969f +Float c = Math::unpack(8191u); // 0.499969f +Float d = Math::unpack(8191); // 1.0f +/* [unpack] */ +static_cast(a); +static_cast(b); +static_cast(c); +static_cast(d); +} + +{ +/* [pack] */ +auto a = Math::pack(0.5f); // 32767 +auto b = Math::pack(0.5f); // 8191 +/* [pack] */ +static_cast(a); +static_cast(b); +} + { Range1D range, a, b; constexpr UnsignedInt dimensions = 1; diff --git a/src/Magnum/Math/Packing.h b/src/Magnum/Math/Packing.h index fc1d788c1..c12f77f70 100644 --- a/src/Magnum/Math/Packing.h +++ b/src/Magnum/Math/Packing.h @@ -57,13 +57,7 @@ value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$ To ensure the integral type is correctly detected when using literals, this function should be called with both template parameters explicit, e.g.: @attention - @code{.cpp} - // Literal type is (signed) char, but we assumed unsigned char, a != 1.0f - Float a = Math::unpack('\xFF'); - - // b = 1.0f - Float b = Math::unpack('\xFF'); - @endcode + @snippet MagnumMath.cpp unpack-template-explicit @see @ref pack() */ @@ -75,12 +69,7 @@ template inline FloatingPoint unpack(const Alternative to the above with ability to specify how many bits of the integral representation to use. Example usage: -@code{.cpp} -Float a = Math::unpack(8191); // 0.124987f -Float b = Math::unpack(8191); // 0.499969f -Float b = Math::unpack(8191u); // 0.499969f -Float b = Math::unpack(8191); // 1.0f -@endcode +@snippet MagnumMath.cpp unpack */ template inline FloatingPoint unpack(const Integral& value); #else @@ -124,14 +113,14 @@ template(0.5f); // 32767 -auto b = Math::pack(0.5f); // 8191 -@endcode +@snippet MagnumMath.cpp pack */ #ifdef DOXYGEN_GENERATING_OUTPUT template inline Integral pack(FloatingPoint value);