Browse Source

Math: compile code snippets from Packing.h.

simd
Vladimír Vondruš 7 years ago
parent
commit
476dc5c3f5
  1. 34
      doc/snippets/MagnumMath.cpp
  2. 30
      src/Magnum/Math/Packing.h

34
doc/snippets/MagnumMath.cpp

@ -877,6 +877,40 @@ Debug{} << Math::Vector3<UnsignedShort>{a}; // prints {16968, 48552, 15993}
/* [Half-usage-vector] */ /* [Half-usage-vector] */
} }
{
/* [unpack-template-explicit] */
// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f
Float a = Math::unpack<Float>('\xFF');
// b = 1.0f
Float b = Math::unpack<Float, UnsignedByte>('\xFF');
/* [unpack-template-explicit] */
static_cast<void>(a);
static_cast<void>(b);
}
{
/* [unpack] */
Float a = Math::unpack<Float, UnsignedShort>(8191); // 0.124987f
Float b = Math::unpack<Float, UnsignedShort, 14>(8191); // 0.499969f
Float c = Math::unpack<Float, 14>(8191u); // 0.499969f
Float d = Math::unpack<Float, 14>(8191); // 1.0f
/* [unpack] */
static_cast<void>(a);
static_cast<void>(b);
static_cast<void>(c);
static_cast<void>(d);
}
{
/* [pack] */
auto a = Math::pack<UnsignedShort>(0.5f); // 32767
auto b = Math::pack<UnsignedShort, 14>(0.5f); // 8191
/* [pack] */
static_cast<void>(a);
static_cast<void>(b);
}
{ {
Range1D range, a, b; Range1D range, a, b;
constexpr UnsignedInt dimensions = 1; constexpr UnsignedInt dimensions = 1;

30
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 To ensure the integral type is correctly detected when using literals, this
function should be called with both template parameters explicit, e.g.: function should be called with both template parameters explicit, e.g.:
@attention @attention
@code{.cpp} @snippet MagnumMath.cpp unpack-template-explicit
// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f
Float a = Math::unpack<Float>('\xFF');
// b = 1.0f
Float b = Math::unpack<Float, UnsignedByte>('\xFF');
@endcode
@see @ref pack() @see @ref pack()
*/ */
@ -75,12 +69,7 @@ template<class FloatingPoint, class Integral> inline FloatingPoint unpack(const
Alternative to the above with ability to specify how many bits of the integral Alternative to the above with ability to specify how many bits of the integral
representation to use. Example usage: representation to use. Example usage:
@code{.cpp} @snippet MagnumMath.cpp unpack
Float a = Math::unpack<Float, UnsignedShort>(8191); // 0.124987f
Float b = Math::unpack<Float, UnsignedShort, 14>(8191); // 0.499969f
Float b = Math::unpack<Float, 14>(8191u); // 0.499969f
Float b = Math::unpack<Float, 14>(8191); // 1.0f
@endcode
*/ */
template<class FloatingPoint, class Integral, UnsignedInt bits> inline FloatingPoint unpack(const Integral& value); template<class FloatingPoint, class Integral, UnsignedInt bits> inline FloatingPoint unpack(const Integral& value);
#else #else
@ -124,14 +113,14 @@ template<class FloatingPoint, UnsignedInt bits, std::size_t size, class Integral
/** /**
@brief Pack floating-point value into an integer representation @brief Pack floating-point value into an integer representation
Converts floating-point value in range @f$ [0, 1] @f$ to full range of given Converts floating-point value in range @f$ [0, 1] @f$ to full range of
*unsigned* integral type or range @f$ [-1, 1] @f$ to full range of given *signed* given *unsigned* integral type or range @f$ [-1, 1] @f$ to full range of
integral type. given *signed* integral type.
@note For best precision, `FloatingPoint` type should be always larger that @note For best precision, `FloatingPoint` type should be always larger that
resulting `Integral` type (e.g. @ref Magnum::Float "Float" to resulting `Integral` type (e.g. @ref Magnum::Float "Float" to
@ref Magnum::Short "Short", @ref Magnum::Double "Double" to @ref Magnum::Int "Int" @ref Magnum::Short "Short", @ref Magnum::Double "Double" to
and similarly for vector types). @ref Magnum::Int "Int" and similarly for vector types).
@attention Return value for floating point numbers outside the normalized @attention Return value for floating point numbers outside the normalized
range is undefined. range is undefined.
@ -164,10 +153,7 @@ template<class Integral, std::size_t size, class FloatingPoint, UnsignedInt bits
Alternative to the above with ability to specify how many bits of the integral Alternative to the above with ability to specify how many bits of the integral
representation to use. Example usage: representation to use. Example usage:
@code{.cpp} @snippet MagnumMath.cpp pack
auto a = Math::pack<UnsignedShort>(0.5f); // 32767
auto b = Math::pack<UnsignedShort, 14>(0.5f); // 8191
@endcode
*/ */
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
template<class Integral, UnsignedInt bits, class FloatingPoint> inline Integral pack(FloatingPoint value); template<class Integral, UnsignedInt bits, class FloatingPoint> inline Integral pack(FloatingPoint value);

Loading…
Cancel
Save