/**************************************************************************/
/*                                                                        */
/*                                 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_pi__.c,v 1.2 1997/09/25 17:05:16 ae59 Exp $ */
/*
$Log: b_pi__.c,v $
 * Revision 1.2  1997/09/25  17:05:16  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:35  ae59
 * Put under RCS control
 *
 */
/*************************************************************************
 *                                                                       *
 * Descriptive Name : Lpi                Processor : C                   *
 *                                                                       *
 * Function returning PI with current acurracy                           *
 * ===========================================                           *
 *                                                                       *
 * Include files :  b_lari.h  - definitions for INTERN standard functions*
 *                                                                       *
 * Function value : int       - 0                                        *
 *                                                                       *
 * Used Number Base :  2**32                                             *
 *                                                                       *
 * Used Functions :                                                      *
 *    LpiGen          Internal Routine to compute more digits of PI      *
 *    Lginit          Initialization of global constants                 *
 *                                                                       *
 * Used UNSIGNED Global Variables :                                      *
 *    Maxl            Length of INTERN Variables                         *
 *    Lcurrprec       Initial Length of INTERN Variables                 *
 *    Lgiflag         Flag for Initialization of Global INTERN Variables *
 *    Ldebug          Flag for printing additional information           *
 *                                                                       */
/*      Date            : 1991-09-09                            */
/*      1991-09-09 : reduce max. line length                    */
/*      1990-11-12 : undef removed                              *
 *      1990-09-04 : Larith.h replaced by b_lari.h              *
 *      1990-07-17 : LPiov4, L4ovPi moved to b_gini.c           *
 *************************************************************************/

#define  Name        "Lpi"
#define  Main

#define  PiMore      20

#ifdef AIX
#include "/u/p88c/runtime/base/b_lari.h"
#else
#include "b_lari.h"
#endif

static char  *function = Name;

/************************************************************
 * Algorithm                                                *
 ************************************************************/

#ifdef LINT_ARGS
int b_pi__(dynamic *pi)
#else
int b_pi__(pi)

dynamic *pi;
#endif
#define  LRoutine    "Lpi"
{
   extern a_btyp  Maxl;
   extern a_btyp  Lgiflag;
   extern char      *Lroutine;
   extern dynamic   LPiov4;

#ifdef Debug
   extern int       Ldebug;
#endif

   int       rc;
   a_btyp  Lcurrprec;  /* Necessary while Lsqrt is used ! */
#define poolvars  0

#ifdef Debug
   Ldebug -= 1;         /* Diminish Debug Level         */
   if (Ldebug >= 0) printf("\n Entering Routine %s",LRoutine);
#endif


  /*----------------*
   | Initialization |
   *----------------*/

   Lroutine = function;
   Lcurrprec = Maxl;            /* Save precision setting       */
   rc = 0;


  /**************************************************************
   * Initialization of Global Constants and Storage Locations   *
   **************************************************************/

   if (Lgiflag==0) Lginit();    /* Initialization of GLOBALS     */

#ifdef Debug
   if (Ldebug >= 0) {
      printf("\n  (Lpi 123) Maxl = %d\n",Maxl);
      }
#endif

   if (Maxl > LPiov4.l) {
/*    Maxl = 2*Maxl; */
      Maxl += PiMore;
      rc = LpiGen();
      Maxl = Lcurrprec;

#ifdef Debug
      if (Ldebug >= 0) {
         printf("\n  (Lpi 135) Maxl = %d\n",Maxl);
         }
#endif

      if (rc != 0) {
         ERREXIT(0,rc,0);       /* Error message and handling    */
         }
      }


   SHIFT_(2,&LPiov4,pi);
   if (rc != 0) {
      ERREXIT(rc,rc,0);         /* Error message and handling    */
      }
   pi->r = 1;

#ifdef Debug
   if (Ldebug >= 0) {
      printf("\n  (Lpi 153) Pi = ");  Lprinti(pi);
      }
#endif

   RETURN(0);
}
