Metropoli BBS
VIEWER: formath.c MODE: TEXT (ASCII)
/*Copyright (C) 1992, 1994 by Thomas Glen Smith.  All Rights Reserved.*/
/** formath APL2 V1.0.0 ************************************************
* Called from formatg and formatz to format an element.                *
***********************************************************************/
#define INCLUDES LIMITS+STDIO+STRING
#include "includes.h"
void formath(d,cp,width,precisn,digits,fch)
double d;		/* Value t/b formatted. */
char *cp; 	/* Output location. */
int width;	/* Width of output. */
int precisn;	/* Places output right of d.p. */
int digits;	/* Places output left of d.p. */
char *fch;	/* Lfc string. */
{
	Chrcopy; Formben; Formbfn;
	extern int apldigs, aplerr;
	Imin;
	char ch,dh,format[80],*ip,*jp,*kp,*op,output[80];
	int i,j,k,m,ovflo;

	output[0] = '\0';
	if (precisn >= 0) { /* f-notation */
		ovflo = formbfn(d,cp,width,precisn,digits,fch,output);
		if (ovflo)
			return; /* Return after overflow condition. */
	}
	else /* e-notation */
		ovflo = formben(d,cp,width,precisn,digits,fch,output);
	ip=output;
	i = j = imin(strlen(output),width);
	for (k = width - j; k > 0; k--) *cp++ = ' '; /* fill with blanks */
	if ('.' == (ch = *fch)) /* Lfc[1] == '.'? */
		while (i--) *cp++ = *ip++; /* Copy as is. */
	else while (i--) /* Replace decimal point with Lfc[1]. */
		*cp++ = ('.' == (dh = *ip++)) ? ch : dh;
}
[ RETURN TO DIRECTORY ]