/**************************************************************************/
/*                                                                        */
/*                                 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: b_irnd.c,v 1.2 1997/09/25 17:03:24 ae59 Exp $ */
/*
$Log: b_irnd.c,v $
 * Revision 1.2  1997/09/25  17:03:24  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:27  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_irnd.c                              */
/*                                                              */
/*      Entries         : void b_irnd(value,lb,ub);             */
/*                        multiprecision value;                 */
/*                        multiprecision *lb;                   */
/*                        multiprecision *ub;                   */
/*                                                              */
/*      Arguments       : value - being rounded to an interval  */
/*                        lb    - lower bound of interval       */
/*                        ub    - upper bound of interval       */
/*                                                              */
/*      Description     : Determine multiprecision interval     */
/*                        that is formed by a multiprecision    */
/*                        value and its rounding information.   */
/*                                                              */
/*      Note            : zero returned if zero was input!      */
/*                        temporary value is freed!             */
/*                                                              */
/*      Date            : 1992-01-23                            */
/*      1992-01-23 : assignment in compare advanced             */
/*      1991-06-17 : new routine                                */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif

#ifdef LINT_ARGS
local void b_irnd(multiprecision value,multiprecision *lb,multiprecision *ub)
#else
local void b_irnd(value,lb,ub)

multiprecision value;
multiprecision *lb;
multiprecision *ub;
#endif
        {
        int rc1,rc2;       /* !!! must be int !!! */
        multiprecision bb;

        E_TPUSH("b_irnd")

        /* determine bounds not considering the sign of the value */
        rc2 = b_brnd(value,*ub);
        if ((rc1 = b_bcpy(value,*lb))!=0 || rc2!=0)
           {
           if (rc1==ALLOC || rc2==ALLOC)
              e_trap(ALLOCATION,2,E_TMLT,&value);
           else
              e_trap(OVERFLOW,2,E_TMLT,&value);
           }

        /* interchange bounds if negative value */
        else if (value->z==0 && value->s==1)
           {
           bb = *lb;
           *lb = *ub;
           *ub = bb;
           }

        if (value->f) l_free(&value);

        E_TPOPP("b_irnd")
        return;
        }
