static char * _pscien(long double r, register char *s, int n, int flags) { int sign, dp; register char *s1; s1 = _ecvt(r, n + 1, &dp, &sign); if (sign) *s++ = '-'; else if (flags & FL_SIGN) *s++ = '+'; else if (flags & FL_SPACE) *s++ = ' '; *s++ = *s1++; if ((n > 0) || (flags & FL_ALT)) *s++ = '.'; while (--n >= 0) if (*s1) *s++ = *s1++; else *s++ = '0'; *s++ = 'e'; if ( r != 0 ) --dp ; if ( dp<0 ) { *s++ = '-' ; dp= -dp ; } else { *s++ = '+' ; } if (dp >= 100) { *s++ = '0' + (dp / 100); dp %= 100; } *s++ = '0' + (dp/10); *s++ = '0' + (dp%10); return s; }
void GetOldIndexingName(char * szName, int Index) { int dec, sign; char Temp[512]; strcpy(Temp, _ecvt(Index, 256, &dec, &sign)); Temp[dec] = '\0'; strcat(szName, Temp); }
void elapsedToStringFPS(double elapsed, char* str) { double fps = 1 / elapsed; int numDigits = 8; int decimal, sign; char* fpsStr = _ecvt(fps, numDigits, &decimal, &sign); if (decimal > 0) { strncpy(str, fpsStr, decimal); strncpy(str+decimal, ".", 1); strncpy(str+decimal+1, fpsStr+decimal, 2); str[decimal+3] = '\0'; } }
CString CCue::ToString() { int i = ptr->GetIndex(); int decimal, sign, precision; if (i > 10) { precision = 2; } else { precision = 1; } CString index = _ecvt(i, precision, &decimal, &sign); return index + " **LOCATION OF THE POINTER**"; }
static void test_xcvt(void) { char *str; int i, decpt, sign, err; for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; str = _ecvt( test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15), "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str, test_cvt_testcases[i].expstr_e); ok( decpt == test_cvt_testcases[i].expdecpt_e, "_ecvt() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_e); ok( sign == test_cvt_testcases[i].expsign, "_ecvt() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; str = _fcvt( test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15), "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str, test_cvt_testcases[i].expstr_f); ok( decpt == test_cvt_testcases[i].expdecpt_f, "_fcvt() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_f); ok( sign == test_cvt_testcases[i].expsign, "_fcvt() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } if (p__ecvt_s) { str = malloc(1024); for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; err = p__ecvt_s(str, 1024, test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok(err == 0, "_ecvt_s() failed with error code %d\n", err); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15), "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str, test_cvt_testcases[i].expstr_e); ok( decpt == test_cvt_testcases[i].expdecpt_e, "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_e); ok( sign == test_cvt_testcases[i].expsign, "_ecvt_s() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } free(str); } else win_skip("_ecvt_s not available\n"); if (p__fcvt_s) { int i; str = malloc(1024); /* invalid arguments */ err = p__fcvt_s(NULL, 0, 0.0, 0, &i, &i); ok(err == EINVAL, "got %d, expected EINVAL\n", err); err = p__fcvt_s(str, 0, 0.0, 0, &i, &i); ok(err == EINVAL, "got %d, expected EINVAL\n", err); str[0] = ' '; str[1] = 0; err = p__fcvt_s(str, -1, 0.0, 0, &i, &i); ok(err == 0, "got %d, expected 0\n", err); ok(str[0] == 0, "got %c, expected 0\n", str[0]); ok(str[1] == 0, "got %c, expected 0\n", str[1]); err = p__fcvt_s(str, 1, 0.0, 0, NULL, &i); ok(err == EINVAL, "got %d, expected EINVAL\n", err); err = p__fcvt_s(str, 1, 0.0, 0, &i, NULL); ok(err == EINVAL, "got %d, expected EINVAL\n", err); for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; err = p__fcvt_s(str, 1024, test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok(err == 0, "_fcvt_s() failed with error code %d\n", err); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15), "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str, test_cvt_testcases[i].expstr_f, i); ok( decpt == test_cvt_testcases[i].expdecpt_f, "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_f); ok( sign == test_cvt_testcases[i].expsign, "_fcvt_s() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } free(str); } else win_skip("_fcvt_s not available\n"); }
inline char* _Stl_qecvtR(long double x, int n, int* pt, int* sign, char*) { return _ecvt((double)x, n, pt, sign); }
// those guys claim _cvt functions being reentrant. inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char*) { return _ecvt(x, n, pt, sign); }
int __cdecl main(int argc, char **argv) { char *result; int testDecimal; int testSign; int i=0; struct testCase testCases[] = { /* odd ball values */ {INT64_TO_DOUBLE(NaN), 7, 1, 0, "1#QNAN0" }, /* positive values */ {0, 0, 0, 0, ""}, {INT64_TO_DOUBLE(PositiveSmall), 17, -323, 0, "49406564584124654"}, {.00123, 3, -2, 0, "123"}, {.123, 3, 0, 0, "123"}, {123, 3, 3, 0, "123"}, {3.1415926535, 9, 1, 0, "314159265"}, {3.1415926535, 10, 1, 0, "3141592654"}, {3.1415926535, 11, 1, 0, "31415926535"}, {3.1415926535, 12, 1, 0, "314159265350"}, {184467444073709570000.0, 21, 21, 0, "184467444073709570000", "184467444073709568000" }, {184467444073709570000.0, 22, 21, 0, "1844674440737095700000", "1844674440737095680000" }, {INT64_TO_DOUBLE(PositiveInfinity), 7, 1, 0, "1#INF00" }, /* negative values */ {-0, 0, 0, 0, ""}, {INT64_TO_DOUBLE(NegativeSmall), 17, -323, 1, "49406564584124654"}, {-.00123, 3, -2, 1, "123"}, {-.123, 3, 0, 1, "123"}, {-123, 3, 3, 1, "123"}, {-3.1415926535, 9, 1, 1, "314159265"}, {-3.1415926535, 10, 1, 1, "3141592654"}, {-3.1415926535, 11, 1, 1, "31415926535"}, {-3.1415926535, 12, 1, 1, "314159265350"}, {-184467444073709570000.0, 21, 21, 1, "184467444073709570000", "184467444073709568000" }, {-184467444073709570000.0, 22, 21, 1, "1844674440737095700000", "1844674440737095680000" }, {INT64_TO_DOUBLE(NegativeInfinity), 7, 1, 1, "1#INF00"} }; if (0 != (PAL_Initialize(argc, argv))) { return FAIL; } /* Loop through each case. Call _ecvt on each test case and check the result. */ for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) { result = _ecvt(testCases[i].value, testCases[i].precision, &testDecimal, &testSign); if (( strcmp(testCases[i].expResult, result) != 0 && strcmp(testCases[i].bsdExpResult, result) != 0 ) || ( testCases[i].sign != testSign ) || ( testCases[i].decimal != testDecimal )) { Fail("PALSUITE ERROR: Test %d\n" "-----------------------\n" "testCases[i].value = '%f'\n" "testCases[i].precision = '%d'\n" "testCases[i].decimal = '%d'\n" "testCases[i].sign = '%d'\n" "testCases[i].expResult = '%s'\n" "result = '%s'\n" "testDecimal = '%d'\n" "testSign = '%d'\n\n", i, testCases[i].value, testCases[i].precision, testCases[i].decimal, testCases[i].sign, testCases[i].expResult, result, testDecimal, testSign); } } PAL_Terminate(); return PASS; }
inline char* _Stl_qecvtR(long double x, int n, int* pt, int* sign, char* buf) { strcpy(buf, _ecvt((double)x, n, pt, sign)); return buf; }
static char * _gcvt(long double value, int ndigit, char *s, int flags) { int sign, dp; register char *s1, *s2; register int i; register int nndigit = ndigit; s1 = _ecvt(value, ndigit, &dp, &sign); s2 = s; if (sign) *s2++ = '-'; else if (flags & FL_SIGN) *s2++ = '+'; else if (flags & FL_SPACE) *s2++ = ' '; if (!(flags & FL_ALT)) for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--) nndigit--; if (USE_EXP(dp,ndigit)) { /* Use E format */ dp--; *s2++ = *s1++; if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.'; while (--nndigit > 0) *s2++ = *s1++; *s2++ = 'e'; if (dp < 0) { *s2++ = '-'; dp = -dp; } else *s2++ = '+'; s2 += NDIGINEXP(dp); *s2 = 0; for (i = NDIGINEXP(dp); i > 0; i--) { *--s2 = dp % 10 + '0'; dp /= 10; } return s; } /* Use f format */ if (dp <= 0) { if (*s1 != '0') { /* otherwise the whole number is 0 */ *s2++ = '0'; *s2++ = '.'; } while (dp < 0) { dp++; *s2++ = '0'; } } for (i = 1; i <= nndigit; i++) { *s2++ = *s1++; if (i == dp) *s2++ = '.'; } if (i <= dp) { while (i++ <= dp) *s2++ = '0'; *s2++ = '.'; } if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--; *s2 = '\0'; return s; }