author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:00 +0100 | |
changeset 8 | 96d16dfe787a |
parent 0 | af501b0c1716 |
child 9 | c3fecc82ade6 |
permissions | -rw-r--r-- |
0 | 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); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
37 |
|
0 | 38 |
return EXIT_SUCCESS; |
39 |
} |