Mail Archives: djgpp/1995/02/21/04:58:33
>
> Hello everybody,
>
> is there a function that converts a float into a string (like
> ecvt, fcvt, and gcvt in TURBO C). I am converting "by hand" and want
> to know if there are some changes to the compiler now (wasn't there
> an e-,f-,gcvt entry in the info reader for GNU C 2.5.8? When I look
> into the new Info reader (that comes with GCC 2.6.x) I miss these
> entries [and I remember that I tried to use these functions with
> 2.5.8 without any success -> undefined references errors]).
>
> BTW: The TURBO C manual claims these funcions as "available on UNIX-
> Systems".
>
> Can anybody help?
>
> Thanks in advance,
>
> Armin
>
Hi,
I try a "man ecvt" on my UNIX station and it says that [efg]cvt are
obsolet ans that you should use [efg]convert instead.
On my station the declaration in include files are only : "char
*econvert()", it's minimalist so I send the man output too as I can't
check the DOS version at work.
------- man econvert ---------
NAME
econvert, fconvert, gconvert, seconvert, sfconvert, sgcon-
vert, ecvt, fcvt, gcvt - output conversion
SYNOPSIS
#include <floatingpoint.h>
char *econvert(value, ndigit, decpt, sign, buf)
double value;
int ndigit, *decpt, *sign;
char *buf;
char *fconvert(value, ndigit, decpt, sign, buf)
double value;
int ndigit, *decpt, *sign;
char *buf;
char *gconvert(value, ndigit, trailing, buf)
double value;
int ndigit;
int trailing;
char *buf;
char *seconvert(value, ndigit, decpt, sign, buf)
single *value;
int ndigit, *decpt, *sign;
char *buf;
char *sfconvert(value, ndigit, decpt, sign, buf)
single *value;
int ndigit, *decpt, *sign;
char *buf;
char *sgconvert(value, ndigit, trailing, buf)
single *value;
int ndigit;
int trailing;
char *buf;
char *ecvt(value, ndigit, decpt, sign)
double value;
int ndigit, *decpt, *sign;
char *fcvt(value, ndigit, decpt, sign)
double value;
int ndigit, *decpt, *sign;
char *gcvt(value, ndigit, buf)
double value;
int ndigit;
char *buf;
DESCRIPTION
econvert() converts the value to a null-terminated string of
ndigit ASCII digits in buf and returns a pointer to buf.
buf should contain at least ndigit+1 characters. The posi-
tion of the radix character relative to the beginning of the
string is stored indirectly through decpt. Thus buf ==
"314" and *decpt == 1 corresponds to the numerical value
3.14, while buf == "314" and *decpt == -1 corresponds to the
numerical value .0314. If the sign of the result is nega-
tive, the word pointed to by sign is nonzero; otherwise it
is zero. The least significant digit is rounded.
fconvert works much like econvert, except that the correct
digit has been rounded as if for sprintf(%w.nf) output with
n=ndigit digits to the right of the radix character. ndigit
can be negative to indicate rounding to the left of the
radix character. The return value is a pointer to buf. buf
should contain at least 310+max(0,ndigit) characters to
accomodate any double-precision value.
gconvert() converts the value to a null-terminated ASCII
string in buf and returns a pointer to buf. It produces
ndigit significant digits in fixed-decimal format, like
sprintf(%w.nf), if possible, and otherwise in floating-
decimal format, like sprintf(%w.ne); in either case buf is
ready for printing, with sign and exponent. The result
corresponds to that obtained by
(void) sprintf(buf, "%w.ng", value);
If trailing= 0, trailing zeros and a trailing point are
suppressed, as in sprintf(%g). If trailing!= 0, trailing
zeros and a trailing point are retained, as in sprintf(%#g).
seconvert, sfconvert, and sgconvert() are single-precision
versions of these functions, and are more efficient than the
corresponding double-precision versions. A pointer rather
than the value itself is passed to avoid C's usual conver-
sion of single-precision arguments to double.
ecvt() and fcvt() are obsolete versions of econvert() and
fconvert() that create a string in a static data area,
overwritten by each call, and return values that point to
that static data. These functions are therefore not reen-
trant.
gcvt() is an obsolete version of gconvert() that always
suppresses trailing zeros and point.
IEEE Infinities and NaNs are treated similarly by these
functions. ``NaN'' is returned for NaN, and ``Inf'' or
``Infinity'' for Infinity. The longer form is produced when
ndigit >= 8.
The radix character is determined by the current setting of
the program's locale (category LC_NUMERIC). In the "C"
locale or if the locale is undefined, the readix character
defaults to a period `.'.
SEE ALSO
printf(3V)
- Raw text -