ICU-3357 define U_INT64_MIN, U_INT64_MAX, and U_UINT64_MAX

X-SVN-Rev: 13577
This commit is contained in:
Steven R. Loomis 2003-11-05 01:49:45 +00:00
parent f05dc3af61
commit bdb879222e
6 changed files with 35 additions and 44 deletions

View File

@ -268,7 +268,7 @@ uprv_isNaN(double number)
#if USE_64BIT_DOUBLE_OPTIMIZATION
/* gcc 3.2 has an optimization bug */
/* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */
return (UBool)(((*((int64_t *)&number)) & INT64_MAX) > gInf64);
return (UBool)(((*((int64_t *)&number)) & U_INT64_MAX) > gInf64);
#else
/* This should work in theory, but it doesn't, so we resort to the more*/
@ -318,7 +318,7 @@ uprv_isInfinite(double number)
#if IEEE_754
#if USE_64BIT_DOUBLE_OPTIMIZATION
/* gcc 3.2 has an optimization bug */
return (UBool)(((*((int64_t *)&number)) & INT64_MAX) == gInf64);
return (UBool)(((*((int64_t *)&number)) & U_INT64_MAX) == gInf64);
#else
/* We know the top bit is the sign bit, so we mask that off in a copy of */

View File

@ -188,37 +188,28 @@
#endif
#if defined(U_INT64_T_UNAVAILABLE)
# ifndef INTMAX_MIN
# define INTMAX_MIN INT32_MIN
# endif
# ifndef INTMAX_MAX
# define INTMAX_MAX INT32_MAX
# endif
# ifndef UINTMAX_MAX
# define UINTMAX_MAX UINT32_MAX
# endif
# error int64_t is required for decimal format and rule-based number format.
#else
# ifndef INT64_MIN
# ifndef INT64_C
/* note: may be wrong for 64 bit platforms - ensure your compiler provides INT64_C */
# define INT64_C(c) c ## LL
# endif
# ifndef UINT64_C
/* note: may be wrong for 64 bit platforms - ensure your compiler provides INT64_C */
# define UINT64_C(c) c ## ULL
# endif
# ifndef U_INT64_MIN
/** The smallest value a 64 bit signed integer can hold @stable ICU 2.0 */
# define INT64_MIN ((int64_t)(-9223372036854775807-1))
# endif
# ifndef INT64_MAX
# define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1))
# endif
# ifndef U_INT64_MAX
/** The largest value a 64 bit signed integer can hold @stable ICU 2.0 */
# define INT64_MAX ((int64_t)(9223372036854775807))
# endif
# ifndef UINT64_MAX
# define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807)))
# endif
# ifndef U_UINT64_MAX
/** The largest value a 64 bit unsigned integer can hold @stable ICU 2.0 */
# define UINT64_MAX ((uint64_t)(18446744073709551615))
# endif
# ifndef INTMAX_MIN
# define INTMAX_MIN INT64_MIN
# endif
# ifndef INTMAX_MAX
# define INTMAX_MAX INT64_MAX
# endif
# ifndef UINTMAX_MAX
# define UINTMAX_MAX UINT64_MAX
# endif
# define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615)))
# endif
#endif
/*==========================================================================*/

View File

@ -654,8 +654,8 @@ DecimalFormat::format(int64_t number,
// check for this before multiplying, and if it happens we use doubles
// instead, trading off accuracy for range.
if (fRoundingIncrement != NULL
|| (fMultiplier != 0 && (number > (INT64_MAX / fMultiplier)
|| number < (INT64_MIN / fMultiplier))))
|| (fMultiplier != 0 && (number > (U_INT64_MAX / fMultiplier)
|| number < (U_INT64_MIN / fMultiplier))))
{
digits.set(((double)number) * fMultiplier,
precision(FALSE),

View File

@ -49,7 +49,7 @@ static char gDecimal = 0;
static const char LONG_MIN_REP[] = "2147483648";
static const char I64_MIN_REP[] = "9223372036854775808";
static const int64_t I64_MIN_VALUE = -9223372036854775807 - 1;
static const int64_t I64_MIN_VALUE = U_INT64_MIN;
enum {
LONG_MIN_REP_LENGTH = sizeof(LONG_MIN_REP) - 1, //Ignore the NULL at the end
@ -370,8 +370,8 @@ DigitList::fitsIntoInt64(UBool ignoreNegativeZero)
return TRUE;
// At this point we have fDecimalAt == fCount, and fCount == INT64_MIN_REP_LENGTH.
// The number will overflow if it is larger than INT64_MAX
// or smaller than INT64_MIN.
// The number will overflow if it is larger than U_INT64_MAX
// or smaller than U_INT64_MIN.
for (int32_t i=0; i<fCount; ++i)
{
char dig = fDigits[i],

View File

@ -281,12 +281,12 @@ Formattable::getInt64(UErrorCode* status) const
case Formattable::kInt64:
return fValue.fInt64;
case Formattable::kDouble:
if (fValue.fDouble > INT64_MAX) {
if (fValue.fDouble > U_INT64_MAX) {
*status = U_INVALID_FORMAT_ERROR;
return INT64_MAX;
} else if (fValue.fDouble < INT64_MIN) {
return U_INT64_MAX;
} else if (fValue.fDouble < U_INT64_MIN) {
*status = U_INVALID_FORMAT_ERROR;
return INT64_MIN;
return U_INT64_MIN;
} else {
return (int64_t)fValue.fDouble;
}

View File

@ -794,9 +794,9 @@ static void TestInt64Format() {
UChar result[512];
UNumberFormat *fmt;
UErrorCode status = U_ZERO_ERROR;
const double doubleInt64Max = (double)INT64_MAX;
const double doubleInt64Min = (double)INT64_MIN;
const double doubleBig = 10.0 * (double)INT64_MAX;
const double doubleInt64Max = (double)U_INT64_MAX;
const double doubleInt64Min = (double)U_INT64_MIN;
const double doubleBig = 10.0 * (double)U_INT64_MAX;
int32_t val32;
int64_t val64;
double valDouble;
@ -810,7 +810,7 @@ static void TestInt64Format() {
log_err("error in unum_openPattern(): %s\n", myErrorName(status));
} else {
unum_setAttribute(fmt, UNUM_MAX_FRACTION_DIGITS, 20);
unum_formatInt64(fmt, INT64_MAX, result, 512, NULL, &status);
unum_formatInt64(fmt, U_INT64_MAX, result, 512, NULL, &status);
if (U_FAILURE(status)) {
log_err("error in unum_format(): %s\n", myErrorName(status));
} else {
@ -828,7 +828,7 @@ static void TestInt64Format() {
val64 = unum_parseInt64(fmt, result, u_strlen(result), &parsepos, &status);
if (U_FAILURE(status)) {
log_err("parseInt64 returned error: %s\n", myErrorName(status));
} else if (val64 != INT64_MAX) {
} else if (val64 != U_INT64_MAX) {
log_err("parseInt64 returned incorrect value, got: %ld\n", val64);
}
@ -892,7 +892,7 @@ static void TestInt64Format() {
val64 = unum_parseInt64(fmt, result, u_strlen(result), &parsepos, &status);
if (status != U_INVALID_FORMAT_ERROR) {
log_err("parseInt64 didn't report error error: %s\n", myErrorName(status));
} else if (val64 != INT64_MAX) {
} else if (val64 != U_INT64_MAX) {
log_err("parseInt64 returned incorrect value, got: %ld\n", val64);
}