OLD | NEW |
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 * | 3 * |
4 * Copyright (C) 1997-2013, International Business Machines | 4 * Copyright (C) 1997-2015, International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ****************************************************************************** | 7 ****************************************************************************** |
8 * | 8 * |
9 * File DIGITLST.H | 9 * File DIGITLST.H |
10 * | 10 * |
11 * Modification History: | 11 * Modification History: |
12 * | 12 * |
13 * Date Name Description | 13 * Date Name Description |
14 * 02/25/97 aliu Converted from java. | 14 * 02/25/97 aliu Converted from java. |
(...skipping 29 matching lines...) Expand all Loading... |
44 DIGIT_PADDING = 3, | 44 DIGIT_PADDING = 3, |
45 DEFAULT_DIGITS = 40, // Initial storage size, will grow as needed. | 45 DEFAULT_DIGITS = 40, // Initial storage size, will grow as needed. |
46 | 46 |
47 // "+." + fDigits + "e" + fDecimalAt | 47 // "+." + fDigits + "e" + fDecimalAt |
48 MAX_DEC_DIGITS = MAX_DIGITS + DIGIT_PADDING + MAX_EXPONENT | 48 MAX_DEC_DIGITS = MAX_DIGITS + DIGIT_PADDING + MAX_EXPONENT |
49 } EDigitListValues; | 49 } EDigitListValues; |
50 | 50 |
51 U_NAMESPACE_BEGIN | 51 U_NAMESPACE_BEGIN |
52 | 52 |
53 class CharString; | 53 class CharString; |
| 54 class DigitInterval; |
54 | 55 |
55 // Export an explicit template instantiation of the MaybeStackHeaderAndArray tha
t | 56 // Export an explicit template instantiation of the MaybeStackHeaderAndArray tha
t |
56 // is used as a data member of DigitList. | 57 // is used as a data member of DigitList. |
57 // | 58 // |
58 // MSVC requires this, even though it should not be necessary. | 59 // MSVC requires this, even though it should not be necessary. |
59 // No direct access to the MaybeStackHeaderAndArray leaks out of the i18n lib
rary. | 60 // No direct access to the MaybeStackHeaderAndArray leaks out of the i18n lib
rary. |
60 // | 61 // |
61 // Macintosh produces duplicate definition linker errors with the explicit te
mplate | 62 // Macintosh produces duplicate definition linker errors with the explicit te
mplate |
62 // instantiation. | 63 // instantiation. |
63 // | 64 // |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 /** Set to zero */ | 307 /** Set to zero */ |
307 void setToZero() {uprv_decNumberZero(fDecNumber);} | 308 void setToZero() {uprv_decNumberZero(fDecNumber);} |
308 | 309 |
309 /** get the number of digits in the decimal number */ | 310 /** get the number of digits in the decimal number */ |
310 int32_t digits() const {return fDecNumber->digits;} | 311 int32_t digits() const {return fDecNumber->digits;} |
311 | 312 |
312 /** | 313 /** |
313 * Round the number to the given number of digits. | 314 * Round the number to the given number of digits. |
314 * @param maximumDigits The maximum number of digits to be shown. | 315 * @param maximumDigits The maximum number of digits to be shown. |
315 * Upon return, count will be less than or equal to maximumDigits. | 316 * Upon return, count will be less than or equal to maximumDigits. |
| 317 * result is guaranteed to be trimmed. |
316 */ | 318 */ |
317 void round(int32_t maximumDigits); | 319 void round(int32_t maximumDigits); |
318 | 320 |
319 void roundFixedPoint(int32_t maximumFractionDigits); | 321 void roundFixedPoint(int32_t maximumFractionDigits); |
320 | 322 |
321 /** Ensure capacity for digits. Grow the storage if it is currently less th
an | 323 /** Ensure capacity for digits. Grow the storage if it is currently less th
an |
322 * the requested size. Capacity is not reduced if it is already great
er | 324 * the requested size. Capacity is not reduced if it is already great
er |
323 * than requested. | 325 * than requested. |
324 */ | 326 */ |
325 void ensureCapacity(int32_t requestedSize, UErrorCode &status); | 327 void ensureCapacity(int32_t requestedSize, UErrorCode &status); |
(...skipping 23 matching lines...) Expand all Loading... |
349 | 351 |
350 | 352 |
351 /** | 353 /** |
352 * Get the digit's value, as an integer from 0..9 inclusive. | 354 * Get the digit's value, as an integer from 0..9 inclusive. |
353 * Note that internally this value is a decNumberUnit, but ICU configures it
to be a uint8_t. | 355 * Note that internally this value is a decNumberUnit, but ICU configures it
to be a uint8_t. |
354 * @param i index of digit | 356 * @param i index of digit |
355 * @return value of that digit | 357 * @return value of that digit |
356 */ | 358 */ |
357 uint8_t getDigitValue(int32_t i); | 359 uint8_t getDigitValue(int32_t i); |
358 | 360 |
| 361 /** |
| 362 * Gets the upper bound exponent for this value. For 987, returns 3 |
| 363 * because 10^3 is the smallest power of 10 that is just greater than |
| 364 * 987. |
| 365 */ |
| 366 int32_t getUpperExponent() const; |
| 367 |
| 368 /** |
| 369 * Gets the lower bound exponent for this value. For 98.7, returns -1 |
| 370 * because the right most digit, is the 10^-1 place. |
| 371 */ |
| 372 int32_t getLowerExponent() const { return fDecNumber->exponent; } |
| 373 |
| 374 /** |
| 375 * Sets result to the smallest DigitInterval needed to display this |
| 376 * DigitList in fixed point form and returns result. |
| 377 */ |
| 378 DigitInterval& getSmallestInterval(DigitInterval &result) const; |
| 379 |
| 380 /** |
| 381 * Like getDigitValue, but the digit is identified by exponent. |
| 382 * For example, getDigitByExponent(7) returns the 10^7 place of this |
| 383 * DigitList. Unlike getDigitValue, there are no upper or lower bounds |
| 384 * for passed parameter. Instead, getDigitByExponent returns 0 if |
| 385 * the exponent falls outside the interval for this DigitList. |
| 386 */ |
| 387 uint8_t getDigitByExponent(int32_t exponent) const; |
| 388 |
| 389 /** |
| 390 * Appends the digits in this object to a CharString. |
| 391 * 3 is appended as (char) 3, not '3' |
| 392 */ |
| 393 void appendDigitsTo(CharString &str, UErrorCode &status) const; |
| 394 |
| 395 /** |
| 396 * Equivalent to roundFixedPoint(-digitExponent) except unlike |
| 397 * roundFixedPoint, this works for any digitExponent value. |
| 398 * If maxSigDigits is set then this instance is rounded to have no more |
| 399 * than maxSigDigits. The end result is guaranteed to be trimmed. |
| 400 */ |
| 401 void roundAtExponent(int32_t digitExponent, int32_t maxSigDigits=INT32_MAX); |
| 402 |
| 403 /** |
| 404 * Quantizes according to some amount and rounds according to the |
| 405 * context of this instance. Quantizing 3.233 with 0.05 gives 3.25. |
| 406 */ |
| 407 void quantize(const DigitList &amount, UErrorCode &status); |
| 408 |
| 409 /** |
| 410 * Like toScientific but only returns the exponent |
| 411 * leaving this instance unchanged. |
| 412 */ |
| 413 int32_t getScientificExponent( |
| 414 int32_t minIntDigitCount, int32_t exponentMultiplier) const; |
| 415 |
| 416 /** |
| 417 * Converts this instance to scientific notation. This instance |
| 418 * becomes the mantissa and the exponent is returned. |
| 419 * @param minIntDigitCount minimum integer digits in mantissa |
| 420 * Exponent is set so that the actual number of integer digits |
| 421 * in mantissa is as close to the minimum as possible. |
| 422 * @param exponentMultiplier The exponent is always a multiple of |
| 423 * This number. Usually 1, but set to 3 for engineering notation. |
| 424 * @return exponent |
| 425 */ |
| 426 int32_t toScientific( |
| 427 int32_t minIntDigitCount, int32_t exponentMultiplier); |
| 428 |
| 429 /** |
| 430 * Shifts decimal to the right. |
| 431 */ |
| 432 void shiftDecimalRight(int32_t numPlaces); |
359 | 433 |
360 private: | 434 private: |
361 /* | 435 /* |
362 * These data members are intentionally public and can be set directly. | 436 * These data members are intentionally public and can be set directly. |
363 *<P> | 437 *<P> |
364 * The value represented is given by placing the decimal point before | 438 * The value represented is given by placing the decimal point before |
365 * fDigits[fDecimalAt]. If fDecimalAt is < 0, then leading zeros between | 439 * fDigits[fDecimalAt]. If fDecimalAt is < 0, then leading zeros between |
366 * the decimal point and the first nonzero digit are implied. If fDecimalAt | 440 * the decimal point and the first nonzero digit are implied. If fDecimalAt |
367 * is > fCount, then trailing zeros between the fDigits[fCount-1] and the | 441 * is > fCount, then trailing zeros between the fDigits[fCount-1] and the |
368 * decimal point are implied. | 442 * decimal point are implied. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 487 |
414 public: | 488 public: |
415 | 489 |
416 #if U_OVERRIDE_CXX_ALLOCATION | 490 #if U_OVERRIDE_CXX_ALLOCATION |
417 using UMemory::operator new; | 491 using UMemory::operator new; |
418 using UMemory::operator delete; | 492 using UMemory::operator delete; |
419 #else | 493 #else |
420 static inline void * U_EXPORT2 operator new(size_t size) U_NO_THROW { return
::operator new(size); }; | 494 static inline void * U_EXPORT2 operator new(size_t size) U_NO_THROW { return
::operator new(size); }; |
421 static inline void U_EXPORT2 operator delete(void *ptr ) U_NO_THROW { ::ope
rator delete(ptr); }; | 495 static inline void U_EXPORT2 operator delete(void *ptr ) U_NO_THROW { ::ope
rator delete(ptr); }; |
422 #endif | 496 #endif |
| 497 static char U_EXPORT2 getStrtodDecimalSeparator(); |
423 | 498 |
424 /** | 499 /** |
425 * Placement new for stack usage | 500 * Placement new for stack usage |
426 * @internal | 501 * @internal |
427 */ | 502 */ |
428 static inline void * U_EXPORT2 operator new(size_t /*size*/, void * onStack,
EStackMode /*mode*/) U_NO_THROW { return onStack; } | 503 static inline void * U_EXPORT2 operator new(size_t /*size*/, void * onStack,
EStackMode /*mode*/) U_NO_THROW { return onStack; } |
429 | 504 |
430 /** | 505 /** |
431 * Placement delete for stack usage | 506 * Placement delete for stack usage |
432 * @internal | 507 * @internal |
(...skipping 14 matching lines...) Expand all Loading... |
447 } | 522 } |
448 }; | 523 }; |
449 | 524 |
450 | 525 |
451 U_NAMESPACE_END | 526 U_NAMESPACE_END |
452 | 527 |
453 #endif // #if !UCONFIG_NO_FORMATTING | 528 #endif // #if !UCONFIG_NO_FORMATTING |
454 #endif // _DIGITLST | 529 #endif // _DIGITLST |
455 | 530 |
456 //eof | 531 //eof |
OLD | NEW |