Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

digitlst.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *
00004 *   Copyright (C) 1997-1999, International Business Machines
00005 *   Corporation and others.  All Rights Reserved.
00006 *
00007 ********************************************************************************
00008 *
00009 * File DIGITLST.H
00010 *
00011 * Modification History:
00012 *
00013 *   Date        Name        Description
00014 *   02/25/97    aliu        Converted from java.
00015 *   03/21/97    clhuang     Updated per C++ implementation.
00016 *   04/15/97    aliu        Changed MAX_COUNT to DBL_DIG.  Changed Digit to char.
00017 *   09/09/97    aliu        Adapted for exponential notation support.
00018 *   08/02/98    stephen     Added nearest/even rounding
00019 *   06/29/99    stephen     Made LONG_DIGITS a macro to satisfy SUN compiler
00020 *   07/09/99    stephen     Removed kMaxCount (unused, for HP compiler)
00021 *******************************************************************************
00022 */
00023  
00024 #ifndef DIGITLST_H
00025 #define DIGITLST_H
00026  
00027 #include "unicode/utypes.h"
00028 #include <float.h>
00029 
00030 // Decimal digits in a 32-bit int
00031 //#define LONG_DIGITS 19 
00032 
00052 class U_COMMON_API DigitList { // Declare external to make compiler happy
00053 public:
00054     DigitList();
00055     ~DigitList();
00056 
00057     DigitList(const DigitList&); // copy constructor
00058 
00059     DigitList& operator=(const DigitList&);  // assignment operator
00060 
00064     UBool operator==(const DigitList& other) const;
00065 
00069     UBool operator!=(const DigitList& other) const { return !operator==(other); }
00070 
00078     void clear(void);
00079 
00084     inline void append(char digit);
00085 
00090     double getDouble(void);
00091 
00097     int32_t getLong(void);
00098 
00103     UBool fitsIntoLong(UBool ignoreNegativeZero);
00104 
00110     void set(double source, int32_t maximumDigits, UBool fixedPoint = TRUE);
00111 
00117     void set(int32_t source, int32_t maximumDigits = 0);
00118 
00122     UBool isZero(void) const;
00123 
00129     UBool isLONG_MIN(void) const;
00130 
00135     static const char kZero;
00136 
00137 private:
00138     enum {
00139         MAX_DIGITS = DBL_DIG,
00140         MAX_EXPONENT = DBL_DIG,
00141         DIGIT_PADDING = 3,
00142 
00143          // "+." + fDigits + "e" + fDecimalAt
00144         MAX_DEC_DIGITS = DBL_DIG + DIGIT_PADDING + MAX_EXPONENT
00145     };
00146 
00147 public:
00169     int32_t     fDecimalAt;
00170     int32_t     fCount;
00171     UBool       fIsPositive;
00172     char        *fDigits;
00173 
00174 private:
00175 
00176     /* One character before fDigits for the decimal*/
00177     char        fDecimalDigits[MAX_DEC_DIGITS + 1];
00178 
00179 //    static char LONG_MIN_REP[LONG_DIGITS];
00180 //    static const char LONG_MIN_REP[];
00181 //    static int32_t    LONG_MIN_REP_LENGTH;
00182 
00188     void round(int32_t maximumDigits);
00189 
00193     /*static void initializeLONG_MIN_REP(void);*/
00194 
00195     UBool shouldRoundUp(int32_t maximumDigits);
00196 
00205     static int32_t formatBase10(int32_t number, char *outputStr, int32_t outputLen);
00206 };
00207  
00208 // -------------------------------------
00209 // Appends the digit to the digit list if it's not out of scope.
00210 // Ignores the digit, otherwise.
00211 
00212 inline void
00213 DigitList::append(char digit)
00214 {
00215     // Ignore digits which exceed the precision we can represent
00216     if (fCount < MAX_DIGITS)
00217         fDigits[fCount++] = digit;
00218 }
00219 
00220 #endif // _DIGITLST
00221 //eof
00222 
00223 
00224 

Generated at Tue Dec 5 17:55:27 2000 for ICU by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000