/**************************************************************************/
/*                                                                        */
/*                                 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: r_rval.c,v 1.2 1997/09/25 17:50:00 ae59 Exp $ */
/*
$Log: r_rval.c,v $
 * Revision 1.2  1997/09/25  17:50:00  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:10  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_rval.c                              */
/*                                                              */
/*      Entries         : a_real r_rval(s,rnd)                  */
/*                        s_trng s;                             */
/*                        a_intg rnd;                           */
/*                                                              */
/*      Arguments       : s   - input string                    */
/*                        rnd - rounding mode                   */
/*                              -1 = rounding downwards         */
/*                               0 = round to nearest           */
/*                               1 = round upwards              */
/*                                                              */
/*      Description     : Convert a character string            */
/*                        to IEEE double format                 */
/*                                                              */
/*      Date            : 1991-04-22                            */
/*      1991-04-22 : real assignment replaced by R_ASSIGN()     */
/*      1991-02-21 : (a_char *) cast in r_conv()                */
/*      1991-02-13 : copy string if static                      */
/*      1991-01-22 : r_ass() used                               */
/*      1990-12-05 : b_cp__ removed                             */
/*      1990-11-22 : replace strncpy by memcpy                  */
/*      1990-11-20 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

#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_zero;
#endif

#ifdef LINT_ARGS
local a_real r_rval(s_trng s,a_intg rnd)
#else
local a_real r_rval(s,rnd)

s_trng s;
a_intg rnd;
#endif
        {
        a_real res;
        a_char *next;
        char ch;

        E_TPUSH("r_rval")

        if (s.clen<=0)
           {
           R_ASSIGN(res,*r_zero);
           e_trap(I_O_ERROR,2,E_TMSG,58);
           }
        else if (s.clen>=BUFFERSIZE)
           {
           R_ASSIGN(res,*r_zero);
           e_trap(I_O_BUFFER,2,E_TMSG,56);
           }
        else
           {
           if (s.suba) s_asgn(&s,s);
           ch = s.ptr[s.clen];
           s.ptr[s.clen] = '\0';

           r_conv((a_char *)s.ptr,&res,rnd,&next);

           s.ptr[s.clen] = ch;
           }

        if (s.tmp) s_free(&s);

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