User Tools

Site Tools


brain:verylong.h

verylong.h

#ifndef __SHAREWIZ_VERYLONG_H__
#define __SHAREWIZ_VERYLONG_H__
 
//#include <string>
 
// Very Long Integer Class
 
 
class Verylong
{
private:
	// Data Fields
	std::string vlstr;     // The string is stored in reverse order.
	int    vlsign;    // Sign of Verylong: +=>0; -=>1
 
	// Private member functions
	Verylong multdigit(int) const;
	Verylong mult10(int) const;
 
public:
	// Constructors and destructor
	Verylong(const std::string&);
	Verylong(int);
	Verylong(const Verylong &);
	~Verylong();
 
	// Conversion operators
	operator int() const;
	operator double() const;
	operator std::string () const;
 
	// Arithmetic operators and Relational operators
	const Verylong & operator = (const Verylong &);  // assignment operator
	Verylong operator - () const;     // negate  operator
	Verylong operator ++ ();          // prefix  increment operator
	Verylong operator ++ (int);       // postfix increment operator
	Verylong operator -- ();          // prefix  decrement operator
	Verylong operator -- (int);       // postfix decrement operator
 
	Verylong operator += (const Verylong &);
	Verylong operator -= (const Verylong &);
	Verylong operator *= (const Verylong &);
	Verylong operator /= (const Verylong &);
	Verylong operator %= (const Verylong &);
	Verylong operator ^= (const Verylong &);
 
	friend Verylong operator + (const Verylong &, const Verylong &);
	friend Verylong operator - (const Verylong &, const Verylong &);
	friend Verylong operator * (const Verylong &, const Verylong &);
	friend Verylong operator / (const Verylong &, const Verylong &);
	friend Verylong operator % (const Verylong &, const Verylong &);
	friend Verylong operator ^ (const Verylong &, const Verylong &);
 
	friend int operator == (const Verylong &, const Verylong &);
	friend int operator != (const Verylong &, const Verylong &);
	friend int operator <  (const Verylong &, const Verylong &);
	friend int operator <= (const Verylong &, const Verylong &);
	friend int operator >  (const Verylong &, const Verylong &);
	friend int operator >= (const Verylong &, const Verylong &);
 
	// Other functions
	friend Verylong abs(const Verylong &);
	friend Verylong sqrt(const Verylong &);
	friend Verylong pow(const Verylong &, const Verylong &);
	friend double div(const Verylong &, const Verylong &);
 
	// Class Data
	static const Verylong zero;
	static const Verylong one;
	static const Verylong two;
 
	// I/O stream functions
	friend std::ostream & operator << (std::ostream &, const Verylong &);
	friend std::istream & operator >> (std::istream &, Verylong &);
};
 
 
//template <> Verylong zero(Verylong) { return Verylong::zero; }
//template <> Verylong one(Verylong) { return Verylong::one; }
 
 
#endif
brain/verylong.h.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki