/**************************************************************************/
/*                                                                        */
/*                                 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: l_trun.c,v 1.2 1997/09/25 17:40:11 ae59 Exp $ */
/*
$Log: l_trun.c,v $
 * Revision 1.2  1997/09/25  17:40:11  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:33  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : l_trun.c                              */
/*                                                              */
/*      Entries         : a_intg l_trun(a)                      */
/*                        multiprecision a;                     */
/*                                                              */
/*      Arguments       : a = INTERN value                      */
/*                                                              */
/*      Description     : Truncate INTERN value to integer.     */
/*                                                              */
/*      Date            : 1990-11-22                            */
/*      1990-11-22 : E_TPUSH+E_TPOPP                            */
/*      1990-10-30 : temporary flag                             */
/*      1990-07-16 : LINT_ARGS prototype                        */
/****************************************************************/

#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 l_trun(multiprecision a)
#else
local a_intg l_trun(a)

multiprecision a;
#endif
        {
        a_intg res = 0;

        E_TPUSH("l_trun")

        if (a->z)
           {
           }
        else if (a->e>0 || (a->e==0 && (a->m[0] & MSB)))
           e_trap(OVERFLOW,4,E_TMSG,15,E_TMLT+E_TEXT(7),&a);
        else if (a->e==0)
           {
           if (a->s)
#if C_P_2
              res = -a->m[0];
#else
              res = ~(a->m[0])+1;
#endif
           else
              res = a->m[0];
           }

        if (a->f) l_free(&a);

        E_TPOPP("l_trun")
        return(res);
        }
