/**************************************************************************/
/*                                                                        */
/*                                 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: b_inv1.c,v 1.2 1997/09/25 17:03:10 ae59 Exp $ */
/*
$Log: b_inv1.c,v $
 * Revision 1.2  1997/09/25  17:03:10  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:26  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_inv1.c                              */
/*                                                              */
/*      Entries         : a_btyp b_inv1(func,arg,res,rnd)       */
/*                        int (*func)();                        */
/*                        a_real arg,*res;                      */
/*                        a_intg rnd;                           */
/*                                                              */
/*      Arguments       : func = function to be evaluated for   */
/*                               a given real argument          */
/*                        arg  = argument of function           */
/*                        res  = result of function             */
/*                        rnd  = rounding                       */
/*                               <0 : downwards                 */
/*                               =0 : nearest                   */
/*                               >0 : upwards                   */
/*                                                              */
/*      Function value  : function dependent return code.       */
/*                                                              */
/*      Description     : evaluate a function for a given       */
/*                        real argument.                        */
/*                                                              */
/*      Date            : 1991-01-08                            */
/*      1991-01-08 : b_rtol() with rounding argument            */
/*      1990-07-13 : LINT_ARGS prototype, Maxl renamed          */
/*      1990-08-02 : prototype completed                        */
/****************************************************************/

#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 a_btyp b_inv1(int (*func)(multiprecision,multiprecision),
                      a_real arg,a_real *res,a_intg rnd)
#else
local a_btyp b_inv1(func,arg,res,rnd)

int (*func)();
a_real arg;
a_real *res;
a_intg rnd;
#endif
        {
        a_intg code;
        multiprecision l_arg,l_res;
        a_btyp rc;
        a_btyp Oldb_maxl;

        l_init(&l_arg);
        l_init(&l_res);

        if (b_rtol(arg,&l_arg,(a_intg)0)) return(ALLOCATION);

        Oldb_maxl = b_maxl;
        b_maxl = 3;

        code = (*func)(l_arg,l_res);

        b_maxl = Oldb_maxl;

        rc = b_ltor(l_res,res,rnd);

        l_free(&l_arg);
        l_free(&l_res);

        return((code)?(a_btyp)code:rc);
        }
