ecvt(3) — Subroutines
OSF
NAME
ecvt, fcvt, gcvt − Converts a floating-point number to a string
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <stdlib.h>
char ∗ecvt (
double value,
int num_digits,
int ∗decimal_ptr,
int ∗sign );
char ∗fcvt (
double value,
int num_digits,
int ∗decimal_ptr,
int ∗sign );
char ∗gcvt (
double value,
int num_digits,
char ∗buffer );
PARAMETERS
valueSpecifies the double value to be converted.
num_digitsSpecifies the number of digits in the resulting string.
decimal_ptrHolds the position of the decimal point relative to the beginning of the string. A negative number means the decimal point is to the left of the digits given in the string.
signHolds 0 (zero) if the value is positive or zero, and a nonzero value if it is negative.
bufferSpecifies the character array for the resulting string.
DESCRIPTION
The ecvt(), fcvt(), and gcvt() functions convert floating-point numbers to null-terminated strings.
The ecvt() function converts the value specified by the value parameter to a null-terminated string of length num_digits, and returns a pointer to it. The resulting low-order digit is rounded according to the current rounding mode. The decimal_ptr parameter is assigned to the position of the decimal point relative to the position of the string. The sign parameter is assigned 0 (zero) if value is positive or zero, and a nonzero value if value is negative. The decimal point and sign are not included in the string.
The fcvt() function is the same as the ecvt() function, except that it rounds to the correct digit for outputting num_digits digits in C or FORTRAN F-format.In the F-format, num_digits is taken as the number of digits desired after the decimal point.
The gcvt() function converts the value specified by the value parameter to a null-terminated string, stores it in the array pointed to by the buffer parameter, and then returns buffer. The gcvt() function attempts to produce a string of num_digits significant digits in FORTRAN F-format. If this is not possible, then E-format is used. The string is ready for printing, complete with minus sign, decimal point, or exponent, as appropriate. Trailing zeros are suppressed.
NOTES
In the F-format, num_digits is the number of digits desired after the decimal point. Very large numbers produce a very long string of digits before the decimal point, and then num_digits digits after the decimal point. For large numbers, it is preferable to use the gcvt() or ecvt() function so that the E-format will be used.
The ecvt(), fcvt(), and gcvt() functions represent the following special values that are specified in ANSI/IEEE Std. 754-1985 for floating-point arithmetic: Quiet NaN NaNQ
signalling NaNNaNS
+Infinity
The sign associated with each of these values is stored into the sign parameter. Note, also, that in IEEE Floating Point, a value of 0 (zero) can be positive or negative, as set by the sign parameter.
CAUTION
All three functions store the strings in a static area of memory whose contents are overwritten each time one of the functions is called.