/**************************************************************************/
/*                                                                        */
/*                                 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_merr.c,v 1.2 1997/09/25 18:20:13 ae59 Exp $ */
/*
$Log: t_merr.c,v $
 * Revision 1.2  1997/09/25  18:20:13  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:41  ae59
 * Put under RCS control
 *
 */
/*      Date    : 1991-09-06                                    */
/*      1991-09-06 : reduce maximum line length                 */

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

#ifdef LINT_ARGS
#ifdef ANSI_C
static int err_ext_to_int(const ExtReal *arg, ExtReal *res);
#else  /* NOT ANSI_C */
static int err_ext_to_int(ExtReal *arg, ExtReal *res);
#endif /* ANSI_C */
#else  /* NOT LINT_ARGS */
static int err_ext_to_int();
#endif /* LINT_ARGS */

/*-------------------------------------------------------------------*
 | ieee err                                                          |
 | vom Anwender erweiterbar                                          |
 |                                                                   |
 | falls return == TakeOver wird der Wert fuer x->res als            |
 | Funktionswert und                                                 |
 | x->type als Rueckgabewert der Funktion uebernommen                |
 | es tritt dann kein Standard Fehlerbehandlung in Aktion            |
 | x->type = -1 ==> x->res wird direkt ohne Fehlermeldung als        |
 |                  Funktionswert verwendet                          |
 | x->type = 0  ==> nicht unbedingt sinnvoll, unterbrochene Funktion |
 |                  wird mit dem Originalargument ausgefuehrt        |
 | x->type > 0  ==> es erfolgt eine Fehlermeldung, in den makehead-  |
 |                  Rahmen erfolgt Programmabbruch                   |
 *-------------------------------------------------------------------*/
#ifdef LINT_ARGS
int ieee_matherr(struct ieee_exception *x)
#else
int ieee_matherr(x)
struct ieee_exception *x;
#endif /* LINT_ARGS */
{
/*   printf("von  ieee_matherr()\n"); */

   switch(x->type) {
   case DOMAIN:
      if(0==strcmp(x->name, "extreal_to_int"))
         return err_ext_to_int(&(x->arg1->u), &(x->res->u));
      break;
   case SING:
      break;
   case OVER_FLOW:
      break;
   case PLOSS:
      break;
   case TLOSS:
      break;
   case UNDER_FLOW:
      if(0==strcmp(x->name, "exp"))
      {
        copyee(&Zero, &(x->res->u));
        x->type = -1;
        return(TakeOver);
      }
      break;
   default:
      break;
   }

/*   printf("Ende ieee_matherr()\n\n"); */
   /* --- keine eigene Massnahme getroffen --- */
   return NoTakeOver;
} /* ieee_err() */

/*--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
static int err_ext_to_int(const ExtReal *arg, ExtReal *res)
#else
static int err_ext_to_int(arg, res)
const ExtReal *arg;
      ExtReal *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
static int err_ext_to_int(ExtReal *arg, ExtReal *res)
#else
static int err_ext_to_int(arg, res)
ExtReal *arg;
ExtReal *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   extern ExtReal IntMax;
   extern ExtReal IntMin;

   if(SGNE(arg)==NEG)
      copyee(&IntMin, res);
   else
      copyee(&IntMax, res);
   return TakeOver;
} /* err_ext_to_int() */
