From 4b253a57f78071bca7d3c0f50346b9d00480702e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 21 Sep 2015 16:35:31 +1000 Subject: [PATCH] rational: add operator int --- rational.cpp | 8 ++++++++ rational.hpp | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rational.cpp b/rational.cpp index 9fe513d2..771b2d43 100644 --- a/rational.cpp +++ b/rational.cpp @@ -96,6 +96,14 @@ rational::operator double (void) const } +//----------------------------------------------------------------------------- +template +rational::operator int (void) const +{ + return static_cast (n / d); +} + + /////////////////////////////////////////////////////////////////////////////// template rational diff --git a/rational.hpp b/rational.hpp index 7c30b2cf..b85b12ff 100644 --- a/rational.hpp +++ b/rational.hpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2014 Danny Robson + * Copyright 2014-2015 Danny Robson */ #ifndef __UTIL_RATIONAL_HPP @@ -35,6 +35,7 @@ namespace util { explicit operator float (void) const; explicit operator double (void) const; + explicit operator int (void) const; rational reduced (void) const;