/**************************************************************************/
/*                                                                        */
/*                                 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_out.c,v 1.2 1997/09/25 17:04:49 ae59 Exp $ */
/*
$Log: b_out.c,v $
 * Revision 1.2  1997/09/25  17:04:49  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:33  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_out.c                               */
/*                                                              */
/*      Entries         : void b_out                            */
/*                        (mant,expo,digits,buffer,bdp,dexpo)   */
/*                        a_btyp *mant;                         */
/*                        a_intg *dexpo,digits,expo,*bdp;       */
/*                        char *buffer;                         */
/*                                                              */
/*      Arguments       : expo - exponent of IEEE value         */
/*                        mant - mantissa of IEEE value         */
/*                        digits - number of digits             */
/*                        buffer - output string                */
/*                        bdp - position of decimal point       */
/*                        dexpo - decimal exponent of first     */
/*                                non-zero digit                */
/*                                dexpo<0 : float format        */
/*                                dexpo>=0: fixed format        */
/*                                                              */
/*                                                              */
/*      Description     : Decimal representation determined from*/
/*                        exponent and mantissa of IEEE value   */
/*                                                              */
/*      Date            : 1991-01-29                            */
/*      1991-01-29 : B_ASHR() arithmetic shuft right.           */
/*      1990-07-12 : LINT_ARGS prototype, cm renamed            */
/****************************************************************/

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

#ifdef LINT_ARGS
local void b_out(a_btyp *mant,a_intg expo,a_intg digits,char *buffer,
                 a_intg *bdp,a_intg *dexpo)
#else
local void b_out(mant,expo,digits,buffer,bdp,dexpo)

a_btyp *mant;
a_intg expo;
a_intg digits;
char *buffer;
a_intg *bdp;
a_intg *dexpo;
#endif
        {
        a_intg i,k;

        /* allign mantissa to dotprecision              */
        k = B_ASHR(expo,LOG_B_LENGTH);
        if ( (i = (expo & (B_LENGTH-1))-EXPO_SHIFT) <0)
             {
#if C_P_3
             mant[2] = (mant[2]>>-i) | (mant[1]<<(B_LENGTH+i));
             mant[1] = (mant[1]>>-i) | (mant[0]<<(B_LENGTH+i));
             mant[0] = (mant[0]>>-i);
#else
             b_shru(mant,D_U_RATIO+1,-i);
#endif
             }
        else if (i>0)
             {
#if C_P_3
             mant[0] = (mant[0]<<i) | (mant[1]>>(B_LENGTH-i));
             mant[1] <<= i;
#else
             b_shlu(mant,D_U_RATIO,i);
#endif
             }

        b_cm__[A_BEGIN] = A_D_P-k;
        b_cm__[A_END] = (A_D_P+D_U_RATIO)-k;

   /* copy value to I/O-buffer                                  */
        for (i=D_U_RATIO;i>=0;i--)
             b_cm__[A_D_P-k+i] = mant[i];

   /* clear accu contents between number and decimal point      */
        for (i=(A_D_P+D_U_RATIO+1)-k;i<=A_D_P;i++)
            b_cm__[i] = ZERO;
        for (i=A_D_P+1;i<=(A_D_P-1)-k;i++)
            b_cm__[i] = ZERO;

/*                                                                   */
/* conversion of integer part                                        */
/*                                                                   */
        if (expo>=0) {
            b_outi(&digits,buffer,bdp,dexpo,b_cm__);
            }

/*                                                                   */
/* conversion of fraction part                                       */
/*                                                                   */
        if (digits>0) {
            b_outf(&digits,buffer,bdp,dexpo,b_cm__);
            }

        return;
        }
