]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/ecvt.3
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man3 / ecvt.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
8 .\" 386BSD man pages
9 .\" Modified Sat Jul 24 19:40:39 1993 by Rik Faith (faith@cs.unc.edu)
10 .\" Modified Fri Jun 25 12:10:47 1999 by Andries Brouwer (aeb@cwi.nl)
11 .\"
12 .TH ECVT 3 2021-03-22 GNU "Linux Programmer's Manual"
13 .SH NAME
14 ecvt, fcvt \- convert a floating-point number to a string
15 .SH LIBRARY
16 Standard C library
17 .RI ( libc ", " \-lc )
18 .SH SYNOPSIS
19 .nf
20 .B #include <stdlib.h>
21 .PP
22 .BI "char *ecvt(double " number ", int " ndigits ", int *restrict " decpt ,
23 .BI " int *restrict " sign );
24 .BI "char *fcvt(double " number ", int " ndigits ", int *restrict " decpt ,
25 .BI " int *restrict " sign );
26 .fi
27 .PP
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .PP
33 .BR ecvt (),
34 .BR fcvt ():
35 .nf
36 Since glibc 2.17
37 (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200809L))
38 || /* Glibc >= 2.20 */ _DEFAULT_SOURCE
39 || /* Glibc <= 2.19 */ _SVID_SOURCE
40 Glibc versions 2.12 to 2.16:
41 (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200112L))
42 || _SVID_SOURCE
43 Before glibc 2.12:
44 _SVID_SOURCE || _XOPEN_SOURCE >= 500
45 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
46 .fi
47 .SH DESCRIPTION
48 The
49 .BR ecvt ()
50 function converts \fInumber\fP to a null-terminated
51 string of \fIndigits\fP digits (where \fIndigits\fP is reduced to a
52 system-specific limit determined by the precision of a
53 .IR double ),
54 and returns a pointer to the string.
55 The high-order digit is nonzero, unless
56 .I number
57 is zero.
58 The low order digit is rounded.
59 The string itself does not contain a decimal point; however,
60 the position of the decimal point relative to the start of the string
61 is stored in \fI*decpt\fP.
62 A negative value for \fI*decpt\fP means that
63 the decimal point is to the left of the start of the string.
64 If the sign of
65 \fInumber\fP is negative, \fI*sign\fP is set to a nonzero value,
66 otherwise it is set to 0.
67 If
68 .I number
69 is zero, it is unspecified whether \fI*decpt\fP is 0 or 1.
70 .PP
71 The
72 .BR fcvt ()
73 function is identical to
74 .BR ecvt (),
75 except that
76 \fIndigits\fP specifies the number of digits after the decimal point.
77 .SH RETURN VALUE
78 Both the
79 .BR ecvt ()
80 and
81 .BR fcvt ()
82 functions return a pointer to a
83 static string containing the ASCII representation of \fInumber\fP.
84 The static string is overwritten by each call to
85 .BR ecvt ()
86 or
87 .BR fcvt ().
88 .SH ATTRIBUTES
89 For an explanation of the terms used in this section, see
90 .BR attributes (7).
91 .ad l
92 .nh
93 .TS
94 allbox;
95 lbx lb lb
96 l l l.
97 Interface Attribute Value
98 T{
99 .BR ecvt ()
100 T} Thread safety MT-Unsafe race:ecvt
101 T{
102 .BR fcvt ()
103 T} Thread safety MT-Unsafe race:fcvt
104 .TE
105 .hy
106 .ad
107 .sp 1
108 .SH CONFORMING TO
109 SVr2;
110 marked as LEGACY in POSIX.1-2001.
111 POSIX.1-2008 removes the specifications of
112 .BR ecvt ()
113 and
114 .BR fcvt (),
115 recommending the use of
116 .BR sprintf (3)
117 instead (though
118 .BR snprintf (3)
119 may be preferable).
120 .SH NOTES
121 .\" Linux libc4 and libc5 specified the type of
122 .\" .I ndigits
123 .\" as
124 .\" .IR size_t .
125 Not all locales use a point as the radix character ("decimal point").
126 .SH SEE ALSO
127 .BR ecvt_r (3),
128 .BR gcvt (3),
129 .BR qecvt (3),
130 .BR setlocale (3),
131 .BR sprintf (3)