printf("fastpath? [%d]\n", number);
#endif
- if( data.fFastpathStatus==kFastpathYES ) {
+ if( data.fFastpathStatus==kFastpathYES) {
#define kZero 0x0030
const int32_t MAX_IDX = MAX_DIGITS+2;
outputStr[--destIdx] = 0; // term
int64_t n = number;
- if (number < 0) { // Negative numbers are slightly larger than a postive
- //outputStr[--destIdx] = (char)(-(n % 10) + kZero);
- n *= -1;
- }
- do {
+ if (number < 1) {
+ // Negative numbers are slightly larger than positive
+ // output the first digit (or the leading zero)
+ outputStr[--destIdx] = (-(n % 10) + kZero);
+ n /= -10;
+ }
+ // get any remaining digits
+ while (n > 0) {
outputStr[--destIdx] = (n % 10) + kZero;
n /= 10;
- } while (n > 0);
+ }
// Slide the number to the start of the output str
#else
infoln("NOTE: UCONFIG_FORMAT_FASTPATHS not set, test skipped.");
#endif
+
+ // get some additional case
+ {
+ UErrorCode status=U_ZERO_ERROR;
+ DecimalFormat df(UnicodeString("0000",""),status);
+ int64_t long_number = 1;
+ UnicodeString expect = "0001";
+ UnicodeString result;
+ FieldPosition pos;
+ df.format(long_number, result, pos);
+ if(U_FAILURE(status)||expect!=result) {
+ errln("FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),""));
+ } else {
+ logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),""));
+ }
+ }
+ {
+ UErrorCode status=U_ZERO_ERROR;
+ DecimalFormat df(UnicodeString("0000000000000000000",""),status);
+ int64_t long_number = U_INT64_MIN; // -9223372036854775808L;
+ // uint8_t bits[8];
+ // memcpy(bits,&long_number,8);
+ // for(int i=0;i<8;i++) {
+ // logln("bits: %02X", (unsigned int)bits[i]);
+ // }
+ UnicodeString expect = "-9223372036854775808";
+ UnicodeString result;
+ FieldPosition pos;
+ df.format(long_number, result, pos);
+ if(U_FAILURE(status)||expect!=result) {
+ errln("FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
+ } else {
+ logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
+ }
+ }
+ {
+ UErrorCode status=U_ZERO_ERROR;
+ DecimalFormat df(UnicodeString("0000000000000000000",""),status);
+ int64_t long_number = U_INT64_MAX; // -9223372036854775808L;
+ // uint8_t bits[8];
+ // memcpy(bits,&long_number,8);
+ // for(int i=0;i<8;i++) {
+ // logln("bits: %02X", (unsigned int)bits[i]);
+ // }
+ UnicodeString expect = "9223372036854775807";
+ UnicodeString result;
+ FieldPosition pos;
+ df.format(long_number, result, pos);
+ if(U_FAILURE(status)||expect!=result) {
+ errln("FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
+ } else {
+ logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
+ }
+ }
+ {
+ UErrorCode status=U_ZERO_ERROR;
+ DecimalFormat df(UnicodeString("0000000000000000000",""),status);
+ int64_t long_number = 0;
+ // uint8_t bits[8];
+ // memcpy(bits,&long_number,8);
+ // for(int i=0;i<8;i++) {
+ // logln("bits: %02X", (unsigned int)bits[i]);
+ // }
+ UnicodeString expect = "0000000000000000000";
+ UnicodeString result;
+ FieldPosition pos;
+ df.format(long_number, result, pos);
+ if(U_FAILURE(status)||expect!=result) {
+ errln("FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
+ } else {
+ logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
+ }
+ }
+ {
+ UErrorCode status=U_ZERO_ERROR;
+ DecimalFormat df(UnicodeString("0000000000000000000",""),status);
+ int64_t long_number = -9223372036854775807L;
+ UnicodeString expect = "-9223372036854775807";
+ UnicodeString result;
+ FieldPosition pos;
+ df.format(long_number, result, pos);
+ if(U_FAILURE(status)||expect!=result) {
+ errln("FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
+ } else {
+ logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
+ }
+ }
}
#endif /* #if !UCONFIG_NO_FORMATTING */