/**************************************************************************/
/*                                                                        */
/*                                 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_geta.c,v 1.2 1997/09/25 17:02:35 ae59 Exp $ */
/*
$Log: b_geta.c,v $
 * Revision 1.2  1997/09/25  17:02:35  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:24  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_geta.c                              */
/*                                                              */
/*      Entries         : a_bool b_geta(a,result,expo,vz)       */
/*                        dotprecision a;                       */
/*                        a_btyp *result;                       */
/*                        a_intg *expo;                         */
/*                        a_bool *vz;                           */
/*                                                              */
/*      Arguments       : a = dotprecision variable             */
/*                        result = a_btyp array[BSIZE]          */
/*                        expo = exponent of number             */
/*                        vz = sign of number                   */
/*                                                              */
/*      Function value  : TRUE if accu is empty                 */
/*                        FALSE otherwise                       */
/*                                                              */
/*      Description     : Get contents of accu ready for use    */
/*                        as IEEE number                        */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : cast to a_bool in sign assignment(accu)=b= */
/*      1992-03-23 : correction of BSIZE to BSIZE-1 in L79 =b=  */
/*      1991-04-15 : optimized mantissa adjustment              */
/*      1990-07-16 : LINT_ARGS prototype                        */
/****************************************************************/

#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 a_bool b_geta(dotprecision a,a_btyp *result,a_intg *expo,
                     a_bool *vz)
#else
local a_bool b_geta(a,result,expo,vz)

dotprecision a;
a_btyp *result;
a_intg *expo;
a_bool *vz;
#endif
        {
        a_intg i,k;
        a_btyp q;

        /* accu is empty                                        */
        if (a[A_BEGIN]==ZERO) return(TRUE);

        /* exponent determined from begin of accu               */
        *expo = (A_D_P-a[A_BEGIN])*B_LENGTH+EXPO_SHIFT;

        /* copy accu to result                                  */
        k = a[A_END]-a[A_BEGIN];
        for (i=0;i<=k && i<BSIZE-1;i++)
           result[i] = a[a[A_BEGIN]+i];

        while (i<BSIZE) { result[i] = ZERO; i++; }

        /* normalization of mantissa */
        if (SHFT_MASK & *result)
           {
           b_shru(result,BSIZE,ZERO_BITS-1);
           (*expo) += ZERO_BITS-1;
           }
        q = *result;
        for(i=0;(HIDDEN_BIT & q)==ZERO;i++) q <<= 1;
        if (i>0)
           {
           b_shlu(result,BSIZE,i);
           (*expo) -= i;
           }

        /* set any insignificant bit in result if inexact       */
        if (k>=BSIZE-1) result[BSIZE-1] |= LSB;

        /* sign of accu                                         */
        *vz = (a_bool) a[A_SIGN];

        return(FALSE);
        }
