/**************************************************************************/
/*                                                                        */
/*                                 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: i_loga.c,v 1.2 1997/09/25 17:29:55 ae59 Exp $ */
/*
$Log: i_loga.c,v $
 * Revision 1.2  1997/09/25  17:29:55  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:00  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : i_loga.c                              */
/*                                                              */
/*      Entries         : a_intv i_loga(x,base)                 */
/*                        a_intv x;                             */
/*                        a_real base;                          */
/*                                                              */
/*      Arguments       : base = base                           */
/*                      : x = interval argument of function     */
/*                                                              */
/*      Description     : Interval logarithm to base base       */
/*                                                              */
/*      Date            : 1991-11-14                            */
/*      1991-11-14 : save and restore flags                     */
/*      1991-02-21 : extern L...() declaration removed          */
/*      1991-01-22 : compare with r_zero replaced by r_sign()   */
/*      1990-11-22 : explicit compare                           */
/*      1990-10-18 : real constants / arguments switched        */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
extern a_real *r_two_,*r_ten_,*r_one_;
#endif

#ifdef LINT_ARGS
local a_intv i_loga( a_intv x, a_real base)
#else
local a_intv i_loga( x, base )
a_intv x;
a_real base;
#endif

{
        a_btyp        rc;
        a_intv          res;
        a_real            dummy;

        E_SPUSH("i_loga")

        rc= 0;

        /* printf("x in i_loga:  %lf   %lf %lf\n", x.INF, x.SUP, base); */

        if (r_eq(base,*r_two_)) {
          res = i_log2(x);
        }
        else if (r_eq(base,*r_ten_)) {
          res = i_log(x);
        }
        /* --- invalid argument --- */
        else if (r_sign(x.INF)<=0) {
          rc = 1;
        }
        /* --- invalid base --- */
        else if ( r_sign(base)<=0 || r_eq(base,*r_one_) ) {
          rc = 1;
        }
        /* --- point argument --- */
        else if ( i_point(x) ) {
            /* printf("point argument!\n"); */
            rc =  i_inv2(Lloga,x.INF,base,&res.INF,&res.SUP);
        }

        /* --- interval argument --- */
        else if ((rc = i_iv(x))!=0) {
            /* printf("interval argument!\n"); */
            rc =  i_inv2(Lloga,x.INF,base,&res.INF,&dummy);
            rc += i_inv2(Lloga,x.SUP,base,&dummy,&res.SUP);
        }
        /* --- invalid argument --- */
        else rc = 1;

        /* --- error --- */
        if (rc) {
            e_trap(INV_ARG,5,E_TDBL+E_TEXT(17),&base,
                             E_TDBL+E_TEXT(5),&x.INF,
                             E_TDBL+E_TEXT(6),&x.SUP);
        }

        /* --- exit --- */
        E_SPOPP("i_loga")
        return(res);
        }
