-/********************************************************************
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/***********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2003, International Business Machines Corporation and
- * others. All Rights Reserved.
- ********************************************************************/
+ * Copyright (c) 1997-2012, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ***********************************************************************/
#include "unicode/utypes.h"
#include "unicode/decimfmt.h"
#include "tsnmfmt.h"
+#include "putilimp.h"
+#include "cstring.h"
#include <float.h>
+#include <stdlib.h>
+
+IntlTestNumberFormat::~IntlTestNumberFormat() {}
static const char * formattableTypeName(Formattable::Type t)
{
case Formattable::kLong: return "kLong";
case Formattable::kString: return "kString";
case Formattable::kArray: return "kArray";
+ case Formattable::kInt64: return "kInt64";
default: return "??unknown??";
}
}
fStatus = U_ZERO_ERROR;
fFormat = NumberFormat::createPercentInstance(locale, fStatus);
testFormat(/* par */);
+
+ if (uprv_strcmp(locale.getName(), "en_US_POSIX") != 0) {
+ name = "Scientific test";
+ logln((UnicodeString)name + " (" + localeName + ")");
+ fStatus = U_ZERO_ERROR;
+ fFormat = NumberFormat::createScientificInstance(locale, fStatus);
+ testFormat(/* par */);
+ }
}
double IntlTestNumberFormat::randDouble()
}
-/* Make sure that we don't get something too large and multiply into infinity. */
+/* Make sure that we don't get something too large and multiply into infinity.
+ @param smallerThanMax the requested maximum value smaller than DBL_MAX */
double IntlTestNumberFormat::getSafeDouble(double smallerThanMax) {
double it;
+ double high = (DBL_MAX/smallerThanMax)/10.0;
+ double low = -high;
do {
it = randDouble();
- } while (-DBL_MAX/smallerThanMax > it || it > DBL_MAX/smallerThanMax);
- it *= smallerThanMax/10.0;
+ } while (low > it || it > high);
return it;
}
{
if (U_FAILURE(fStatus))
{
- errln((UnicodeString)"**** FAIL: createXxxInstance failed.");
+ dataerrln((UnicodeString)"**** FAIL: createXxxInstance failed. - " + u_errorName(fStatus));
if (fFormat != 0)
errln("**** FAIL: Non-null format returned by createXxxInstance upon failure.");
delete fFormat;
DecimalFormat *s = (DecimalFormat*)fFormat;
logln((UnicodeString)" Pattern " + s->toPattern(str));
-#if defined(OS390) || defined(OS400)
+#if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
tryIt(-2.02147304840132e-68);
tryIt(3.88057859588817e-68); // Test rounding when only some digits are shown because exponent is close to -maxfrac
tryIt(-2.64651110485945e+65); // Overflows to +INF when shown as a percent
// These fail due to round-off
// The least significant digit drops by one during each format-parse cycle.
// Both numbers DON'T have a round-off problem when multiplied by 100! (shown as %)
-#ifdef OS390
+#if U_PLATFORM == U_PF_OS390
tryIt(-9.18228054496402e+64);
tryIt(-9.69413034454191e+64);
#else
tryIt(-9.69413034454191e+273);
#endif
-#ifndef OS390
+#if U_PLATFORM != U_PF_OS390
tryIt(1.234e-200);
tryIt(-2.3e-168);
tryIt(1.234e-50);
tryIt(9.99999999999996);
tryIt(9.999999999999996);
+
+ tryIt(5.06e-27);
tryIt((int32_t)INT32_MIN);
tryIt((int32_t)INT32_MAX);
// Convert from long to double
if (number[i].getType() == Formattable::kLong)
number[i].setDouble(number[i].getLong());
+ else if (number[i].getType() == Formattable::kInt64)
+ number[i].setDouble((double)number[i].getInt64());
else if (number[i].getType() != Formattable::kDouble)
{
errMsg = ("**** FAIL: Parse of " + prettify(string[i-1])
fFormat->format(number, stringNum, status);
if (U_FAILURE(status))
{
- errln("**** FAIL: Formatting " + aNumber);
+ errln(UnicodeString("**** FAIL: Formatting ") + aNumber);
return;
}
fFormat->parse(stringNum, number, status);
logln(all);
}
else
- errln((UnicodeString)"**** FAIL: Zero available locales or null array pointer");
+ dataerrln((UnicodeString)"**** FAIL: Zero available locales or null array pointer");
}
void IntlTestNumberFormat::monsterTest(/* char* par */)