malloc.3: ffix
[man-pages.git] / man3 / ecvt.3
blobdd2c7fc538dcae55b5dd3129a8d4ebb4abd831e0
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sat Jul 24 19:40:39 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified Fri Jun 25 12:10:47 1999 by Andries Brouwer (aeb@cwi.nl)
31 .\"
32 .TH ECVT 3 2021-03-22 "" "Linux Programmer's Manual"
33 .SH NAME
34 ecvt, fcvt \- convert a floating-point number to a string
35 .SH SYNOPSIS
36 .nf
37 .B #include <stdlib.h>
38 .PP
39 .BI "char *ecvt(double " number ", int " ndigits ", int *restrict " decpt ,
40 .BI "           int *restrict " sign );
41 .BI "char *fcvt(double " number ", int " ndigits ", int *restrict " decpt ,
42 .BI "           int *restrict " sign );
43 .fi
44 .PP
45 .RS -4
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
48 .RE
49 .PP
50 .BR ecvt (),
51 .BR fcvt ():
52 .nf
53     Since glibc 2.17
54         (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200809L))
55             || /* Glibc >= 2.20 */ _DEFAULT_SOURCE
56             || /* Glibc <= 2.19 */ _SVID_SOURCE
57     Glibc versions 2.12 to 2.16:
58         (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200112L))
59             || _SVID_SOURCE
60     Before glibc 2.12:
61         _SVID_SOURCE || _XOPEN_SOURCE >= 500
62 .\"        || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
63 .fi
64 .SH DESCRIPTION
65 The
66 .BR ecvt ()
67 function converts \fInumber\fP to a null-terminated
68 string of \fIndigits\fP digits (where \fIndigits\fP is reduced to a
69 system-specific limit determined by the precision of a
70 .IR double ),
71 and returns a pointer to the string.
72 The high-order digit is nonzero, unless
73 .I number
74 is zero.
75 The low order digit is rounded.
76 The string itself does not contain a decimal point; however,
77 the position of the decimal point relative to the start of the string
78 is stored in \fI*decpt\fP.
79 A negative value for \fI*decpt\fP means that
80 the decimal point is to the left of the start of the string.
81 If the sign of
82 \fInumber\fP is negative, \fI*sign\fP is set to a nonzero value,
83 otherwise it is set to 0.
85 .I number
86 is zero, it is unspecified whether \fI*decpt\fP is 0 or 1.
87 .PP
88 The
89 .BR fcvt ()
90 function is identical to
91 .BR ecvt (),
92 except that
93 \fIndigits\fP specifies the number of digits after the decimal point.
94 .SH RETURN VALUE
95 Both the
96 .BR ecvt ()
97 and
98 .BR fcvt ()
99 functions return a pointer to a
100 static string containing the ASCII representation of \fInumber\fP.
101 The static string is overwritten by each call to
102 .BR ecvt ()
104 .BR fcvt ().
105 .SH ATTRIBUTES
106 For an explanation of the terms used in this section, see
107 .BR attributes (7).
108 .ad l
111 allbox;
112 lbx lb lb
113 l l l.
114 Interface       Attribute       Value
116 .BR ecvt ()
117 T}      Thread safety   MT-Unsafe race:ecvt
119 .BR fcvt ()
120 T}      Thread safety   MT-Unsafe race:fcvt
124 .sp 1
125 .SH CONFORMING TO
126 SVr2;
127 marked as LEGACY in POSIX.1-2001.
128 POSIX.1-2008 removes the specifications of
129 .BR ecvt ()
131 .BR fcvt (),
132 recommending the use of
133 .BR sprintf (3)
134 instead (though
135 .BR snprintf (3)
136 may be preferable).
137 .SH NOTES
138 .\" Linux libc4 and libc5 specified the type of
139 .\" .I ndigits
140 .\" as
141 .\" .IR size_t .
142 Not all locales use a point as the radix character ("decimal point").
143 .SH SEE ALSO
144 .BR ecvt_r (3),
145 .BR gcvt (3),
146 .BR qecvt (3),
147 .BR setlocale (3),
148 .BR sprintf (3)