diff --git a/Makefile.am b/Makefile.am index 9e9b9196..aba8a38d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -210,6 +210,7 @@ UTIL_FILES = \ range.ipp \ rational.cpp \ rational.hpp \ + rational.ipp \ ray.cpp \ ray.hpp \ region.cpp \ diff --git a/rational.cpp b/rational.cpp index 771b2d43..b64ff473 100644 --- a/rational.cpp +++ b/rational.cpp @@ -160,13 +160,6 @@ rational::operator/ (const T rhs) const } -//----------------------------------------------------------------------------- -template -rational -util::operator/ (T lhs, rational rhs) { - return rhs.inverse () * lhs; -} - //----------------------------------------------------------------------------- template struct util::rational; template struct util::rational< int32_t>; diff --git a/rational.hpp b/rational.hpp index b85b12ff..332a0908 100644 --- a/rational.hpp +++ b/rational.hpp @@ -51,8 +51,15 @@ namespace util { T d; }; - template - rational operator/ (T, rational); + template + rational::type> + operator/ (U, rational); + + template + rational::type> + operator* (U, rational); } +#include "rational.ipp" + #endif diff --git a/rational.ipp b/rational.ipp new file mode 100644 index 00000000..7412af26 --- /dev/null +++ b/rational.ipp @@ -0,0 +1,38 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright 2015 Danny Robson + */ + +#ifdef __UTIL_RATIONAL_IPP +#error +#endif +#define __UTIL_RATIONAL_IPP + + +//----------------------------------------------------------------------------- +template +util::rational::type> +util::operator/ (U lhs, rational rhs) +{ + return rhs.inverse () * lhs; +} + + +//----------------------------------------------------------------------------- +template +util::rational::type> +util::operator* (U lhs, rational rhs) +{ + return rhs * lhs; +}