/**************************************************************************/
/*                                                                        */
/*                                 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: t_scee.c,v 1.2 1997/09/25 18:21:55 ae59 Exp $ */
/*
$Log: t_scee.c,v $
 * Revision 1.2  1997/09/25  18:21:55  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:46  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_scee.c                              */
/*                                                              */
/*      Date    : 1991-09-06                                    */
/*      1991-09-06 : reduce maximum line length                 */
/*      1991-08-05 : remove unused variables e                  */
/*      1991-06-21 : new routine                                */
/****************************************************************/

#ifdef AIX
#include "/u/p88c/runtime/tbyte/t_defs.h"
#else
#include "t_defs.h"
#endif

/* #include <stdlib.h> */
/* already included by o_defs.h
#ifdef LINT_ARGS
extern int abs(int);
#else
extern int abs();
#endif
*/

/*--------------------------------------------------------------*
 | scaliee                                                      |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int scaliee (const ExtReal *arg, int intarg, ExtReal *res)
#else
int scaliee (arg, intarg, res)
const ExtReal  *arg;
      int      intarg;
      ExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int scaliee (ExtReal *arg, int intarg, ExtReal *res)
#else
int scaliee (arg, intarg, res)
ExtReal  *arg;
int      intarg;
ExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   int         e;          /* Exponent des Argumentes           */

   /* --- bei 0 fertig --- */
   if(0==cmpee(arg, &Zero))
      return copyee(arg, res);

   /* --- extrahiere Exponenten --- */
   e = (int)((arg->s.exp & (ExtExpMask)) - ExtExpBias);

   /* --- Pruefe auf DOMAIN --- */
   if(abs(e+intarg) > ExtExpBias) return DOMAIN;

   /* --- Setzt res --- */
   copyee(arg, res);
   res->s.exp += intarg;

   /* --- kein Fehler mehr moeglich --- */
   return NoErr;
} /* scaliee() */

/*--------------------------------------------------------------*
 | scalee                                                       |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int scalee (const ExtReal *arg, const ExtReal *intarg, ExtReal *res)
#else
int scalee (arg, intarg, res)
const ExtReal  *arg;
const ExtReal  *intarg;
      ExtReal  *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int scalee (ExtReal *arg, ExtReal *intarg, ExtReal *res)
#else
int scalee (arg, intarg, res)
ExtReal  *arg;
ExtReal  *intarg;
ExtReal  *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   int         a;          /* (int) intarg                      */
   int         rnd;        /* RundungsMode                      */
   int         ret;        /* Rueckgabe                         */

   /* --- RundungsMode sichern, CHOP setzen --- */
   rnd  = getrndmode();
   setrndmode(CHOP);

   /* --- Konvertierung nach int, falls fehlerfrei scaliee --- */
   if(NoErr==(ret=extreal_to_int(intarg, &a)))
      ret = scaliee(arg, a, res);

   /* --- RundungsMode zuruecksetzen --- */
   setrndmode(rnd);

   return ret;
} /* scalee() */
