/**************************************************************************/
/*                                                                        */
/*                                 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: a_mod_.c,v 1.2 1997/09/25 16:52:18 ae59 Exp $ */
/*
$Log: a_mod_.c,v $
 * Revision 1.2  1997/09/25  16:52:18  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:20:46  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : a_mod_.c                              */
/*                                                              */
/*      Entries         : a_intg a_mod_(i,j)                    */
/*                        a_intg i,j;                           */
/*                                                              */
/*      Arguments       : i = left integer argument             */
/*                        j = right integer argument            */
/*                                                              */
/*      Description     : Integer modulo according to           */
/*                        PASCAL Standard:                      */
/*                           error if j is non-positive         */
/*                           0 <= i mod j = i-k*j < j           */
/*                                          for integral k      */
/*                                                              */
/*      Note            : 0 returned in case of error           */
/*                                                              */
/*      Date            : 1990-11-15                            */
/*      1990-11-15 : E_TPUSH+E_TPOPP                            */
/*      1990-10-24 : NO_ERROR replaced by INV_ARG               */
/*      1990-07-25 : modulo =j if i<0 : explicit compare        */
/****************************************************************/

#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 a_mod_(a_intg i,a_intg j)
#else
local a_intg a_mod_(i,j)

a_intg i;
a_intg j;
#endif
        {
        a_intg res;

        E_TPUSH("a_mod_")

        if (j<=0)
           {
           e_trap(INV_ARG,6,E_TMSG,22,E_TINT+E_TEXT(1),&i,
                                      E_TINT+E_TEXT(2),&j);
           res = 0;
           }
        else if (i<0)
           {
           if (i==MININT) i += j;
           if ((res = i+j+((-i)/j)*j)==j) res = 0;
           }
        else
           res = i-(i/j)*j;

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

