floating.c
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--
We use return EXIT_SUCCESS instead of return 0 committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 *     $Id: floating.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
 * $Source: /development/c/demos/floating.c,v $
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double *getValues (int elements)
{
    double *values;
    int i;

    if ((values = calloc (elements + 1, sizeof (double))) == NULL)
        return NULL;
    for (i = elements; i >= 0; i--)
        values[i] = cos (i);
    return values;
}

#define MAX 40

int main (int argc, char **argv)
{
    double *values = getValues (MAX);
    int i;

    for (i = 0; i < MAX; i++) {
        if (fabs (cos (i) - values[i]) < 0.001)
            printf ("COS(%d) = %3.2g = %3.2g\n", i, values[i], cos (i));
    }

    if (values != NULL)
        free (values);

    return EXIT_SUCCESS;
}