diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 944da0a00..1b05ac225 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -133,6 +133,7 @@ endif() # Files shared between main library and math unit test library set(MagnumMath_SRCS Math/Color.cpp + Math/Half.cpp Math/Functions.cpp Math/Packing.cpp Math/instantiation.cpp) diff --git a/src/Magnum/Math/Half.cpp b/src/Magnum/Math/Half.cpp new file mode 100644 index 000000000..1d62fb0ed --- /dev/null +++ b/src/Magnum/Math/Half.cpp @@ -0,0 +1,41 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Magnum/Math/Half.h" + +#include +#include + +namespace Magnum { namespace Math { + +Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, Half value) { + std::ostringstream out; + /* Wikipedia says it's 3 or 4 decimal places: + https://en.wikipedia.org/wiki/Half-precision_floating-point_format */ + out << std::setprecision(4) << Float(value); + return debug << out.str(); +} + +}} diff --git a/src/Magnum/Math/Half.h b/src/Magnum/Math/Half.h index afb3cb70f..8f64edf2e 100644 --- a/src/Magnum/Math/Half.h +++ b/src/Magnum/Math/Half.h @@ -150,10 +150,16 @@ inline Half operator "" _h(long double value) { return Half(Float(value)); } } -/** @debugoperator{Half} */ -inline Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, Half value) { - return debug << Float(value); -} +/** +@debugoperator{Half} + +Prints the value with 4 significant digits. +@see @ref Corrade::Utility::Debug::operator<<(float), + @ref Corrade::Utility::Debug::operator<<(double), + @ref Corrade::Utility::Debug::operator<<(long double value) +@todoc remove `long double value` once doxygen can link to long double overloads properly +*/ +MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, Half value); }} diff --git a/src/Magnum/Math/Test/HalfTest.cpp b/src/Magnum/Math/Test/HalfTest.cpp index 951b2fc2c..e49f70304 100644 --- a/src/Magnum/Math/Test/HalfTest.cpp +++ b/src/Magnum/Math/Test/HalfTest.cpp @@ -609,12 +609,12 @@ void HalfTest::debug() { std::ostringstream out; - Debug{&out} << -3.64_h << Half{Constants::inf()} + Debug{&out} << -36.41_h << Half{Constants::inf()} << Math::Vector3{3.14159_h, -1.4142_h, 1.618_h}; #ifdef _MSC_VER - CORRADE_COMPARE(out.str(), "-3.64063 inf Vector(3.14063, -1.41406, 1.61816)\n"); + CORRADE_COMPARE(out.str(), "-36.41 inf Vector(3.141, -1.414, 1.618)\n"); #else - CORRADE_COMPARE(out.str(), "-3.64062 inf Vector(3.14062, -1.41406, 1.61816)\n"); + CORRADE_COMPARE(out.str(), "-36.41 inf Vector(3.141, -1.414, 1.618)\n"); #endif }