/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: t_sin.c,v 1.2 1997/09/25 18:22:16 ae59 Exp $ */
/*
$Log: t_sin.c,v $
 * Revision 1.2  1997/09/25  18:22:16  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:47  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_sin.c                               */
/*                                                              */
/*      Entries         : a_real t_sin(arg)                     */
/*                        a_real arg;                           */
/*                                                              */
/*      Arguments       : arg  = argument of sine               */
/*                                                              */
/*      Description     : Sine function.                        */
/*                                                              */
/*      Date            : 1991-11-14                            */
/*      1991-11-14 : save and restore flags                     */
/*      1991-09-24 : macro call StdFctReal replaced             */
/*      1991-09-17 : remove semicolon after makro               */
/*      1991-06-21 : new routine                                */
/****************************************************************/

#ifdef AIX
#include "/u/p88c/runtime/tbyte/t_defs.h"
#else
#include "t_defs.h"
#endif

/* StdFctReal(t_sin,sinee) */
#ifdef LINT_ARGS
a_real t_sin(a_real arg)
#else
a_real t_sin(arg)

a_real arg;
#endif
        {
        int      rnd, rc;
        a_real   res;
        ExtReal  a, r;

        E_SPUSH("t_sin")

        rnd = getrndmode();
        longreal_to_extreal((LongReal *)&arg, &a);

        if ((rc = sinee(&a, &r))!=0
            || (rc = extreal_to_longreal(&r, (LongReal *)&res))!=0)
           ieee_abortr1(rc, &arg);

        setrndmode(rnd);

        E_SPOPP("t_sin")
        return res;
        }
/* ------------------------------------------------------------ */

/*--------------------------------------------------------------*
 | Punkt Sinus                                                  |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int sinee(const ExtReal *arg, ExtReal *res)
#else
int sinee(arg, res)
const ExtReal  *arg;
      ExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int sinee(ExtReal *arg, ExtReal *res)
#else
int sinee(arg, res)
ExtReal  *arg;
ExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   DReal       v;          /* Produkt des Arguments mit 2/pi    */
   ExtReal     j;          /* Ganzzahliger Anteil von v         */
   int         jmod4;      /* j modulo 4                        */
   ExtReal     t;          /* reduziertes Argument              */
   int         ret;        /* Rueckgabe                         */
   int         retr;       /* Rueckgabe Reduktion               */
   int         check;      /* Rueckgabe von Makro ArgCheck      */

   /* --- pruefe Argument --- */
   ArgCheck1(Sin, arg, res);

   /* --- ganzzahliger Anteil von arg --- */
   gza_trg(arg, J_Init_Sin, Period_PiHalf, &v, &j, &jmod4);

   /* --- Reduktion --- */
   retr = red_trg(&v, &j, jmod4, &t);

   /* --- Sinus --- */
   ret  = sincos(&t, res);

   /* --- Rueckgabe ohne RundungsInfo --- */
   return (ret!=NoErr?ret:retr);
} /* sinee() */
