/**************************************************************************/
/*                                                                        */
/*                                 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_sign.c,v 1.2 1997/09/25 17:50:28 ae59 Exp $ */
/*
$Log: r_sign.c,v $
 * Revision 1.2  1997/09/25  17:50:28  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:12  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_sign.c                              */
/*                                                              */
/*      Entries         : a_intg r_sign(a)                      */
/*                        a_real a;                             */
/*                                                              */
/*      Arguments       : a = real value                        */
/*                                                              */
/*      Description     : Sign of normalized IEEE value.        */
/*                                                              */
/*      Function value  : -1 if value is negative               */
/*                         0 if value is zero or error occurred */
/*                         1 if value is positive               */
/*                       error if quiet or signaling NaN        */
/*                                                              */
/*      Date            : 1993-12-07                            */
/*      1993-12-07 : replaced b_deko call by code (optimi.)=b=  */
/*      1992-11-23 : add E_ieee for e_trap(INV_op =b=           */
/*      1991-04-23 : MANT_INFINITY() used                       */
/*      1991-04-22 : messages changed in e_trap()               */
/*      1991-01-07 : SIGNALING macro introduced                 */
/*      1990-11-20 : E_TPUSH+E_TPOPP                            */
/*      1990-11-12 : INV_OP                                     */
/****************************************************************/

#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_sign(a_real a)
#else
local a_intg r_sign(a)

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

        E_TPUSH("r_sign")

        /* decompose IEEE value                                 */

        u = (a_btyp *)&a;


        /* sign of real value   */
        vza = (u[B_HPART] & MSB) ? TRUE : FALSE;


        /* exponent of number   */
        if ((expoa = ((u[B_HPART] & EXPO_MASK)>>EXPO_SHIFT)-CHARAC)
            ==-CHARAC)
           {
		 /* zero exponent field*/

           /* high part of mantissa */
           manta[0] = (u[B_HPART] & MANT_HIGH) | HIDDEN_BIT;

           /* value is zero     */
           if (!((manta[0] &= NOT_HIDDEN_BIT) | u[B_LPART]))
		 {
              expoa=0;
		    goto _ready;
	 	 }
           /* denormalized number  */
           expoa = -CHARAC+1;
           }



        if (expoa>EXPO_MAX)
           {
           /* low part of mantissa */
           manta[1] = u[B_LPART];

           /* high part of mantissa */
           manta[0] = (u[B_HPART] & MANT_HIGH) | HIDDEN_BIT;

           /* check for infinity */
           if (MANT_INFINITY(manta))
              expoa = (vza) ? -1 : 1;
           else
              {
              if (SIGNALING(manta[0]))
                 e_trap(INV_OP+E_IEEE,4,E_TMSG,5,E_TDBL+E_TEXT(7),&a);
              else
                 e_trap(INV_OP+E_IEEE,4,E_TMSG,14,E_TDBL+E_TEXT(7),&a);
              expoa = 0;
              }
           }
        else
           expoa = (vza) ? -1 : 1;
_ready:
        E_TPOPP("r_sign")
        return(expoa);
        }


