/**************************************************************************/
/*                                                                        */
/*                                 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: r_expo.c,v 1.2 1997/09/25 17:46:04 ae59 Exp $ */
/*
$Log: r_expo.c,v $
 * Revision 1.2  1997/09/25  17:46:04  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:58  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_expo.c                              */
/*                                                              */
/*      Entries         : a_intg r_expo(m)                      */
/*                        a_real m;                             */
/*                                                              */
/*      Arguments       : m = mantissa                          */
/*                                                              */
/*      Description     : Base 2 exponent of mantissa with      */
/*                        0.5 <= |mantissa| < 1.0.              */
/*                                                              */
/*      Note            : -MAXINT is returned if r==0.0.        */
/*                         MAXINT is returned if r=+/-infinity  */
/*                        qNaN causes an INV_ARG exception      */
/*                        sNaN causes an INV_OP  exception      */
/*                                                              */
/*      Date            : 1992-11-23                            */
/*      1992-11-23 : add E_ieee for e_trap(INV_op ... =b=       */
/*      1991-05-20 : new normalization                          */
/*      1991-04-23 : MANT_INFINITY() used                       */
/*      1991-02-27 : e_trap() arguments changed / only if NaN   */
/*      1991-01-31 : Changes made according to Note.            */
/*      1990-11-19 : E_TPUSH+E_TPOPP                            */
/*      1990-09-03 : mantissa ranges changed                    */
/*      1990-07-16 : return 0 if argument is 0.0                */
/****************************************************************/

#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_intg r_expo(a_real m)
#else
local a_intg r_expo(m)

a_real m;
#endif
        {
        a_bool vz;
        a_intg expo;
        a_btyp mant[D_U_RATIO];

        E_TPUSH("r_expo")

        if (b_deko(m,&expo,mant,&vz))
           {
           expo = -MAXINT;
           }
        else if (expo>EXPO_MAX)
           {
           if (MANT_INFINITY(mant))
              expo = MAXINT;
           else if (SIGNALING(mant[0]))
              e_trap(INV_OP+E_IEEE,4,E_TMSG,5,E_TDBL+E_TEXT(7),&m);
           else
              e_trap(INV_ARG,2,E_TDBL+E_TEXT(7),&m);
           }
        else
           {
           expo++;
           if ((mant[0] & HIDDEN_BIT)==ZERO)
              {
              do {
                 b_shl1(mant,D_U_RATIO);
                 expo--;
                 }
              while ((mant[0] & HIDDEN_BIT)==ZERO);
              }
           }

        E_TPOPP("r_expo")
        return(expo);
        }

