Back to index

glibc  2.9
Classes | Defines | Functions | Variables
tfformat.c File Reference
#include <stdio.h>

Go to the source code of this file.

Classes

struct  sprint_double_type

Defines

#define BSIZE   1024

Functions

static int matches (register char *result, register const char *desired)
int main (int argc, char *argv[])

Variables

sprint_double_type sprint_doubles []
int required_precision = 13

Class Documentation

struct sprint_double_type

Definition at line 5 of file tfformat.c.

Class Members
const char * format_string
int line
const char * result
double value

Define Documentation

#define BSIZE   1024

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 4072 of file tfformat.c.

{
  int errcount = 0;
  int testcount = 0;
  double d;
#define BSIZE 1024
  char buffer[BSIZE];
  sprint_double_type *dptr;
  for (dptr = sprint_doubles; dptr->line; dptr++)
    {
      sprintf (buffer, dptr->format_string, dptr->value);
      if (!matches(buffer, dptr->result))
       {
         errcount++;
         printf(
   "Error in line %d using \"%s\".  Result is \"%s\"; should be: \"%s\".\n",
                dptr->line, dptr->format_string, buffer, dptr->result);
       }

      sprintf (buffer, "%.999g", dptr->value);
      sscanf (buffer, "%lg", &d);
      if (dptr->value != d)
       {
         errcount++;
         printf ("Error in line %d.  String is \"%s\", value is %g.\n",
                dptr->line, buffer, d);
       }
      testcount++;
    }

  /* And one special test.  */
  {
    static const char ref[] = "1.7763568394002504646778106689453125e-15";
    int i;
    d = 1.0;
    for (i = 1; i < 50; ++i)
      d /= 2;
    sprintf (buffer, "%.100g", d);
    if (!matches (buffer, ref))
      {
       ++errcount;
       printf (
    "Error in line %d using \"%s\".  Result is \"%s\"; should be: \"%s\".\n",
              __LINE__, "%.100g", buffer, ref);
      }
  }

  if (errcount == 0)
    {
      printf("Encountered no errors in %d tests.\n", testcount);
      return 0;
    }
  else
    {
      printf("Encountered %d errors in %d tests.\n",
             errcount, testcount);
      return 1;
    }
}

Here is the call graph for this function:

static int matches ( register char *  result,
register const char *  desired 
) [static]

Definition at line 4053 of file tfformat.c.

{
    int digits_seen = 0;
    for (;; result++, desired++) {
       if (*result == *desired) {
           if (*result == 0)
              return 1;
           else if (*result >= '0' && *result <= '9')
              digits_seen++;
       }
       else if (digits_seen >= required_precision
               && *result >= '0' && *result <= '9'
               && *desired >= '0' && *desired <= '9')
           continue;
       else
           return 0;
    }
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 4050 of file tfformat.c.

Definition at line 13 of file tfformat.c.