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

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

#ifdef LINT_ARGS
#ifdef ANSI_C
static int mantcmp(const Digit arg1[], const Digit arg2[]);
#else
static int mantcmp(Digit arg1[], Digit arg2[]);
#endif /* ANSI_C */
#else  /* NOT LINT_ARGS */
static int mantcmp();
#endif /* LINT_ARGS */
/*--------------------------------------------------------------*
 | cmpee                                                        |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int cmpee (const ExtReal *arg1, const ExtReal *arg2)
#else
int cmpee (arg1, arg2)
const ExtReal  *arg1;
const ExtReal  *arg2;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int cmpee (ExtReal *arg1, ExtReal *arg2)
#else
int cmpee (arg1, arg2)
ExtReal  *arg1;
ExtReal  *arg2;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   unsigned int   s1, s2;
   int   e1, e2;
   int   m;

   /* --- compare sign --- */
   s1 = arg1->s.exp&ExtSignMask;
   s2 = arg2->s.exp&ExtSignMask;
   if(s1!=s2)
      if(arg1->s.DIGIT(7)!=0&&arg2->s.DIGIT(7)!=0)
         return (int)(s1 > s2 ? -1 : 1);

   /* --- compare exponent --- */
   e1 = (arg1->s.exp&ExtExpMask);
   e2 = (arg2->s.exp&ExtExpMask);
   if (e1!=e2)
      return (int)(e1>e2 ? (int)(s1==0?1:-1) : (int)(s2==0?-1:1));

   /* --- compare mant --- */           /* 130391 cb */
/* m = mantcmp(&(arg1->s.digit[0]), &(arg2->s.digit[0])); */
   m = mantcmp(arg1->s.digit, arg2->s.digit);
   return (int)(s1==0?m:-m);
} /* cmpee() */

/*--------------------------------------------------------------*
 | cmpabsee                                                     |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int cmpabsee (const ExtReal *arg1, const ExtReal *arg2)
#else
int cmpabsee (arg1, arg2)
const ExtReal  *arg1;
const ExtReal  *arg2;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int cmpabsee (ExtReal *arg1, ExtReal *arg2)
#else
int cmpabsee (arg1, arg2)
ExtReal  *arg1;
ExtReal  *arg2;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   ExtReal a1, a2;

   /* --- abs --- */
   absee(arg1, &a1);
   absee(arg2, &a2);

   /* --- cmpabs --- */
   return cmpee(&a1, &a2);
} /* cmpabsee() */

/*--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
static int mantcmp(const Digit arg1[], const Digit arg2[])
#else
static int mantcmp(arg1, arg2)
const Digit arg1[];
const Digit arg2[];
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
static int mantcmp(Digit arg1[], Digit arg2[])
#else
static int mantcmp(arg1, arg2)
Digit arg1[];
Digit arg2[];
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   register int i;

#if LSBFIRST
   for (i=ExtMantLen; --i>=0 && arg1[i]==arg2[i]; ) ;
   if (i<0) return(0);
   return (arg1[i]>arg2[i]? 1 : -1);
#else
   for (i=0; i<ExtMantLen && arg1[i]==arg2[i]; i++) ;
   if (i==ExtMantLen) return(0);
   return (arg1[i]>arg2[i] ? 1 : -1);
#endif
} /* mantcmp() */
