/**************************************************************************/
/*                                                                        */
/*                                 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_irnd.c,v 1.2 1997/09/25 18:18:06 ae59 Exp $ */
/*
$Log: t_irnd.c,v $
 * Revision 1.2  1997/09/25  18:18:06  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:35  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_irnd.c                              */
/*                                                              */
/*      Date            : 1991-08-05                            */
/*      1991-08-05 : remove unused variables e                  */
/*      1991-06-21 : new routine                                */
/****************************************************************/

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

/*--------------------------------------------------------------*
 | iround_rel, arg*(1+eps_rel)) bzw arg*(1-eps_rel))            |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int iround_rel(const IExtReal *arg, const ExtReal *eps_rel, IExtReal *res)
#else
int iround_rel(arg, eps_rel, res)
const IExtReal  *arg;
const  ExtReal  *eps_rel;
      IExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int iround_rel(IExtReal *arg, ExtReal *eps_rel, IExtReal *res)
#else
int iround_rel(arg, eps_rel, res)
IExtReal  *arg;
 ExtReal  *eps_rel;
IExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   round_rel(UP,   &(arg->u), eps_rel, &(res->u));
   round_rel(DOWN, &(arg->l), eps_rel, &(res->l));

   return NoErr;
} /* iround_rel() */

/*--------------------------------------------------------------*
 | iround_abs, arg+eps_abs bzw arg+eps_abs                      |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int iround_abs(const IExtReal *arg, const ExtReal *eps_abs, IExtReal *res)
#else
int iround_abs(arg, eps_abs, res)
const IExtReal  *arg;
const  ExtReal  *eps_abs;
      IExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int iround_abs(IExtReal *arg, ExtReal *eps_abs, IExtReal *res)
#else
int iround_abs(arg, eps_abs, res)
IExtReal  *arg;
 ExtReal  *eps_abs;
IExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   round_abs(UP,   &(arg->u), eps_abs, &(res->u));
   round_abs(DOWN, &(arg->l), eps_abs, &(res->l));

   return NoErr;
} /* iround_abs() */

/*--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int round_rel(int rndmod, const ExtReal *arg, const ExtReal *eps_rel,
              ExtReal *res)
#else
int round_rel(rndmod, arg, eps_rel, res)
      int      rndmod;
const ExtReal  *arg;
const ExtReal  *eps_rel;
      ExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int round_rel(int rndmod, ExtReal *arg, ExtReal *eps_rel, ExtReal *res)
#else
int round_rel(rndmod, arg, eps_rel, res)
int      rndmod;
ExtReal  *arg;
ExtReal  *eps_rel;
ExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   ExtReal  e;
   int      rnd;

   rnd  = getrndmode();     /* Rundungs-Mode sichern */

   setrndmode(NEAR);
   mulee(arg, eps_rel, &e);
   absee(&e, &e);
   setrndmode(rndmod);
   if (rndmod==UP)
      addee(arg, &e, res);
   else if (rndmod==DOWN)
      subee(arg, &e, res);

   setrndmode(rnd); /* auf urspruenglichen Mode zuruecksetzten */

   return NoErr;
} /* round_rel() */

/*--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int round_abs(int rndmod, const ExtReal *arg, const ExtReal *eps_abs,
              ExtReal *res)
#else
int round_abs(rndmod, arg, eps_abs, res)
      int      rndmod;
const ExtReal  *arg;
const ExtReal  *eps_abs;
      ExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int round_abs(int rndmod, ExtReal *arg, ExtReal *eps_abs, ExtReal *res)
#else
int round_abs(rndmod, arg, eps_abs, res)
int      rndmod;
ExtReal  *arg;
ExtReal  *eps_abs;
ExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   int      rnd;

   rnd  = getrndmode();     /* Rundungs-Mode sichern */

   setrndmode(rndmod);
   if(rndmod==UP)
      addee(arg, eps_abs, res);
   else if(rndmod==DOWN)
      subee(arg, eps_abs, res);
   setrndmode(rnd); /* auf urspruenglichen Mode zuruecksetzten */

   return NoErr;
} /* round_abs() */

/*--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int sround(int rndmod, const ExtReal *arg, const ExtReal *eps_rel,
           const ExtReal *eps_abs, ExtReal *res)
#else
int sround(rndmod, arg, eps_rel, eps_abs, res)
      int      rndmod;
const ExtReal  *arg;
const ExtReal  *eps_rel;
const ExtReal  *eps_abs;
      ExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int sround(int rndmod, ExtReal *arg, ExtReal *eps_rel, ExtReal *eps_abs,
           ExtReal *res)
#else
int sround(rndmod, arg, eps_rel, eps_abs, res)
int      rndmod;
ExtReal  *arg;
ExtReal  *eps_rel;
ExtReal  *eps_abs;
ExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   ExtReal  e;
   int      rnd;

   rnd  = getrndmode();     /* Rundungs-Mode sichern */

   setrndmode(NEAR);
   mulee(arg, eps_rel, &e);
   absee(&e, &e);
   setrndmode(rndmod);
   if(rndmod==UP) {
      addee(arg, &e, res);
      addee(res, eps_abs, res);
   }
   else if(rndmod==DOWN) {
      subee(arg, &e, res);
      subee(res, eps_abs, res);
   }
   setrndmode(rnd); /* auf urspruenglichen Mode zuruecksetzten */

   return NoErr;
} /* round_abs() */
