diff options
Diffstat (limited to 'src/lib/libc/stdlib/ecvt.3')
-rw-r--r-- | src/lib/libc/stdlib/ecvt.3 | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/ecvt.3 b/src/lib/libc/stdlib/ecvt.3 new file mode 100644 index 0000000000..1ff9a4f61b --- /dev/null +++ b/src/lib/libc/stdlib/ecvt.3 | |||
@@ -0,0 +1,172 @@ | |||
1 | .\" $OpenBSD | ||
2 | .\" | ||
3 | .\" Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. The name of the author may not be used to endorse or promote products | ||
15 | .\" derived from this software without specific prior written permission. | ||
16 | .\" | ||
17 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
18 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
19 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
20 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
22 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
23 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
24 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
25 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
26 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | .\" | ||
28 | .Dd December 1, 2002 | ||
29 | .Dt ECVT 3 | ||
30 | .Os | ||
31 | .Sh NAME | ||
32 | .Nm ecvt , | ||
33 | .Nm fcvt , | ||
34 | .Nm gcvt | ||
35 | .Nd convert double to | ||
36 | .Tn ASCII | ||
37 | string | ||
38 | .Sh SYNOPSIS | ||
39 | .Fd #include <stdlib.h> | ||
40 | .Ft char * | ||
41 | .Fn ecvt "double value" "int ndigit" "int *decpt" "int *sign" | ||
42 | .Ft char * | ||
43 | .Fn fcvt "double value" "int ndigit" "int *decpt" "int *sign" | ||
44 | .Ft char * | ||
45 | .Fn gcvt "double value" "int ndigit" "char *buf" | ||
46 | .Sh DESCRIPTION | ||
47 | .Bf -symbolic | ||
48 | These functions are provided for compatibility with legacy code. | ||
49 | New code should use the | ||
50 | .Xr snprintf 3 | ||
51 | function for improved safety and portability. | ||
52 | .Ef | ||
53 | .Pp | ||
54 | The | ||
55 | .Fn ecvt , | ||
56 | .Fn fcvt | ||
57 | and | ||
58 | .Fn gcvt | ||
59 | functions convert the double precision floating-point number | ||
60 | .Fa value | ||
61 | to a NUL-terminated | ||
62 | .Tn ASCII | ||
63 | string. | ||
64 | .Pp | ||
65 | The | ||
66 | .Fn ecvt | ||
67 | function converts | ||
68 | .Fa value | ||
69 | to a NUL-terminated string of exactly | ||
70 | .Fa ndigit | ||
71 | digits and returns a pointer to that string. | ||
72 | The result is padded with zeroes from left to right as needed. | ||
73 | There are no leading zeroes unless | ||
74 | .Fa value | ||
75 | itself is 0. | ||
76 | The least significant digit is rounded in an implementation-dependent manner. | ||
77 | The position of the decimal point relative to the beginning of the string | ||
78 | is stored in | ||
79 | .Fa decpt . | ||
80 | A negative value indicates that the decimal point is located | ||
81 | to the left of the returned digits (this occurs when there is no | ||
82 | whole number component to | ||
83 | .Fa value ) . | ||
84 | If | ||
85 | .Fa value | ||
86 | is zero, it is unspecified whether the integer pointed to by | ||
87 | .Fa decpt | ||
88 | will be 0 or 1. | ||
89 | The decimal point itself is not included in the returned string. | ||
90 | If the sign of the result is negative, the integer pointed to by | ||
91 | .Fa sign | ||
92 | is non-zero; otherwise, it is 0. | ||
93 | .Pp | ||
94 | If the converted value is out of range or is not representable, | ||
95 | the contents of the returned string are unspecified. | ||
96 | .Pp | ||
97 | The | ||
98 | .Fn fcvt | ||
99 | function is identical to | ||
100 | .Fn ecvt | ||
101 | with the exception that | ||
102 | .Fa ndigit | ||
103 | specifies the number of digits after the decimal point (zero-padded as | ||
104 | needed). | ||
105 | .Pp | ||
106 | The | ||
107 | .Fn gcvt | ||
108 | function converts | ||
109 | .Fa value | ||
110 | to a NUL-terminated string similar to the %g | ||
111 | .Xr printf 3 | ||
112 | format specifier and stores the result in | ||
113 | .Fa buf . | ||
114 | It produces | ||
115 | .Fa ndigit | ||
116 | significant digits similar to the %f | ||
117 | .Xr printf 3 | ||
118 | format specifier where possible. | ||
119 | If | ||
120 | .Fa ndigit | ||
121 | does allow sufficient precision, the result is stored in | ||
122 | exponential notation similar to the %e | ||
123 | .Xr printf 3 | ||
124 | format specifier. | ||
125 | If | ||
126 | .Fa value | ||
127 | is less than zero, | ||
128 | .Fa buf | ||
129 | will be prefixed with a minus sign. | ||
130 | A decimal point is included in the returned string if | ||
131 | .Fa value | ||
132 | is not a whole number. | ||
133 | Unlike the | ||
134 | .Fn ecvt | ||
135 | and | ||
136 | .Fn fcvt | ||
137 | functions, | ||
138 | .Fa buf | ||
139 | is not zero-padded. | ||
140 | .Sh RETURN VALUES | ||
141 | The | ||
142 | .Fn ecvt , | ||
143 | .Fn fcvt | ||
144 | and | ||
145 | .Fn gcvt | ||
146 | functions return a NUL-terminated string representation of | ||
147 | .Fa value . | ||
148 | .Sh WARNINGS | ||
149 | The | ||
150 | .Fn ecvt | ||
151 | and | ||
152 | .Fn fcvt | ||
153 | functions return a pointer to internal storage space that will be | ||
154 | overwritten by subsequent calls to either function. | ||
155 | .Pp | ||
156 | The maximum possible precision of the return value is limited by the | ||
157 | precision of a double and may not be the same on all architectures. | ||
158 | .Pp | ||
159 | The | ||
160 | .Xr snprintf 3 | ||
161 | function is preferred over these functions for new code. | ||
162 | .Sh SEE ALSO | ||
163 | .Xr printf 3 , | ||
164 | .Xr strtod 3 | ||
165 | .Sh STANDARDS | ||
166 | The | ||
167 | .Fn ecvt , | ||
168 | .Fn fcvt | ||
169 | and | ||
170 | .Fn gcvt | ||
171 | functions conform to | ||
172 | .St -susv3 . | ||