ECVT(3) —
NAME
ecvt, fcvt, gcvt − output conversion
SYNOPSIS
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;
char ∗buf;
#include <ieee.h>
int cvtrounding (class)
int class;
DESCRIPTION
Ecvt converts value to a null-terminated string of up to ndigit ASCII digits and returns a pointer thereto. The position of the units digit relative to the beginning of the string is stored indirectly through decpt (zero or negative means to the left of the returned digits). If the sign of value is negative, the word pointed to by sign is set non-zero; otherwise, it is zero. The decimal string is rounded in the position specified by ndigit if this represents less than the intrinsic precision of value as a type double object; otherwise, the result is one of the decimal strings of no more than 17 digits to which value is the closest floating-point approximation.
Fcvt is identical to ecvt, except that the correct digit has been rounded for FORTRAN F-format output of the number of digits specified by ndigit.
Gcvt converts the value to a null-terminated ASCII string in buf and returns a pointer to buf. It attempts to produce ndigit significant digits in FORTRAN F-format, if possible, otherwise, in E-format, ready for printing. Trailing zeros may be suppressed.
If value is infinite, the string produced is “INF”. If value is a NaN (Not-a-Number), the string produced is “NAN()”. No distinction is made between signaling and quiet NaNs.
The cvtrounding() function determines which of two major classes of rounding is in effect. The first class is CVT_IEEE, or rounding in accordance with the IEEE standard 754 for binary floating point arithmetic. This gives four modes (defined in <ieee.h>):
TONEAREST
UPWARD
DOWNWARD
TOWARDZERO
The particular one of these in effect is governed by the use of the rounding functions (see ieee(3)). The default mode is TONEAREST.
The second class is CVT_ROUND (rounding "to roundest"). In this, the roundest of the set of external values which map to the same internal value is chosen, and then rounded to the precision required. This is the default.
EXAMPLES
The difference between the IEEE modes and "to roundest" may be shown by several examples:
The internal value 3fb1 eb85 1eb8 51ec, to 17 digits, is given as:
0.070000000000000007 CVT_IEEE, TONEAREST
0.070000000000000007 CVT_IEEE, UPWARD
0.070000000000000006 CVT_IEEE, DOWNWARD
0.070000000000000006 CVT_IEEE, TOWARDZERO
0.070000000000000000 CVT_ROUND
The negative of this value, bfb1 eb85 1eb8 51ec, to 17 digits, is given as:
-0.070000000000000007 CVT_IEEE, TONEAREST
-0.070000000000000006 CVT_IEEE, UPWARD
-0.070000000000000007 CVT_IEEE, DOWNWARD
-0.070000000000000006 CVT_IEEE, TOWARDZERO
-0.070000000000000000 CVT_ROUND
The internal value 3fc6 6666 6666 6666, to 17 digits, is given as:
0.17499999999999999 CVT_IEEE, TONEAREST
0.17500000000000000 CVT_ROUND
The same value, to 2 digits, is given as:
0.17 CVT_IEEE, TONEAREST
0.18 CVT_ROUND
SEE ALSO
BUGS
The return values point to static data, the content of which is overwritten by each call.
PRPQs 5799-WZQ/5799-PFF: IBM/4.3 — July 1987