/**************************************************************************/
/*                                                                        */
/*                                 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: l_mant.c,v 1.2 1997/09/25 17:36:50 ae59 Exp $ */
/*
$Log: l_mant.c,v $
 * Revision 1.2  1997/09/25  17:36:50  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:23  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : l_mant.c                              */
/*                                                              */
/*      Entries         : multiprecision l_mant(a)              */
/*                        multiprecision a;                     */
/*                                                              */
/*      Description     : Normalized mantissa of multiprecision */
/*                        value.                                */
/*                        0.5 <= |mantissa| < 1.0               */
/*                                                              */
/*      Note            : 0.0 returned if argument is 0.0       */
/*                                                              */
/*      Date            : 1991-08-28                            */
/*      1991-08-28 : a->z==0 instead of a->z!=0                 */
/*      1990-11-15 : E_TPUSH+E_TPOPP / consider temporary flag  */
/****************************************************************/

#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 multiprecision l_mant(multiprecision a)
#else
local multiprecision l_mant(a)

multiprecision a;
#endif
        {
        multiprecision res;
        a_btyp m;
        a_intg n;

        E_TPUSH("l_mant")

        l_init(&res);

        if (res==NULL)
           e_trap(ALLOCATION,2,E_TMSG,65);
        else if (a->z==0)
           {
           n = 0;
           m = a->m[0];
           while ((m & MSB)==ZERO)
              {
              n++;
              m <<= 1;
              }

           if (n) n = b_bshf(n,a,res);
           else n = b_bcpy(a,res);
           res->e = 0;

           if (n==ALLOC)
              e_trap(ALLOCATION,2,E_TMSG,65);
           }

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

        E_TPOPP("l_mant")
        return(res);
        }
