/**************************************************************************/
/*                                                                        */
/*                                 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_conf.c,v 1.2 1997/09/25 17:01:02 ae59 Exp $ */
/*
$Log: b_conf.c,v $
 * Revision 1.2  1997/09/25  17:01:02  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:17  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_conf.c                              */
/*                                                              */
/*      Entries         : void b_conf(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 value          */
/*                        bits    - number of required bits     */
/*                                                              */
/*      Description     : Convert fractional part of number     */
/*                                                              */
/*      Note            : No range check on array pd.           */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : changed new to new_v =b=                   */
/*      1991-02-18 : new arguments a_b, a_e                     */
/*      1991-01-22 : argument d changed to d_otpr               */
/*      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_conf(a_intg dp,a_btyp *pd,a_intg *a_b,a_intg *a_e,
                  d_otpr d,a_intg *bits)
#else
local void b_conf(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_bool new_v;
        a_intg block;
        a_btyp carry,*q,*p;

        /* initialize                                   */
        block = B_LENGTH;
        new_v = (*a_b==0) ? TRUE : FALSE;
        if (new_v) *a_b = A_D_P+1;
        *a_e = A_D_P+1;
        q = &d[A_D_P+1];

        /* convert by repeated multiplication           */
        while (*bits>-BIN_PACK)
           {
           if ( (block -= BIN_PACK) <0)
              {
              block = B_LENGTH-BIN_PACK;
              q++;
              (*a_e)++;
              }

           carry = ZERO;
           for (p=pd+dp-1;p>=pd;p--)
              {
              *p = ((*p)<<BIN_PACK)+carry;
              carry = (*p) / DEC_PACK_POWER;
              *p %= DEC_PACK_POWER;
              }
           *q |= carry<<block;

           if (new_v)
              {
              if (carry) new_v = FALSE;
              }
           else *bits -= BIN_PACK;
           }

        while (--dp>=0)
           {
           if (pd[dp])
               {
               d[*a_e] |= LSB;
               break;
               }
           }

        return;
        }
