⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rational.h

📁 Gambit 是一个游戏库理论软件
💻 H
字号:
//// $Source: /home/gambit/CVS/gambit/sources/math/rational.h,v $// $Date: 2002/08/26 05:50:05 $// $Revision: 1.3 $//// DESCRIPTION;// Interface to a rational number class//// This file is part of Gambit// Modifications copyright (c) 2002, The Gambit Project//// The original copyright and license are included below.// This may look like C code, but it is really -*- C++ -*-/* Copyright (C) 1988 Free Software Foundation    written by Doug Lea (dl@rocky.oswego.edu)This file is part of the GNU C++ Library.  This library is freesoftware; you can redistribute it and/or modify it under the terms ofthe GNU Library General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at youroption) any later version.  This library is distributed in the hopethat it will be useful, but WITHOUT ANY WARRANTY; without even theimplied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE.  See the GNU Library General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, 675 Mass Ave, Cambridge, MA 02139, USA.*/#ifndef _Rational_h#ifdef __GNUG__#pragma interface#endif#define _Rational_h 1#include "math/integer.h"#include <math.h>class gInput;class gOutput;class gRational{protected:  gInteger          num;  gInteger          den;  void             normalize();public:                   gRational();                   gRational(double);                   gRational(int n);                   gRational(long n);                   gRational(int n, int d);                   gRational(long n, long d);                   gRational(long n, unsigned long d);                   gRational(unsigned long n, long d);                   gRational(unsigned long n, unsigned long d);                   gRational(const gInteger& n);                   gRational(const gInteger& n, const gInteger& d);                   gRational(const gRational&);                  ~gRational();  gRational &operator =  (const gRational& y);  friend int       operator == (const gRational& x, const gRational& y);  friend int       operator != (const gRational& x, const gRational& y);  friend int       operator <  (const gRational& x, const gRational& y);  friend int       operator <= (const gRational& x, const gRational& y);  friend int       operator >  (const gRational& x, const gRational& y);  friend int       operator >= (const gRational& x, const gRational& y);  friend gRational  operator +  (const gRational& x, const gRational& y);  friend gRational  operator -  (const gRational& x, const gRational& y);  friend gRational  operator *  (const gRational& x, const gRational& y);  friend gRational  operator /  (const gRational& x, const gRational& y);  void             operator += (const gRational& y);  void             operator -= (const gRational& y);  void             operator *= (const gRational& y);  void             operator /= (const gRational& y);#ifdef __GNUG__  friend gRational  operator <? (const gRational& x, const gRational& y); // min  friend gRational  operator >? (const gRational& x, const gRational& y); // max#endif  friend gRational  operator - (const gRational& x);// builtin gRational functions  void             negate();                      // x = -x  void             invert();                      // x = 1/x  friend int       sign(const gRational& x);             // -1, 0, or +1  friend gRational  abs(const gRational& x);              // absolute value  friend gRational  sqr(const gRational& x);              // square  friend gRational  pow(const gRational& x, long y);  friend gRational  pow(const gRational& x, const gInteger& y);  const gInteger&   numerator() const;  const gInteger&   denominator() const;// coercion & conversion                   operator double() const;  friend gInteger   floor(const gRational& x);  friend gInteger   ceil(const gRational& x);  friend gInteger   trunc(const gRational& x);  friend gInteger   round(const gRational& x);  friend gInput&    operator >> (gInput& s, gRational& y);  friend gOutput&   operator << (gOutput& s, const gRational& y);  int		   fits_in_float() const;  int		   fits_in_double() const;// procedural versions of operators  friend int       compare(const gRational& x, const gRational& y);  friend void      add(const gRational& x, const gRational& y, gRational& dest);  friend void      sub(const gRational& x, const gRational& y, gRational& dest);  friend void      mul(const gRational& x, const gRational& y, gRational& dest);  friend void      div(const gRational& x, const gRational& y, gRational& dest);// error detection  void    error(const char* msg) const;  int              OK() const;};gText ToText(const gRational &);gRational FromText(const gText &, gRational &);void gEpsilon(gRational &v, int i = 8);#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -