xref: /freebsd/lib/libc/stdlib/strfromd.3 (revision f5dc2263ab1be8a35a7e27e82103f9ccd41ae584)
1.\"
2.\" Copyright (c) 2026 Faraz Vahedi <kfv@kfv.io>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd June 27, 2026
7.Dt STRFROMD 3
8.Os
9.Sh NAME
10.Nm strfromd ,
11.Nm strfromf ,
12.Nm strfroml
13.Nd convert floating point value to
14.Tn ASCII
15string
16.Sh LIBRARY
17.Lb libc
18.Sh SYNOPSIS
19.In stdlib.h
20.Ft int
21.Fn strfromd "char * restrict str" "size_t size" "const char * restrict format" "double fp"
22.Ft int
23.Fn strfromf "char * restrict str" "size_t size" "const char * restrict format" "float fp"
24.Ft int
25.Fn strfroml "char * restrict str" "size_t size" "const char * restrict format" "long double fp"
26.Sh DESCRIPTION
27Functions
28.Fn strfromd ,
29.Fn strfromf ,
30and
31.Fn strfroml
32convert the floating-point value
33.Fa fp
34to a null terminated string, storing at most
35.Fa size
36bytes
37.Pq including the terminating null character
38into the array pointed to by
39.Fa str .
40.Pp
41These functions are equivalent to
42.Fn snprintf "s" "n" "format" "fp" ,
43except that default argument promotions are not applied to
44.Fa fp ,
45and the
46.Fa format
47string is restricted.
48It shall consist of exactly the character
49.Ql % ,
50followed by an optional precision that does not contain an asterisk
51.Ql * ,
52followed by one of the conversion specifiers
53.Cm a , A , e , E , f , F , g ,
54or
55.Cm G .
56The conversion specifier applies to the type indicated by the
57function suffix, rather than by a length modifier.
58.Pp
59Use of any other format string results in undefined behaviour,
60as does any undefined behaviour inherited from
61.Xr snprintf 3
62per se.
63In case of a format string not specified by the standard, the string
64.Ql EDOOFUS
65is written to
66.Fa str ,
67subject to the same truncation rules as a successful conversion, and
68.Va errno
69is set to
70.Er EDOOFUS .
71.Sh RETURN VALUES
72The
73.Fn strfromd ,
74.Fn strfromf ,
75and
76.Fn strfroml
77functions, as per
78.Xr snprintf 3 ,
79return the number of characters
80.Po
81not counting the terminating null character
82.Pc
83that would have been written
84had
85.Fa n
86been sufficiently large.
87Thus, the null terminated output has been completely written if
88and only if the returned value is both nonnegative and less than
89.Fa size .
90.Sh ERRORS
91.Bl -tag -width Er
92.It Bq Er EDOOFUS
93The
94.Fa format
95string is not of the form the standard specifies.
96.El
97.Sh SEE ALSO
98.Xr snprintf 3 ,
99.Xr strtod 3 ,
100.Xr strtol 3 ,
101.Xr strtoul 3
102.Sh STANDARDS
103Functions
104.Fn strfromd ,
105.Fn strfromf ,
106and
107.Fn strfroml
108conform to
109.St -isoC-2023 .
110