TC floating point

Yijun Ding ding at unix.cis.pitt.edu
Thu Feb 22 03:04:38 AEST 1990


After reading TC sizeof() in the news group, here is a program to show
bugs in TC 2.0:

#include <math.h>
char buf[80];
double x, *f;

main()
{
  test1();
  test2();
}

test2()
{
  /* error: floating point format not linked */
  /* solution: x=sin(1) */
  f = (double *)malloc(sizeof(double)*10);
  scanf("%lf",f);
  printf("%lf\n",*f);
}

test1()
{
  /* number of digits after decimal incorrect */
  x = 3.14;
  sprintf(buf,"%8.0e %8.1e %8.2e %8.3e\n",x,x,x,x);
  puts(buf);
}

The bug in test1() in not important, but I am still looking best way to avoid
the problem in test2(). TC will load floating point routine 'automatically' for
you. It is fooled when malloc() is used, even the program involves lengthy
numerical calculations.



More information about the Comp.lang.c mailing list