ssiinn() -- Mathematics function (libm)

Calculate sine
#iinncclluuddee <mmaatthh.hh>
ddoouubbllee ssiinn(_r_a_d_i_a_n) ddoouubbllee _r_a_d_i_a_n;

ssiinn() calculates the  sine of its argument _r_a_d_i_a_n, which  must be in radian
measure.

_E_x_a_m_p_l_e
The following example uses the functions  ssiinn() and ccooss() to paint sine and
cosine on the screen.  It is by Dmitry Gringauz (dmitry@golem.com).

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

#define MAX_X 79 /* X dimension of screen */
#define MAX_Y 23 /* Y dimension of screen */
char screen[MAX_X][MAX_Y]; /* the screen matrix */

main()
{
    double pi = 3.14159, i, result;
    int x = 0, y = 0, mid_x = (MAX_X-1)/2, mid_y = (MAX_Y-1)/2;

    /* blank (dot) out the screen */
    for (y = 0; y < MAX_Y; y++)
        for (x = 0; x < MAX_X; x++)
            screen[x][y] = '.';

    /* build the "axis" */
    for (x=0; x < MAX_X; x++)
        screen[x][mid_y] = '-';
    for (y = 0; y < MAX_Y; y++)
        screen[mid_x][y] = '|';

    /* make center and arrows */
    screen[mid_x][mid_y] = '+';
    screen[mid_x][0] = '^';
    screen[MAX_X-1][mid_y] = '>';

    /* do the sin() and cos() thing */
    for (i = -pi; i <= pi; i = i + 2.0 / (MAX_X)) {
        result = sin(i) ;

        x = i*mid_x/pi + mid_x;
        y = mid_y*(-1.0*result) + mid_y;

        if (x >= MAX_X)
            x = MAX_X - 1;

        if (y >= MAX_Y)
            y = MAX_Y - 1;

        screen[x][y] = '*';
        result = cos(i) ;

        x = i*mid_x/pi + mid_x;
        y = mid_y*(-1.0*result) + mid_y;

        if (x >= MAX_X)
            x = MAX_X - 1;

        if (y >= MAX_Y)
            y = MAX_Y - 1;
        screen[x][y] = '*';
    } /* i */

    /* print the screen */
    for (y = 0; y < MAX_Y; y++) {
        for (x = 0; x < MAX_X; x++)
            printf("%c", screen[x][y]);
        printf("\n");
    } /* y */
}

_S_e_e _A_l_s_o
ccooss(), ccoosshh(), lliibbmm, ssiinnhh()
ANSI Standard, section 7.5.2.6
POSIX Standard, section 8.1
