equal
deleted
inserted
replaced
|
1 /** |
|
2 * $Id: floating.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ |
|
3 * $Source: /development/c/demos/floating.c,v $ |
|
4 * |
|
5 */ |
|
6 |
|
7 #include <stdio.h> |
|
8 #include <stdlib.h> |
|
9 #include <math.h> |
|
10 |
|
11 double *getValues (int elements) |
|
12 { |
|
13 double *values; |
|
14 int i; |
|
15 |
|
16 if ((values = calloc (elements + 1, sizeof (double))) == NULL) |
|
17 return NULL; |
|
18 for (i = elements; i >= 0; i--) |
|
19 values[i] = cos (i); |
|
20 return values; |
|
21 } |
|
22 |
|
23 #define MAX 40 |
|
24 |
|
25 int main (int argc, char **argv) |
|
26 { |
|
27 double *values = getValues (MAX); |
|
28 int i; |
|
29 |
|
30 for (i = 0; i < MAX; i++) { |
|
31 if (fabs (cos (i) - values[i]) < 0.001) |
|
32 printf ("COS(%d) = %3.2g = %3.2g\n", i, values[i], cos (i)); |
|
33 } |
|
34 |
|
35 if (values != NULL) |
|
36 free (values); |
|
37 return EXIT_SUCCESS; |
|
38 } |