/**************************************************************************/
/*                                                                        */
/*                                 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_succ.c,v 1.2 1997/09/25 17:39:37 ae59 Exp $ */
/*
$Log: l_succ.c,v $
 * Revision 1.2  1997/09/25  17:39:37  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:31  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : l_succ.c                              */
/*                                                              */
/*      Entries         : multiprecision l_succ(a)              */
/*                        multiprecision a;                     */
/*                                                              */
/*      Description     : Successor of multiprecision value     */
/*                        within screen of mantissa length Maxl.*/
/*                        If a=0, +2**(-32*Maxl) is returned.   */
/*                                                              */
/*      Date            : 1991-12-10                            */
/*      1991-12-10 : in case of a==0 negate exponent            */
/*      1990-11-15 : E_TPUSH+E_TPOPP / consider temporary flag  */
/*      1990-08-06 : ->m[0]==ZERO (not assignment)              */
/****************************************************************/

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

#ifdef LINT_ARGS
local multiprecision l_succ(multiprecision a)
#else
local multiprecision l_succ(a)

multiprecision a;
#endif
        {
        multiprecision res;

        E_TPUSH("l_succ")

        l_init(&res);

        if (res==NULL)
           e_trap(ALLOCATION,2,E_TMSG,65);
        else if (a->z)
           {
           res->z = FALSE;
           res->s = FALSE;
           res->e = -b_maxl;
           res->l = 1;
           if (b_ball(1,&res->m))
              {
              e_trap(ALLOCATION,2,E_TMSG,65);
              res->z = TRUE;
              res->l = 0;
              }
           else
              res->m[0] = LSB;
           }
        else
           {
           if (b_ball(b_maxl,&res->m))
              {
              e_trap(ALLOCATION,2,E_TMSG,65);
              res->z = TRUE;
              res->l = 0;
              E_TPOPP("l_succ")
              return(res);
              }
           res->z = FALSE;
           res->s = a->s;
           res->l = b_maxl;
           res->e = a->e;
           if (a->l<b_maxl)
              B_COPY(res->m,a->m,a->l)
           else
              B_COPY(res->m,a->m,b_maxl)

           if (NOT(res->s))
              {
              if (b_bcad(b_maxl,res->m))
                 {
                 if (res->e==MAXINT)
                    e_trap(OVERFLOW,2,E_TMLT+E_TEXT(7),&a);
                 else
                    {
                    res->e++;
                    res->m[0] = LSB;
                    }
                 }
              }
           else if (b_test(a->l-b_maxl,&a->m[b_maxl]))
              {
              (void)b_bcsu(b_maxl,res->m);
              if (res->m[0]==ZERO)
                 {
                 if (res->e==-MAXINT)
                    e_trap(UNDERFLOW,2,E_TMLT+E_TEXT(7),&a);
                 else
                    {
                    res->e--;
                    res->m[0] = MAX_BASETYPE;
                    }
                 }
              }
           }

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

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