diff --git a/Makefile.am b/Makefile.am index c662b7ea..037a6623 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,6 +79,7 @@ UTIL_FILES = \ log.ipp \ maths.cpp \ maths.hpp \ + maths.ipp \ maths/matrix.cpp \ maths/matrix.hpp \ maths/polynomial.ipp\ diff --git a/maths.cpp b/maths.cpp index 4e7f422e..585f21a5 100644 --- a/maths.cpp +++ b/maths.cpp @@ -95,15 +95,6 @@ almost_equal (const double &a, const double &b) { return ieee_double::almost_equal (a, b); } -//----------------------------------------------------------------------------- -template -typename std::enable_if::value, T>::type -round_up (T value, T align) { - CHECK_HARD (align > 1); - return (value + align - 1) / align; -} - - //----------------------------------------------------------------------------- template T diff --git a/maths.hpp b/maths.hpp index 4ff39fc7..b831471c 100644 --- a/maths.hpp +++ b/maths.hpp @@ -40,9 +40,9 @@ double rootsquare (T a, T b) pure; -template -T -round_up (T value, T align) pure; +template +typename std::common_type::type +round_up (T value, U align) pure; template @@ -173,4 +173,7 @@ max (const T &a , const T &b , const Args &...args ) template int sign (T val); + +#include "maths.ipp" + #endif // __MATHS_HPP diff --git a/maths.ipp b/maths.ipp new file mode 100644 index 00000000..e1da6061 --- /dev/null +++ b/maths.ipp @@ -0,0 +1,36 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2014 Danny Robson + */ + +#ifndef __UTIL_MATHS_IPP +#define __UTIL_MATHS_IPP +#else +#error "Include only once" +#endif + +#include + +//----------------------------------------------------------------------------- +template +typename std::common_type::type +round_up (T value, U align) { + static_assert (std::is_integral::value, "round_up requires integral types"); + static_assert (std::is_integral::value, "round_up requires integral types"); + + return divup (value, align) * align; +}