/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program 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 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program 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.
*/

#ifndef _POLYMAKE_RATIONAL_H
#define _POLYMAKE_RATIONAL_H "$Project: polymake $$Id: Rational.h,v 1.32 2004/06/22 16:22:44 gawrilow Exp $"

#if defined(__GNUC__) && __GNUC_MINOR__<3 && !defined(__APPLE__) && !defined(__COMO__)
#pragma interface
#endif

#include_next <Rational.h>
#ifndef _POLYMAKE_OPERATIONS_BASIC_DEFS_H
#  include <operations_basic_defs.h>
#endif
#ifndef _POLYMAKE_COMPARATORS_BASIC_DEFS_H
#  include <comparators_basic_defs.h>
#endif
#ifndef _POLYMAKE_CONVERTERS_BASIC_DEFS_H
#  include <converters_basic_defs.h>
#endif

namespace pm {

template <>
struct type_traits<Rational> {
   static const bool
      is_default_constructible=true,
      is_copy_constructible=true,
      is_assignable=true;
};

inline cmp_value sign(const Rational& a) {
   return sign(mpq_numref(a.get_rep())->_mp_size);
}
inline Rational& inv_sign(Rational& a) { return a.negate(); }

namespace operations {

template <> struct arith_tag<Rational> : arith_tag<Integer> {
   typedef Rational unsigned_type;
};

template <>
struct cmp_scalar<Rational,Rational> {
   typedef Rational first_argument_type;
   typedef Rational second_argument_type;
   typedef cmp_value result_type;

   result_type operator() (const Rational& a, const Rational& b) const {
      return sign(a.compare(b));
   }
   template <typename Iterator2>
   result_type operator() (partial_left, const Rational& a, const Iterator2&) const {
      return cmp_value(sign(a));
   }
   template <typename Iterator1>
   result_type operator() (partial_right, const Iterator1&, const Rational& b) const {
      return cmp_value(-sign(b));
   }
};
} // end namespace operations

template <>
struct conv<Rational, std::string> {
   typedef Rational argument_type;
   typedef std::string result_type;
   result_type operator() (const Rational& a) const { return a.to_string(); }
};

} // end namespace pm

namespace polymake {
   using pm::sign;
   using pm::inv_sign;
}

#endif // _POLYMAKE_RATIONAL_H

// Local Variables:
// mode:C++
// End:
