/**************************************************************************/
/*                                                                        */
/*                                 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_pred.c,v 1.2 1997/09/25 17:49:25 ae59 Exp $ */
/*
$Log: r_pred.c,v $
 * Revision 1.2  1997/09/25  17:49:25  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:08  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_pred.c                              */
/*                                                              */
/*      Entries         : a_real r_pred(a)                      */
/*                        a_real a;                             */
/*                                                              */
/*      Arguments       : a = real value                        */
/*                                                              */
/*      Function value  : Preceding normalized IEEE value.      */
/*                                                              */
/*      Description     : Preceding normalized IEEE value.      */
/*                        -infinity returned if overflow.       */
/*                        largest negative normalized or        */
/*                        denormalized number returned if a==0. */
/*                                                              */
/*      Note            : argument returned if NaN or infinity  */
/*                                                              */
/*      Date            : 1991-09-06                            */
/*      1991-09-06 : reduce maximum line length                 */
/*      1991-02-25 : extend to denormalized numbers             */
/*      1990-11-20 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

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

#ifdef LINT_ARGS
local a_real r_pred(a_real a)
#else
local a_real r_pred(a)

a_real a;
#endif
        {
        a_intg expoa;
        a_bool vza;
        a_btyp manta[D_U_RATIO];

        E_TPUSH("r_pred")

        /* decompose IEEE value                                 */
        if (b_deko(a,&expoa,manta,&vza))
           {
           vza = TRUE;
           expoa = EXPO_MIN;
#ifdef NORMALIZE_ENABLE
           if (f_ppdn)
              manta[0] = HIDDEN_BIT;
           else
#endif
              manta[1] = LSB;
           }
        else if (expoa>EXPO_MAX)
           {
           E_TPOPP("r_pred")
           return(a);
           }
        else if (vza)
           {
           b_addc(manta+(D_U_RATIO-1));
           if (SHFT_MASK & *manta) {
#if C_P_3
              manta[1] =
                 (manta[1]>>1) | (manta[0]<<(B_LENGTH-1));
              manta[0] >>= 1;
#else
              b_shr1(manta,D_U_RATIO);
#endif
              expoa++;
              }
           }
        else
           {
           b_subc(manta+(D_U_RATIO-1));
           if ((HIDDEN_BIT & *manta)==ZERO)
              {
              if (--expoa<EXPO_MIN)
                 {
#ifdef NORMALIZE_ENABLE
                 if (f_ppdn)
                    {
#if C_P_3
                    manta[0] = manta[1] = ZERO;
#else
                    B_CLEAR(manta,(a_intg)D_U_RATIO);
#endif
                    vza = FALSE;
                    }
                 else
#endif
                    {
                    expoa = EXPO_MIN;
                    }
                 }
              else
                 {
#if C_P_3
                 manta[0] = (manta[0]<<1) |
                            (manta[1]>>(B_LENGTH-1));
                 manta[1] <<= 1;
#else
                 b_shl1(manta,(a_intg)D_U_RATIO);
#endif
                 manta[D_U_RATIO-1] |= LSB;
                 }
              }
           }

        /* compose result                                       */
        b_comp(&a,expoa,manta,vza);

        E_TPOPP("r_pred")
        return(a);
        }
