char* _STLP_CALL __write_float(char* buf, ios_base::fmtflags flags, int precision, long double x) { # ifdef USE_SPRINTF_INSTEAD char fmtbuf[64]; int i = fill_fmtbuf(fmtbuf, flags, 'L'); sprintf(buf, fmtbuf, precision, x); // we should be able to return buf + sprintf(), but we do not trust'em... return buf + strlen(buf); # else char cvtbuf[NDIG+2]; char * bp; int decpt, sign; switch (flags & ios_base::floatfield) { case ios_base::fixed: bp = _Stl_qfcvtR(x, (min) (precision, MAXFCVT), &decpt, &sign, cvtbuf); break; case ios_base::scientific : bp = _Stl_qecvtR(x, (min) (precision + 1, MAXECVT), &decpt, &sign, cvtbuf); break; default : bp = _Stl_qecvtR(x, (min) (precision, MAXECVT), &decpt, &sign, cvtbuf); break; } __format_float(buf, bp, decpt, sign, x, flags, precision, true); return buf + strlen(buf); # endif }
_STLP_EXP_DECLSPEC void _STLP_CALL __write_float(string &buf, ios_base::fmtflags flags, int precision, double x) { # ifdef USE_SPRINTF_INSTEAD char static_buf[256+10];//+2 - 10/1/07 char fmtbuf[32]; fill_fmtbuf(fmtbuf, flags, 0); sprintf(static_buf, fmtbuf, precision, x); // we should be able to return static_buf + sprintf(), but we do not trust'em... buf = static_buf; # else char cvtbuf[NDIG+2]; char * bp; int decpt, sign; switch (flags & ios_base::floatfield) { case ios_base::fixed: bp = _Stl_fcvtR(x, (min) (precision, MAXFCVT), &decpt, &sign, cvtbuf); break; case ios_base::scientific : bp = _Stl_ecvtR(x, (min) (precision + 1, MAXECVT), &decpt, &sign, cvtbuf); break; default : bp = _Stl_ecvtR(x, (min) (precision, MAXECVT), &decpt, &sign, cvtbuf); break; } __format_float(buf, bp, decpt, sign, x, flags, precision, false); # endif }
size_t _STLP_CALL __write_float(__iostring &buf, ios_base::fmtflags flags, int precision, long double x) { # ifdef USE_SPRINTF_INSTEAD /* If we want 'abitrary' precision, we should use 'abitrary' buffer size * below. - ptr */ char static_buf[128]; // char *static_buf = new char [128+precision]; char fmtbuf[64]; int i = fill_fmtbuf(fmtbuf, flags, 'L'); // snprintf(static_buf, 128+precision, fmtbuf, precision, x); # ifndef N_PLAT_NLM snprintf(ARRAY_AND_SIZE(static_buf), fmtbuf, precision, x); # else sprintf(static_buf, fmtbuf, precision, x); # endif // we should be able to return buf + sprintf(), but we do not trust'em... buf = static_buf; // delete [] static_buf; return find_if(buf.begin(), buf.end(), GroupPos()) - buf.begin(); # else char cvtbuf[NDIG+2]; char * bp; int decpt, sign; switch (flags & ios_base::floatfield) { case ios_base::fixed: bp = _Stl_qfcvtR(x, (min) (precision, MAXFCVT), &decpt, &sign, cvtbuf); break; case ios_base::scientific: bp = _Stl_qecvtR(x, (min) (precision + 1, MAXECVT), &decpt, &sign, cvtbuf); break; default : bp = _Stl_qecvtR(x, (min) (precision, MAXECVT), &decpt, &sign, cvtbuf); break; } return __format_float(buf, bp, decpt, sign, x, flags, precision, true); # endif /* USE_SPRINTF_INSTEAD */ }