OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [coremark/] [cvt.c] - Diff between revs 355 and 406

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 355 Rev 406
Line 3... Line 3...
double modf(double x, double *iptr); // Our local version of modf()
double modf(double x, double *iptr); // Our local version of modf()
 
 
#define CVTBUFSIZE 80
#define CVTBUFSIZE 80
static char CVTBUF[CVTBUFSIZE];
static char CVTBUF[CVTBUFSIZE];
 
 
static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag)
static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf,
 
                 int eflag)
{
{
  int r2;
  int r2;
  double fi, fj;
  double fi, fj;
  char *p, *p1;
  char *p, *p1;
 
 
  if (ndigits < 0) ndigits = 0;
        if (ndigits < 0)
  if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
                ndigits = 0;
 
        if (ndigits >= CVTBUFSIZE - 1)
 
                ndigits = CVTBUFSIZE - 2;
  r2 = 0;
  r2 = 0;
  *sign = 0;
  *sign = 0;
  p = &buf[0];
  p = &buf[0];
  if (arg < 0)
        if (arg < 0) {
  {
 
    *sign = 1;
    *sign = 1;
    arg = -arg;
    arg = -arg;
  }
  }
  arg = modf(arg, &fi);
  arg = modf(arg, &fi);
  p1 = &buf[CVTBUFSIZE];
  p1 = &buf[CVTBUFSIZE];
 
 
  if (fi != 0)
        if (fi != 0) {
  {
 
    p1 = &buf[CVTBUFSIZE];
    p1 = &buf[CVTBUFSIZE];
    while (fi != 0)
                while (fi != 0) {
    {
 
      fj = modf(fi / 10, &fi);
      fj = modf(fi / 10, &fi);
      *--p1 = (int)((fj + .03) * 10) + '0';
      *--p1 = (int)((fj + .03) * 10) + '0';
      r2++;
      r2++;
    }
    }
    while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++;
                while (p1 < &buf[CVTBUFSIZE])
  }
                        *p++ = *p1++;
  else if (arg > 0)
        } else if (arg > 0) {
  {
                while ((fj = arg * 10) < 1) {
    while ((fj = arg * 10) < 1)
 
    {
 
      arg = fj;
      arg = fj;
      r2--;
      r2--;
    }
    }
  }
  }
  p1 = &buf[ndigits];
  p1 = &buf[ndigits];
  if (eflag == 0) p1 += r2;
        if (eflag == 0)
 
                p1 += r2;
  *decpt = r2;
  *decpt = r2;
  if (p1 < &buf[0])
        if (p1 < &buf[0]) {
  {
 
    buf[0] = '\0';
    buf[0] = '\0';
    return buf;
    return buf;
  }
  }
  while (p <= p1 && p < &buf[CVTBUFSIZE])
        while (p <= p1 && p < &buf[CVTBUFSIZE]) {
  {
 
    arg *= 10;
    arg *= 10;
    arg = modf(arg, &fj);
    arg = modf(arg, &fj);
    *p++ = (int) fj + '0';
    *p++ = (int) fj + '0';
  }
  }
  if (p1 >= &buf[CVTBUFSIZE])
        if (p1 >= &buf[CVTBUFSIZE]) {
  {
 
    buf[CVTBUFSIZE - 1] = '\0';
    buf[CVTBUFSIZE - 1] = '\0';
    return buf;
    return buf;
  }
  }
  p = p1;
  p = p1;
  *p1 += 5;
  *p1 += 5;
  while (*p1 > '9')
        while (*p1 > '9') {
  {
 
    *p1 = '0';
    *p1 = '0';
    if (p1 > buf)
    if (p1 > buf)
      ++*--p1;
                        ++ * --p1;
    else
                else {
    {
 
      *p1 = '1';
      *p1 = '1';
      (*decpt)++;
      (*decpt)++;
      if (eflag == 0)
                        if (eflag == 0) {
      {
                                if (p > buf)
        if (p > buf) *p = '0';
                                        *p = '0';
        p++;
        p++;
      }
      }
    }
    }
  }
  }
  *p = '\0';
  *p = '\0';

powered by: WebSVN 2.1.0

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