/**************************************************************************/
/*                                                                        */
/*                                 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_coni.c,v 1.2 1997/09/25 17:01:09 ae59 Exp $ */
/*
$Log: b_coni.c,v $
 * Revision 1.2  1997/09/25  17:01:09  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:18  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_coni.c                              */
/*                                                              */
/*      Entries         : void b_coni(dp,pd,a_b,a_e,d,bits)     */
/*                        a_intg dp;                            */
/*                        a_btyp *pd;                           */
/*                        a_intg *a_b;                          */
/*                        a_intg *a_e;                          */
/*                        d_otpr d;                             */
/*                        a_intg *bits;                         */
/*                                                              */
/*      Arguments       : dp - length of pd                     */
/*                        pd - packed decimals                  */
/*                        a_b     - first position in mantissa  */
/*                        a_e     - last  position in mantissa  */
/*                        d - dotprecision variable             */
/*                        bits - number of required bits        */
/*                                                              */
/*      Description     : Convert integer part of number        */
/*                                                              */
/*      Note            : No range check on array pd.           */
/*                                                              */
/*      Date            : 1991-02-18                            */
/*      1991-02-18 : new arguments a_b, a_e                     */
/*      1991-01-22 : argument d changed to dotprecision         */
/*      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 void b_coni(a_intg dp,a_btyp *pd,a_intg *a_b,a_intg *a_e,
                  d_otpr d,a_intg *bits)
#else
local void b_coni(dp,pd,a_b,a_e,d,bits)

a_intg dp;
a_btyp *pd;
a_intg *a_b;
a_intg *a_e;
d_otpr d;
a_intg *bits;
#endif
        {
        a_intg da,block;
        a_btyp mod,*q,*p;

        /* initialize                                   */
        if (*a_b==0) *a_e = A_D_P;
        *a_b = A_D_P;
        q = &d[A_D_P];
        da = 0;
        block = 0;

        /* convert by repeated division                 */
        while (da<dp)
           {
           if (block==B_LENGTH) {
              block = 0;
              *bits -= B_LENGTH;
              q--;
              (*a_b)--;
              }

           mod = ZERO;
           for (p=pd+da;p<pd+dp;p++)
              {
              *p += mod*DEC_PACK_POWER;
              mod = *p & (BIN_PACK_POWER-1);
              *p >>= BIN_PACK;
              }
           *q |= mod<<block;
           block += BIN_PACK;

           while (pd[da]==ZERO && da<dp) da++;
           }

        *bits -= B_LENGTH;
        mod = *q;
        while (!(mod & MSB))
           {
           mod <<= 1;
           (*bits)++;
           }

        return;
        }
