floating.c
author Markus Brökers <mbroeker@largo.homelinux.org>
Mon, 30 Aug 2010 15:21:47 +0200
changeset 146 0ffa20c26b2d
parent 77 49e0babccb23
permissions -rw-r--r--
gauss.c: set a proper accuracy value: 1E-6

/**
 * floating.c
 * Copyright (C) 2008 Markus Broeker
 */

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

double *getValues (unsigned 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);

    unsigned 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;
}