char*  _STLP_CALL
__write_float(char* buf, ios_base::fmtflags flags, int precision,
              double x)
{
# ifdef USE_SPRINTF_INSTEAD
  char fmtbuf[32];
  fill_fmtbuf(fmtbuf, flags, 0);
  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_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);
  return buf + strlen(buf);
# endif

}
Example #2
0
size_t  _STLP_CALL
__write_float(__iostring &buf, ios_base::fmtflags flags, int precision,
              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[32];
  fill_fmtbuf(fmtbuf, flags, 0);
  // 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
  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_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;
  }
  return __format_float(buf, bp, decpt, sign, x, flags, precision, false);
#endif
}
Example #3
0
char*  __STL_CALL
__write_float(char* buf, ios_base::fmtflags flags, int precision,
              double x)
{
  char cvtbuf[NDIG+2];
  char * bp;
  int decpt, sign;

  if (flags & ios_base::fixed)
    bp = _Stl_fcvtR(x, min(precision, MAXFCVT), &decpt, &sign, cvtbuf);
  else
    bp = _Stl_ecvtR(x, min(precision + 1, MAXECVT),     &decpt, &sign, cvtbuf);

  __format_float(buf, bp, decpt, sign, x, flags, precision, false);

  return buf + strlen(buf);
}