From c67ada694cf6de9e92bd836c8e589e658667ba35 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 24 Dec 2006 16:08:49 +0100 Subject: [PATCH] explicit ctors for rational. --- flower/include/rational.hh | 7 ++++--- flower/rational.cc | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/flower/include/rational.hh b/flower/include/rational.hh index bc64465cfe..ac1a6d12fc 100644 --- a/flower/include/rational.hh +++ b/flower/include/rational.hh @@ -54,8 +54,9 @@ public: Initialize to 0. */ Rational (); - Rational (int, int); - Rational (double); + Rational (int); + explicit Rational (int, int); + explicit Rational (double); Rational (Rational const &r) { copy (r);} Rational &operator = (Rational const &r) { @@ -98,6 +99,6 @@ ostream & operator << (ostream &, Rational); #endif -const Rational infinity_rat = INT_MAX; +const Rational infinity_rat (INT_MAX); #endif // RATIONAL_HH diff --git a/flower/rational.cc b/flower/rational.cc index 150ace0359..748a869841 100644 --- a/flower/rational.cc +++ b/flower/rational.cc @@ -66,6 +66,17 @@ Rational::Rational (int n, int d) normalize (); } +Rational::Rational (int n) +{ + sign_ = ::sign (n); + num_ = ::abs (n); + den_ = 1; +} + + +/* + We can actually do a little better. See Knuth 4.5.2 + */ static inline int gcd (int a, int b) { -- 2.39.2