Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1092 git-svn-id: svn://10.65.10.50/trunk@16352 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			136 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #ifndef __FRACTION_H
 | |
| #define __FRACTION_H
 | |
| 
 | |
| #ifndef __REAL_H
 | |
| #include <real.h>
 | |
| #endif
 | |
| 
 | |
| // @doc EXTERNAL
 | |
| 
 | |
| // @class fraction (per GREENLEAF) | Classe per la gestione dei numeri frazionari
 | |
| //
 | |
| // @base public | TObject
 | |
| 
 | |
| class fraction : public TObject
 | |
| 
 | |
| // @author:(INTERNAL) Alex
 | |
| {
 | |
|   // @access:(INTERNAL) Private Member
 | |
|   // @cmember:(INTERNAL) Numero fractione
 | |
|   friend fraction operator *(const fraction & a, __int64 b);
 | |
| 	friend fraction operator /(const fraction & a, __int64 b);
 | |
| 	friend fraction operator /(__int64 a, const fraction & b);
 | |
|   
 | |
|   __int64 _num;
 | |
| 	__int64 _den;
 | |
| 
 | |
|   // @access Protected Member
 | |
| protected:
 | |
| 	// @cmember Duplica il numero frazionario (vedi classe <c TObject>)
 | |
|   virtual TObject* dup() const;
 | |
| 	// @cmember assegna il numero frazionario (vedi classe <c TObject>)
 | |
| 	void simplify();
 | |
| 
 | |
|   // @cmember Crea una frazione a partire da una stringa avente la VIRGOLA come separatore dei decimali!
 | |
| 	void build_fraction(const char* stringa);
 | |
|   
 | |
| 	// @access Public Member
 | |
| public:
 | |
|   // @cmember Controlla se si tratta di un frazione uguale 0 (TRUE se 0)
 | |
|   bool is_zero() const  { return _num == 0;}
 | |
|   // @cmember Controlla se si tratta di un frazione uguale 1 (TRUE se 1)
 | |
|   bool is_one() const  { return _num == _den;}
 | |
|   // @cmember Ritorna il segno del fraction
 | |
|   int sign() const ;
 | |
|   // @cmember Trasforma il fraction in intero (operator int era troppo pericoloso)
 | |
|   __int64 integer() const { return _num / _den;}
 | |
| 
 | |
|   // @cmember Assegna una frazione
 | |
|   fraction& operator =(const fraction& b);
 | |
|   // @cmember Assegna una frazione
 | |
|   fraction& operator =(const real& b) { build_fraction(b.stringa()); return *this; }
 | |
|   // @cmember Aggiunge ad un frazione il valore passato
 | |
|   fraction& operator +=(const fraction& b);
 | |
|   // @cmember Sottrae ad un frazione il valore passato
 | |
|   fraction& operator -=(const fraction& b);
 | |
|   // @cmember Moltiplica un fractione per il valore passato (passato per indirizzo)
 | |
|   fraction& operator *=(const fraction& b);
 | |
|   // @cmember Divide un fractione per il valore passato (passato per indirizzo)
 | |
|   fraction& operator /=(const fraction& b);
 | |
|   // @cmember Ritorna la negazione di un frazione (TRUE se 0, altrimenti FALSE)
 | |
|   bool operator !() const { return is_zero(); }
 | |
|   // @cmember Ritorna il risultato della differenza tra due frazioni
 | |
|   fraction operator -() const;
 | |
| 
 | |
|   // @cmember Trasforma il fraction in real
 | |
|   operator real() const;
 | |
| 
 | |
|   // @cmember Costruttore
 | |
|   fraction();
 | |
|   // @cmember Costruttore
 | |
|   fraction(const real &num, const real& den);
 | |
|   fraction(__int64 num, __int64 den = 1) : _num(num), _den(den) { simplify(); }
 | |
|   // @cmember Costruttore
 | |
|   fraction(const fraction& b) ;
 | |
|   // @cmember Costruttore
 | |
|   fraction(const char* stringa) { build_fraction(stringa); }
 | |
|   // @cmember Distruttore
 | |
|   virtual ~fraction() { }
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Math operators
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| fraction operator +(const fraction& a, const fraction& b) ;
 | |
| fraction operator -(const fraction& a, const fraction& b) ;
 | |
| fraction operator *(const fraction& a, const fraction& b) ;
 | |
| fraction operator /(const fraction& a, const fraction& b) ;
 | |
| 
 | |
| bool operator <(const fraction& a, const fraction& b) ;
 | |
| bool operator >(const fraction& a, const fraction& b) ;
 | |
| bool operator <=(const fraction& a, const fraction& b) ;
 | |
| bool operator >=(const fraction& a, const fraction& b) ;
 | |
| bool operator ==(const fraction& a, const fraction& b) ;
 | |
| bool operator !=(const fraction& a, const fraction& b) ;
 | |
| 
 | |
| #if 0
 | |
| // Valanga apparentemente inutile: aggiungere solo cio' che serve veramente!
 | |
| inline fraction operator +(const real& a, const fraction& b) { return ::operator +((fraction)a, b);}
 | |
| inline fraction operator +(const fraction& a, const real& b) { return ::operator +(b, a);}
 | |
| inline fraction operator +(const fraction& a, __int64 b) { return ::operator +(a, (fraction)b);}
 | |
| inline fraction operator +(__int64 a, const fraction& b) { return ::operator +(b, a);}
 | |
| inline fraction operator -(const real& a, const fraction& b) { return ::operator -((fraction)a, b);}
 | |
| inline fraction operator -(const fraction& a, const real& b) { return ::operator -(a, (fraction)b);}
 | |
| inline fraction operator -(const fraction& a, __int64 b) { return ::operator -(a, (fraction)b);}
 | |
| inline fraction operator -(__int64 a, const fraction& b) { return ::operator -((fraction)a, b);}
 | |
| inline fraction operator *(const real& a, const fraction& b) { return ::operator *((fraction)a, b);}
 | |
| inline fraction operator *(const fraction& a, const real& b) { return ::operator *(b, a);}
 | |
| fraction operator *(const fraction& a, __int64 b);
 | |
| inline fraction operator *(__int64 a, const fraction& b) { return ::operator *(b, a);}
 | |
| inline fraction operator /(const real& a, const fraction& b) { return ::operator /((fraction)a, b);}
 | |
| inline fraction operator /(const fraction& a, const real& b) { return ::operator /(a, (fraction)b);}
 | |
| fraction operator /(const fraction& a, __int64 b);
 | |
| fraction operator /(__int64 a, const fraction& b);
 | |
| 
 | |
| inline bool operator <(const real& a, const fraction& b) { return ::operator < (a, (real)b);}
 | |
| inline bool operator <(const fraction& a, const real& b) { return ::operator <((real) a, b);}
 | |
| inline bool operator >(const real& a, const fraction& b)  { return ::operator > (a, (real)b);};
 | |
| inline bool operator >(const fraction& a, const real& b) { return ::operator >((real) a, b);}
 | |
| inline bool operator <=(const real& a, const fraction& b) { return ::operator <= (a, (real)b);}
 | |
| inline bool operator <=(const fraction& a, const real& b) { return operator <=((real) a, b);}
 | |
| inline bool operator >=(const real& a, const fraction& b) { return operator >=(a, (real) b);}
 | |
| inline bool operator >=(const fraction& a, const real& b) { return operator >=((real) a, b);}
 | |
| inline bool operator ==(const real& a, const fraction& b) { return operator ==(a, (real) b);}
 | |
| inline bool operator ==(const fraction& a, const real& b) { return operator ==((real) a, b);}
 | |
| inline bool operator !=(const real& a, const fraction& b) { return operator !=(a, (real) b);}
 | |
| inline bool operator !=(const fraction& a, const real& b) { return operator !=((real) a, b);}
 | |
| 
 | |
| #endif
 | |
| 
 | |
| void swap(fraction& a, fraction& b) ;
 | |
| const fraction& fnc_min(const fraction& a, const fraction& b);
 | |
| const fraction& fnc_max(const fraction& a, const fraction& b);
 | |
| 
 | |
| #endif
 |