// File: decimal.hpp // Description: Decimal class // Project: - // Version: 1.00 // Revision: A // Content: Simple decimal class for "Cobol like" numerical manipulations // // // Language: Zortech C++, ver. 3.0 // OS: MS-DOS // Date: 04.04.1997 // Author: Peter Fabo // Mail: fabo@fmph.uniba.sk // Phone: 00421 7 65429248 // // Imlementation Dependencies #ifndef __DECIMAL_HPP_ #define __DECIMAL_HPP_ #include #include #include #include #define DECIMAL_LENGHT 6 // Header data enum decimal_error { DECIMAL_OK, DECIMAL_OVERFLOW, DECIMAL_DIV0 }; class decimal { static long int decimalLenght; // lenght of decimal part static long int decimalMask; // 10^decimalLenght static long int decimalMask_2; // 10^(decimalLenght/2) -> for oper. * long int integerPart; long int decimalPart; int decimalPartLenght(); // internal function for calculating // lenght of dec. part, used for // printing '0' a.e. in 1.00001 etc // void setAccuracy(int); // not implemented // int accuracy; public: Decimal(double); // constructors Decimal(long int=0); Decimal(char *); Decimal& operator=(decimal &); Decimal& operator-(); Decimal& operator +=(decimal &a){ return (*this)+a; } Decimal& operator -=(decimal &a){ return (*this)-a; } Decimal& operator *=(decimal &a){ return (*this)*a; } Decimal& operator /=(decimal &a){ return (*this)/a; } friend Decimal operator +(decimal &, Decimal &); friend Decimal operator -(decimal &, Decimal &); friend Decimal operator *(decimal &, Decimal &); friend Decimal operator /(decimal &, Decimal &); friend ostream& operator <<(ostream &, Decimal &); friend istream& operator >>(istream &, Decimal &); // friend int operator < (decimal &, Decimal &); // not implemented // friend int operator > (decimal &, Decimal &); // friend int operator <= (decimal &, Decimal &); // friend int operator >= (decimal &, Decimal &); operator double (); }; #endif __DECIMAL_HPP_ // End of header data decimal.hpp