示例#1
0
void _STLP_CALL __get_floor_digits(__iostring &out, _STLP_LONG_DOUBLE __x) {
#ifdef USE_SPRINTF_INSTEAD
  char cvtbuf[128];
#  ifndef _STLP_NO_LONG_DOUBLE
#   ifndef N_PLAT_NLM
  snprintf(ARRAY_AND_SIZE(cvtbuf), "%Lf", __x); // check for 1234.56!
#   else
  sprintf(cvtbuf, "%Lf", __x); // check for 1234.56!
#   endif
#  else
  snprintf(ARRAY_AND_SIZE(cvtbuf), "%f", __x);  // check for 1234.56!
#  endif
  char *p = strchr( cvtbuf, '.' );
  if ( p == 0 ) {
    out.append( cvtbuf );
  } else {
    out.append( cvtbuf, p );
  }
#else
  char cvtbuf[NDIG+2];
  char * bp;
  int decpt, sign;
#ifndef _STLP_NO_LONG_DOUBLE
  bp = _Stl_qfcvtR(__x, 0, &decpt, &sign, cvtbuf);
#else
  bp = _Stl_fcvtR(__x, 0, &decpt, &sign, cvtbuf);
#endif

  if (sign) {
    out += '-';
  }
  out.append(bp, bp + decpt);
#endif // USE_PRINTF_INSTEAD
}
示例#2
0
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
}
示例#3
0
char*  __STL_CALL
__write_float(char* buf, ios_base::fmtflags flags, int precision,
              long double x)
{
  char cvtbuf[NDIG+2];
  char * bp;
  int decpt, sign;

  if (flags & ios_base::scientific)
    bp = _Stl_qecvtR(x, min(precision + 1, MAXECVT), &decpt, &sign, cvtbuf);
  else
    bp = _Stl_qfcvtR(x, min(precision, MAXFCVT),     &decpt, &sign, cvtbuf);

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

  return buf + strlen(buf);
}
示例#4
0
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 */
}