numcvt - format numeric value


#include <basic/string.h>
#include <basic/type.h>
#include <basic/generic.h>

int numcvt(s, type, generic)
char *s;
int type;
union generic generic;

char *docvt(type, generic, len, pdecpt, psign, eflag)
int type, len, *pdecpt, *psign, eflag;
union generic generic;


Numcvt formats the numeric value given by type, generic (see generic(inc)) and stores it (followed by a null character) in the string, sNumcvt returns one if the value is negative and zero otherwise. 

The format is that used by the PRINT statement.  Zero values are always formatted as “0”.  Other values are formatted in simple decimal notation or in a scientific notation similar to FORTRAN “E” notation.  Integers are always formatted in decimal notation, as are small floating point numbers.  Single-precision values which cannot be represented in 7 digits because of the magnitude of the exponent and double-precision values which cannot be represented in 20 digits are formatted in scientific notation.  Decimal notation is of the form “[-]ddddd” or “[-]ddd.ddd” if a fractional part exists.  Scientific notation is of the form “[-]d.dddddd” for single-precision and “[-]d.dddddd” for double-precision values.  The digits of the mantissa are formatted with docvt

Docvt formats the numeric value given by type, generic (see generic(inc)).  Docvt returns a pointer to a static area where the ASCII representation of the digits of the value’s mantissa are stored.  The string contains no decimal point.  Instead the position of the decimal point is stored in *pdecpt as an offset relative to the beginning of the string.  If the value is negative, *psign is set to non-zero, and is set to zero otherwise.  If eflag is set, a total of len digits are formatted.  Otherwise all significant digits to the left of the decimal point plus len digits to the right, are formatted.  The last digit is rounded.  To avoid the implementation dependent issues of precision and round-off error in floating point numbers, ecvt and fcvt (see ecvt(3)) are used for the basic conversion. 

These functions support other formatting functions and do not directly implement any BASIC functions. 


bwrite(io), print(io), strS(cvt), usenum(io), usfnum(io)
ecvt(3) in the UNIX Programmer’s Manual

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber