1 .\" Copyright (c) 2016, IBM Corporation.
2 .\" Written by Wainer dos Santos Moschetta <wainersm@linux.vnet.ibm.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of
10 .\" this manual under the conditions for verbatim copying, provided that
11 .\" the entire resulting derived work is distributed under the terms of
12 .\" a permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume.
16 .\" no responsibility for errors or omissions, or for damages resulting.
17 .\" from the use of the information contained herein. The author(s) may.
18 .\" not have taken the same level of care in the production of this.
19 .\" manual, which is licensed free of charge, as they might when working.
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" References consulted:
27 .\" Glibc 2.25 source code and manual.
28 .\" C99 standard document.
29 .\" ISO/IEC TS 18661-1 technical specification.
30 .\" snprintf and other man.3 pages.
32 .TH STRFROMD 3 2017-09-15 "GNU" "Linux Programmer's Manual"
34 strfromd, strfromf, strfroml \- convert a floating-point value into
38 .B #include <stdlib.h>
40 .BI "int strfromd(char *restrict " str ", size_t " n ",
41 .BI " const char *restrict " format ", double " fp ");"
42 .BI "int strfromf(char *restrict " str ", size_t " n ",
43 .BI " const char *restrict " format ", float "fp ");"
44 .BI "int strfroml(char *restrict " str ", size_t " n ",
45 .BI " const char *restrict " format ", long double " fp ");"
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
58 __STDC_WANT_IEC_60559_BFP_EXT__
62 These functions convert a floating-point value,
64 into a string of characters,
71 characters are stored into
74 The terminating null character ('\e0') is written if and only if
76 is sufficiently large, otherwise the written string is truncated at
85 functions are equivalent to
89 snprintf(str, n, format, fp);
96 .SS Format of the format string
99 string must start with the character \(aq%\(aq.
100 This is followed by an optional precision which starts with the period
101 character (.), followed by an optional decimal integer.
102 If no integer is specified after the period character,
103 a precision of zero is used.
104 Finally, the format string should have one of the conversion specifiers
115 The conversion specifier is applied based on the floating-point type
116 indicated by the function suffix.
119 the format string does not have a length modifier character.
122 for a detailed description of these conversion specifiers.
124 The implementation conforms to the C99 standard on conversion of NaN and
130 is a NaN, +NaN, or -NaN, and
136 is the conversion specifier, the conversion is to "nan", "nan", or "-nan",
144 is the conversion specifier, the conversion is to "NAN" or "-NAN".
148 is infinity, it is converted to [-]inf or [-]INF.
153 string results in undefined behavior.
160 functions return the number of characters that would have been written in
165 not counting the terminating null character.
166 Thus, a return value of
168 or greater means that the output was truncated.
175 functions are available in glibc since version 2.25.
177 For an explanation of the terms used in this section, see
180 .B POSIX Safety Concepts
181 section in GNU C Library manual.
187 Interface Attribute Value
192 T} Thread safety MT-Safe locale
193 \^ Asynchronous signal safety AS-Unsafe heap
194 \^ Asynchronous cancellation safety AC-Unsafe mem
197 Note: these attributes are preliminary.
199 C99, ISO/IEC TS 18661-1.
206 functions take account of the
208 category of the current locale.
210 To convert the value 12.1 as a float type to a string using decimal
211 notation, resulting in "12.100000":
215 #define __STDC_WANT_IEC_60559_BFP_EXT__
219 strfromf(s, ssize, "%f", 12.1);
223 To convert the value 12.3456 as a float type to a string using
224 decimal notation with two digits of precision, resulting in "12.35":
228 #define __STDC_WANT_IEC_60559_BFP_EXT__
232 strfromf(s, ssize, "%.2f", 12.3456);
236 To convert the value 12.345e19 as a double type to a string using
237 scientific notation with zero digits of precision, resulting in "1E+20":
241 #define __STDC_WANT_IEC_60559_BFP_EXT__
245 strfromd(s, ssize, "%.E", 12.345e19);