/**************************************************************************/
/*                                                                        */
/*                                 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: s_real.c,v 1.2 1997/09/25 18:01:14 ae59 Exp $ */
/*
$Log: s_real.c,v $
 * Revision 1.2  1997/09/25  18:01:14  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:44  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : s_real.c                              */
/*                                                              */
/*      Entries         : s_trng s_real(s,Totalwidth,           */
/*                                    FracDigits,rnd)           */
/*                        a_real s;                             */
/*                        a_intg rnd,Totalwidth,FracDigits;     */
/*                                                              */
/*      Arguments       : s - IEEE value                        */
/*                        Totalwidth - total length of string   */
/*                        FracDigits - number of fraction digits*/
/*                        rnd - rounding mode                   */
/*                              -1 = round downwards            */
/*                               0 = round to nearest           */
/*                               1 = round upwards              */
/*                                                              */
/*      Description     : Convert an IEEE double format number  */
/*                        to a character string.                */
/*                                                              */
/*      Date            : 1991-01-17                            */
/*      1991-01-17 : (size_t) cast in s_init(),memcpy()         */
/*      1990-11-22 : E_TPUSH+E_TPOPP                            */
/*                   replace strncpy by memcpy                  */
/*      1990-10-16 : assign length to str.clen                  */
/*                   set default TotalWidth                     */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
extern dotprecision b_cp__;
#endif

#ifdef LINT_ARGS
local s_trng s_real(a_real s,a_intg TotalWidth,a_intg FracDigits,a_intg rnd)
#else
local s_trng s_real(s,TotalWidth,FracDigits,rnd)

a_real s;
a_intg TotalWidth;
a_intg FracDigits;
a_intg rnd;
#endif
        {
        s_trng str;
        a_intg length;
        char *buffer;

        E_TPUSH("s_real")

        buffer = (char *)&b_cp__[0];

        if (TotalWidth<=0)
           TotalWidth = ExpDigits+4+3*MANTL/10;

        r_outp(buffer,s,TotalWidth,FracDigits,rnd,&length);

        s_init(&str,(size_t)length);
        str.clen = str.alen;
        if (length>0 && str.ptr!=NULL)
           memcpy(str.ptr,buffer,(size_t)length);
        str.tmp = TRUE;

#ifdef HEAP_CHECK
b_tmph((a_char *)&str.ptr);
#endif

        E_TPOPP("s_real")
        return(str);
        }
