OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [test/] [dcvt.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
 
 
 
 
#include <limits.h>
#include <limits.h>
#include <math.h>
#include <math.h>
#include <stdio.h>
#include <stdio.h>
#include <float.h>
#include <float.h>
#include <ieeefp.h>
#include <ieeefp.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#define _MAX_CHARS 512
#define _MAX_CHARS 512
 
 
static char *lcset = "0123456789abcdef";
static char *lcset = "0123456789abcdef";
 
 
static struct p {
static struct p {
        double pvalue, nvalue;
        double pvalue, nvalue;
        int exp;
        int exp;
} powers[] =
} powers[] =
{
{
{ 1e32, 1e-32, 32},
{ 1e32, 1e-32, 32},
{ 1e16, 1e-16, 16},
{ 1e16, 1e-16, 16},
{ 1e8, 1e-8, 8},
{ 1e8, 1e-8, 8},
{ 1e4, 1e-4, 4},
{ 1e4, 1e-4, 4},
{ 1e2, 1e-2, 2},
{ 1e2, 1e-2, 2},
{ 1e1, 1e-1, 1 },
{ 1e1, 1e-1, 1 },
{ 1e0, 1e-0, 0 }
{ 1e0, 1e-0, 0 }
};
};
 
 
#define _MAX_PREC 16
#define _MAX_PREC 16
 
 
static char
static char
_DEFUN(nextdigit,(value),
_DEFUN(nextdigit,(value),
double *value)
double *value)
{
{
  double tmp;
  double tmp;
 
 
  *value = modf (*value * 10, &tmp) ;
  *value = modf (*value * 10, &tmp) ;
  return  lcset[(int)tmp];
  return  lcset[(int)tmp];
}
}
 
 
 
 
static char *
static char *
_DEFUN(print_nan,(buffer, value, precision),
_DEFUN(print_nan,(buffer, value, precision),
       char *buffer _AND
       char *buffer _AND
       double value _AND
       double value _AND
       int precision)
       int precision)
{
{
  size_t  i;
  size_t  i;
 
 
  if (isnan(value))
  if (isnan(value))
    {
    {
      strcpy(buffer, "nan");
      strcpy(buffer, "nan");
      i = 3;
      i = 3;
 
 
    }
    }
  else
  else
    {
    {
      strcpy(buffer, "infinity");
      strcpy(buffer, "infinity");
      i = 8;
      i = 8;
    }
    }
 
 
  while (i < precision)
  while (i < precision)
    {
    {
      buffer[i++] = ' ';
      buffer[i++] = ' ';
    }
    }
  buffer[i++] = 0;
  buffer[i++] = 0;
  return buffer;
  return buffer;
 
 
}
}
 
 
/* A convert info struct */
/* A convert info struct */
typedef struct
typedef struct
{
{
  char *buffer ;                /* Destination of conversion */
  char *buffer ;                /* Destination of conversion */
  double value;                 /* scratch Value to convert */
  double value;                 /* scratch Value to convert */
  double original_value;        /* saved Value to convert */
  double original_value;        /* saved Value to convert */
  int value_neg;                /* OUT: 1 if value initialiy neg */
  int value_neg;                /* OUT: 1 if value initialiy neg */
  int abs_exp;                  /* abs Decimal exponent of value */
  int abs_exp;                  /* abs Decimal exponent of value */
  int abs_exp_sign;             /* + or - */
  int abs_exp_sign;             /* + or - */
  int exp;                      /* exp not sgned */
  int exp;                      /* exp not sgned */
  int type;                     /* fFeEgG used in printing before exp */
  int type;                     /* fFeEgG used in printing before exp */
 
 
  int print_trailing_zeros;     /* Print 00's after a . */
  int print_trailing_zeros;     /* Print 00's after a . */
 
 
  int null_idx;  /* Index of the null at the end */
  int null_idx;  /* Index of the null at the end */
 
 
/* These ones are read only */
/* These ones are read only */
  int decimal_places;           /* the number of digits to print after
  int decimal_places;           /* the number of digits to print after
                                   the decimal */
                                   the decimal */
  int max_digits;               /* total number of digits to print */
  int max_digits;               /* total number of digits to print */
  int buffer_size;              /* Size of output buffer */
  int buffer_size;              /* Size of output buffer */
 
 
  /* Two sorts of dot ness.
  /* Two sorts of dot ness.
     0  never ever print a dot
     0  never ever print a dot
     1  print a dot if followed by a digit
     1  print a dot if followed by a digit
     2  always print a dot, even if no digit following
     2  always print a dot, even if no digit following
     */
     */
  enum { dot_never, dot_sometimes, dot_always} dot; /* Print a decimal point, always */
  enum { dot_never, dot_sometimes, dot_always} dot; /* Print a decimal point, always */
  int dot_idx;                  /* where the dot went, or would have gone */
  int dot_idx;                  /* where the dot went, or would have gone */
} cvt_info_type;
} cvt_info_type;
 
 
 
 
void
void
_DEFUN(renormalize,(in),
_DEFUN(renormalize,(in),
       cvt_info_type *in)
       cvt_info_type *in)
{
{
 
 
  /* Make sure all numbers are less than 1 */
  /* Make sure all numbers are less than 1 */
 
 
  while (in->value >= 1.0)
  while (in->value >= 1.0)
  {
  {
    in->value = in->value * 0.1;
    in->value = in->value * 0.1;
    in->exp++;
    in->exp++;
  }
  }
 
 
  /* Now we have only numbers between 0 and .9999.., and have adjusted
  /* Now we have only numbers between 0 and .9999.., and have adjusted
     exp to account for the shift */
     exp to account for the shift */
 
 
  if (in->exp >= 0)
  if (in->exp >= 0)
  {
  {
    in->abs_exp_sign = '+';
    in->abs_exp_sign = '+';
    in->abs_exp = in->exp;
    in->abs_exp = in->exp;
  }
  }
  else
  else
  {
  {
    in->abs_exp_sign  = '-';
    in->abs_exp_sign  = '-';
    in->abs_exp = -in->exp;
    in->abs_exp = -in->exp;
  }
  }
 
 
}
}
 
 
/* This routine looks at original_value, and makes it between 0 and 1,
/* This routine looks at original_value, and makes it between 0 and 1,
   modifying exp as it goes
   modifying exp as it goes
 */
 */
 
 
static void
static void
_DEFUN(normalize,(value, in),
_DEFUN(normalize,(value, in),
       double value _AND
       double value _AND
       cvt_info_type *in)
       cvt_info_type *in)
{
{
  int j;
  int j;
  int texp;
  int texp;
  if (value != 0)
  if (value != 0)
  {
  {
     texp = -1;
     texp = -1;
 
 
 
 
  if (value < 0.0)
  if (value < 0.0)
  {
  {
    in->value_neg =1 ;
    in->value_neg =1 ;
    value = - value;
    value = - value;
  }
  }
  else
  else
  {
  {
    in->value_neg = 0;
    in->value_neg = 0;
  }
  }
 
 
 
 
  /* Work out texponent & normalise value */
  /* Work out texponent & normalise value */
 
 
  /* If value > 1, then shrink it */
  /* If value > 1, then shrink it */
  if (value >= 1.0)
  if (value >= 1.0)
  {
  {
    for (j = 0; j < 6; j++)
    for (j = 0; j < 6; j++)
    {
    {
      while (value >= powers[j].pvalue)
      while (value >= powers[j].pvalue)
      {
      {
        value /= powers[j].pvalue;
        value /= powers[j].pvalue;
        texp += powers[j].exp;
        texp += powers[j].exp;
      }
      }
    }
    }
  }
  }
  else if (value != 0.0)
  else if (value != 0.0)
  {
  {
    for (j = 0; j < 6; j++)
    for (j = 0; j < 6; j++)
    {
    {
      while (value <= powers[j].nvalue)
      while (value <= powers[j].nvalue)
      {
      {
        value *= powers[j].pvalue;
        value *= powers[j].pvalue;
        texp -= powers[j].exp;
        texp -= powers[j].exp;
      }
      }
    }
    }
  }
  }
   }
   }
 
 
  else
  else
  {
  {
    texp = 0;
    texp = 0;
  }
  }
 
 
 
 
  in->exp = texp;
  in->exp = texp;
  in->value = value;
  in->value = value;
  in->original_value = value;
  in->original_value = value;
  renormalize(in);
  renormalize(in);
 
 
}
}
int
int
_DEFUN(round,(in, start, now, ch),
_DEFUN(round,(in, start, now, ch),
       cvt_info_type *in _AND
       cvt_info_type *in _AND
       char *start _AND
       char *start _AND
       char *now _AND
       char *now _AND
       char ch)
       char ch)
{
{
  double rounder = 5.0;
  double rounder = 5.0;
 
 
  char *p;
  char *p;
  int ok = 0;
  int ok = 0;
 
 
  now --;
  now --;
 
 
  /* If the next digit to output would have been a '5' run back and */
  /* If the next digit to output would have been a '5' run back and */
  /* see if we can create a more rounded number. If we can then do it.
  /* see if we can create a more rounded number. If we can then do it.
     If not (like when the number was 9.9 and the last char was
     If not (like when the number was 9.9 and the last char was
     another 9), then we'll have to modify the number and try again */
     another 9), then we'll have to modify the number and try again */
  if (ch < '5')
  if (ch < '5')
   return 0;
   return 0;
 
 
 
 
  for (p = now;!ok && p >= start; p--)
  for (p = now;!ok && p >= start; p--)
  {
  {
    switch (*p)
    switch (*p)
    {
    {
    default:
    default:
      abort();
      abort();
    case '.':
    case '.':
      break;
      break;
    case '9':
    case '9':
      rounder = rounder * 0.1;
      rounder = rounder * 0.1;
      break;
      break;
    case '8':
    case '8':
    case '7':
    case '7':
    case '6':
    case '6':
    case '5':
    case '5':
    case '4':
    case '4':
    case '3':
    case '3':
    case '2':
    case '2':
    case '1':
    case '1':
    case '0':
    case '0':
      p = now;
      p = now;
      while (1) {
      while (1) {
          if (*p == '9') {
          if (*p == '9') {
              *p = '0';
              *p = '0';
            }
            }
          else if (*p != '.') {
          else if (*p != '.') {
              (*p)++;
              (*p)++;
              return 0;
              return 0;
            }
            }
          p--;
          p--;
        }
        }
    }
    }
 
 
  }
  }
 
 
  /* Getting here means that we couldn't round the number in place
  /* Getting here means that we couldn't round the number in place
     textually - there have been all nines.
     textually - there have been all nines.
     We'll have to add to it and try the conversion again
     We'll have to add to it and try the conversion again
     eg
     eg
     .99999[9] can't be rounded in place, so add
     .99999[9] can't be rounded in place, so add
     .000005   to it giving:
     .000005   to it giving:
     1.000004   we notice that the result is > 1 so add to exp and
     1.000004   we notice that the result is > 1 so add to exp and
     divide by 10
     divide by 10
     .100004
     .100004
     */
     */
 
 
  in->original_value = in->value = in->original_value + rounder;
  in->original_value = in->value = in->original_value + rounder;
  normalize(in->original_value , in);
  normalize(in->original_value , in);
  return 1;
  return 1;
 
 
 
 
}
}
 
 
 
 
 
 
void
void
_DEFUN(_cvte,(in),
_DEFUN(_cvte,(in),
       register  cvt_info_type *in)
       register  cvt_info_type *in)
{
{
  int buffer_idx  =0;
  int buffer_idx  =0;
  int digit = 0;
  int digit = 0;
 
 
  int after_decimal =0;
  int after_decimal =0;
 
 
  in->buffer[buffer_idx++] = nextdigit(&(in->value));
  in->buffer[buffer_idx++] = nextdigit(&(in->value));
  digit++;
  digit++;
  in->dot_idx = buffer_idx;
  in->dot_idx = buffer_idx;
 
 
 
 
  switch (in->dot)
  switch (in->dot)
  {
  {
  case dot_never:
  case dot_never:
    break;
    break;
  case dot_sometimes:
  case dot_sometimes:
    if (in->decimal_places
    if (in->decimal_places
        && digit < in->max_digits)
        && digit < in->max_digits)
    {
    {
      in->buffer[buffer_idx++] = '.';
      in->buffer[buffer_idx++] = '.';
    }
    }
    break;
    break;
  case dot_always:
  case dot_always:
    in->buffer[buffer_idx++] = '.';
    in->buffer[buffer_idx++] = '.';
  }
  }
 
 
 
 
  while (buffer_idx < in->buffer_size
  while (buffer_idx < in->buffer_size
         && after_decimal < in->decimal_places
         && after_decimal < in->decimal_places
         && digit < in->max_digits)
         && digit < in->max_digits)
  {
  {
    in->buffer[buffer_idx] = nextdigit(&(in->value));
    in->buffer[buffer_idx] = nextdigit(&(in->value));
    after_decimal++;
    after_decimal++;
    buffer_idx++;
    buffer_idx++;
    digit++;
    digit++;
 
 
  }
  }
 
 
  if (round(in,
  if (round(in,
            in->buffer,
            in->buffer,
            in->buffer+buffer_idx,
            in->buffer+buffer_idx,
            nextdigit(&(in->value))))
            nextdigit(&(in->value))))
  {
  {
    _cvte(in);
    _cvte(in);
  }
  }
  else
  else
  {
  {
    in->buffer[buffer_idx++] = in->type;
    in->buffer[buffer_idx++] = in->type;
    in->buffer[buffer_idx++] = in->abs_exp_sign;
    in->buffer[buffer_idx++] = in->abs_exp_sign;
 
 
    if (in->abs_exp >= 100)
    if (in->abs_exp >= 100)
    {
    {
      in->buffer[buffer_idx++] = lcset[in->abs_exp / 100];
      in->buffer[buffer_idx++] = lcset[in->abs_exp / 100];
      in->abs_exp %= 100;
      in->abs_exp %= 100;
    }
    }
    in->buffer[buffer_idx++] = lcset[in->abs_exp / 10];
    in->buffer[buffer_idx++] = lcset[in->abs_exp / 10];
    in->buffer[buffer_idx++] = lcset[in->abs_exp % 10];
    in->buffer[buffer_idx++] = lcset[in->abs_exp % 10];
  }
  }
 
 
  in->buffer[buffer_idx++] = 0;
  in->buffer[buffer_idx++] = 0;
}
}
 
 
 
 
 
 
 
 
/* Produce NNNN.FFFF */
/* Produce NNNN.FFFF */
void
void
_DEFUN(_cvtf,(in),
_DEFUN(_cvtf,(in),
       cvt_info_type *in)
       cvt_info_type *in)
{
{
 
 
  int buffer_idx = 0;            /* Current char being output */
  int buffer_idx = 0;            /* Current char being output */
  int after_decimal = 0;
  int after_decimal = 0;
  int digit =0;
  int digit =0;
 
 
 
 
  in->dot_idx = in->exp + 1;
  in->dot_idx = in->exp + 1;
 
 
  /* Two sorts of number, NNN.FFF and 0.0000...FFFF */
  /* Two sorts of number, NNN.FFF and 0.0000...FFFF */
 
 
 
 
  /* Print all the digits up to the decimal point */
  /* Print all the digits up to the decimal point */
 
 
  while (buffer_idx <= in->exp
  while (buffer_idx <= in->exp
         && digit < in->max_digits
         && digit < in->max_digits
         && buffer_idx < in->buffer_size)
         && buffer_idx < in->buffer_size)
  {
  {
    in->buffer[buffer_idx]  = nextdigit(&(in->value));
    in->buffer[buffer_idx]  = nextdigit(&(in->value));
    buffer_idx++;
    buffer_idx++;
    digit ++;
    digit ++;
  }
  }
 
 
 
 
  /* And the decimal point if we should */
  /* And the decimal point if we should */
  if (buffer_idx < in->buffer_size)
  if (buffer_idx < in->buffer_size)
  {
  {
 
 
    switch (in->dot)
    switch (in->dot)
    {
    {
    case dot_never:
    case dot_never:
      break;
      break;
    case dot_sometimes:
    case dot_sometimes:
      /* Only print a dot if following chars */
      /* Only print a dot if following chars */
      if (in->decimal_places
      if (in->decimal_places
          && digit < in->max_digits )
          && digit < in->max_digits )
      {
      {
       in->buffer[buffer_idx++] = '.';
       in->buffer[buffer_idx++] = '.';
     }
     }
 
 
      break;
      break;
    case dot_always:
    case dot_always:
      in->buffer[buffer_idx++] = '.';
      in->buffer[buffer_idx++] = '.';
    }
    }
 
 
    after_decimal = 0;
    after_decimal = 0;
 
 
    /* And the digits following the point if necessary */
    /* And the digits following the point if necessary */
 
 
    /* Only print the leading zeros if a dot was possible */
    /* Only print the leading zeros if a dot was possible */
    if (in->dot || in->exp>0)
    if (in->dot || in->exp>0)
    {
    {
     while (buffer_idx < in->buffer_size
     while (buffer_idx < in->buffer_size
            && (in->abs_exp_sign == '-' && digit < in->abs_exp - 1)
            && (in->abs_exp_sign == '-' && digit < in->abs_exp - 1)
            && (after_decimal < in->decimal_places)
            && (after_decimal < in->decimal_places)
            && (digit < in->max_digits))
            && (digit < in->max_digits))
     {
     {
       in->buffer[buffer_idx] = '0';
       in->buffer[buffer_idx] = '0';
       buffer_idx++;
       buffer_idx++;
       digit++;
       digit++;
       after_decimal++;
       after_decimal++;
     }
     }
   }
   }
 
 
    while (buffer_idx < in->buffer_size
    while (buffer_idx < in->buffer_size
           && after_decimal < in->decimal_places
           && after_decimal < in->decimal_places
           && digit < in->max_digits)
           && digit < in->max_digits)
    {
    {
      in->buffer[buffer_idx]  = nextdigit(&(in->value));
      in->buffer[buffer_idx]  = nextdigit(&(in->value));
      buffer_idx++;
      buffer_idx++;
      digit++;
      digit++;
      after_decimal++;
      after_decimal++;
    }
    }
  }
  }
 
 
  in->null_idx = buffer_idx;
  in->null_idx = buffer_idx;
  in->buffer[buffer_idx] = 0;
  in->buffer[buffer_idx] = 0;
  if (round(in, in->buffer, in->buffer+buffer_idx,
  if (round(in, in->buffer, in->buffer+buffer_idx,
            nextdigit(&(in->value))))
            nextdigit(&(in->value))))
  {
  {
      _cvtf(in);
      _cvtf(in);
  }
  }
 
 
 
 
 
 
 
 
}
}
 
 
 
 
 
 
char *
char *
_DEFUN(_dcvt,(buffer, invalue, precision, width, type, dot),
_DEFUN(_dcvt,(buffer, invalue, precision, width, type, dot),
       char *buffer _AND
       char *buffer _AND
       double invalue _AND
       double invalue _AND
       int precision _AND
       int precision _AND
       int width _AND
       int width _AND
       char type _AND
       char type _AND
       int dot)
       int dot)
{
{
  cvt_info_type in;
  cvt_info_type in;
 
 
 
 
 
 
  in.buffer = buffer;
  in.buffer = buffer;
  in.buffer_size = 512;
  in.buffer_size = 512;
 
 
  if (!finite(invalue))
  if (!finite(invalue))
  {
  {
    return print_nan(buffer, invalue, precision);
    return print_nan(buffer, invalue, precision);
  }
  }
 
 
 
 
  normalize(invalue, &in);
  normalize(invalue, &in);
 
 
  in.type = type;
  in.type = type;
  in.dot = dot? dot_always: dot_sometimes;
  in.dot = dot? dot_always: dot_sometimes;
 
 
  switch (type)
  switch (type)
  {
  {
 
 
  case 'g':
  case 'g':
  case 'G':
  case 'G':
    /* When formatting a g, the precision refers to the number of
    /* When formatting a g, the precision refers to the number of
       char positions *total*, this leads to various off by ones */
       char positions *total*, this leads to various off by ones */
  {
  {
    /* A precision of 0 means 1 */
    /* A precision of 0 means 1 */
    if (precision == 0)
    if (precision == 0)
     precision = 1;
     precision = 1;
 
 
    /* A g turns into an e if there are more digits than the
    /* A g turns into an e if there are more digits than the
       precision, or it's smaller than e-4 */
       precision, or it's smaller than e-4 */
    if (in.exp >= precision || in.exp < -4)
    if (in.exp >= precision || in.exp < -4)
    {
    {
      in.type = (type == 'g' ? 'e' : 'E');
      in.type = (type == 'g' ? 'e' : 'E');
      in.decimal_places = _MAX_CHARS;
      in.decimal_places = _MAX_CHARS;
      in.max_digits = precision;
      in.max_digits = precision;
      in.print_trailing_zeros = 1;
      in.print_trailing_zeros = 1;
      _cvte(&in);
      _cvte(&in);
    }
    }
    else
    else
    {
    {
      /* G means total number of chars to print */
      /* G means total number of chars to print */
      in.decimal_places = _MAX_CHARS;
      in.decimal_places = _MAX_CHARS;
      in.max_digits = precision;
      in.max_digits = precision;
      in.type = (type == 'g' ? 'f' : 'F');
      in.type = (type == 'g' ? 'f' : 'F');
      in.print_trailing_zeros = 0;
      in.print_trailing_zeros = 0;
      _cvtf(&in);
      _cvtf(&in);
 
 
   if (!dot) {
   if (!dot) {
       /* trim trailing zeros */
       /* trim trailing zeros */
       int j = in.null_idx -1;
       int j = in.null_idx -1;
       while (j > 0 && in.buffer[j] == '0')
       while (j > 0 && in.buffer[j] == '0')
       {
       {
         in.buffer[j] = 0;
         in.buffer[j] = 0;
         j--;
         j--;
       }
       }
       /* Stamp on a . if not followed by zeros */
       /* Stamp on a . if not followed by zeros */
       if (j > 0 && buffer[j] == '.')
       if (j > 0 && buffer[j] == '.')
        in.buffer[j] = 0;
        in.buffer[j] = 0;
     }
     }
    }
    }
 
 
 
 
    break;
    break;
  case 'f':
  case 'f':
  case 'F':
  case 'F':
    in.decimal_places= precision;
    in.decimal_places= precision;
    in.max_digits = _MAX_CHARS;
    in.max_digits = _MAX_CHARS;
      in.print_trailing_zeros = 1;
      in.print_trailing_zeros = 1;
    _cvtf(&in);
    _cvtf(&in);
    break;
    break;
  case 'e':
  case 'e':
  case 'E':
  case 'E':
      in.print_trailing_zeros = 1;
      in.print_trailing_zeros = 1;
    in.decimal_places = precision;
    in.decimal_places = precision;
    in.max_digits = _MAX_CHARS;
    in.max_digits = _MAX_CHARS;
    _cvte(&in);
    _cvte(&in);
    break;
    break;
  }
  }
 
 
  }
  }
 
 
 
 
  return buffer;
  return buffer;
}
}
 
 
 
 
 
 
 
 
char *
char *
_DEFUN(fcvtbuf,(invalue,ndigit,decpt,sign, fcvt_buf),
_DEFUN(fcvtbuf,(invalue,ndigit,decpt,sign, fcvt_buf),
       double invalue _AND
       double invalue _AND
       int ndigit _AND
       int ndigit _AND
       int *decpt _AND
       int *decpt _AND
       int *sign _AND
       int *sign _AND
       char *fcvt_buf)
       char *fcvt_buf)
{
{
  cvt_info_type in;
  cvt_info_type in;
  in.buffer = fcvt_buf;
  in.buffer = fcvt_buf;
  in.buffer_size = 512;
  in.buffer_size = 512;
 
 
  if (!finite(invalue))
  if (!finite(invalue))
    {
    {
      return print_nan(fcvt_buf, invalue, ndigit);
      return print_nan(fcvt_buf, invalue, ndigit);
    }
    }
 
 
  normalize(invalue, &in);
  normalize(invalue, &in);
 
 
  in.dot = dot_never;                   /* Don't print a decimal point */
  in.dot = dot_never;                   /* Don't print a decimal point */
  in.max_digits = _MAX_CHARS;
  in.max_digits = _MAX_CHARS;
  in.buffer_size = _MAX_CHARS;          /* Take as many as needed */
  in.buffer_size = _MAX_CHARS;          /* Take as many as needed */
  in.decimal_places = ndigit;
  in.decimal_places = ndigit;
  _cvtf(&in);
  _cvtf(&in);
  *decpt = in.dot_idx;
  *decpt = in.dot_idx;
  *sign = in.value_neg;
  *sign = in.value_neg;
  return in.buffer;
  return in.buffer;
}
}
 
 
 
 
char *
char *
_DEFUN(ecvtbuf,(invalue,ndigit,decpt,sign, fcvt_buf),
_DEFUN(ecvtbuf,(invalue,ndigit,decpt,sign, fcvt_buf),
       double invalue _AND
       double invalue _AND
       int ndigit _AND
       int ndigit _AND
       int *decpt _AND
       int *decpt _AND
       int *sign _AND
       int *sign _AND
       char *fcvt_buf)
       char *fcvt_buf)
{
{
  cvt_info_type in;
  cvt_info_type in;
  in.buffer = fcvt_buf;
  in.buffer = fcvt_buf;
 
 
  if (!finite(invalue))
  if (!finite(invalue))
    {
    {
      return print_nan(fcvt_buf, invalue, ndigit);
      return print_nan(fcvt_buf, invalue, ndigit);
    }
    }
 
 
  normalize(invalue, &in);
  normalize(invalue, &in);
 
 
 
 
  in.dot = dot_never;                   /* Don't print a decimal point */
  in.dot = dot_never;                   /* Don't print a decimal point */
/* We can work out how many digits go after the decimal point */
/* We can work out how many digits go after the decimal point */
 
 
  in.buffer_size =_MAX_CHARS;
  in.buffer_size =_MAX_CHARS;
  in.decimal_places = _MAX_CHARS;
  in.decimal_places = _MAX_CHARS;
  in.max_digits = ndigit;               /* Take as many as told */
  in.max_digits = ndigit;               /* Take as many as told */
  _cvtf(&in);
  _cvtf(&in);
  *decpt = in.dot_idx;
  *decpt = in.dot_idx;
  *sign = in.value_neg;
  *sign = in.value_neg;
  return in.buffer;
  return in.buffer;
}
}
 
 
 
 
 
 
char *
char *
_DEFUN(gcvt,(d,ndigit,buf),
_DEFUN(gcvt,(d,ndigit,buf),
   double d _AND
   double d _AND
   int ndigit _AND
   int ndigit _AND
   char *buf)
   char *buf)
{
{
  return _dcvt(buf, d, ndigit, 0, 'g', 1);
  return _dcvt(buf, d, ndigit, 0, 'g', 1);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.