RFC: man-page for strfrom functions
Hi all,
The strfrom class of functions convert a floating-point value into string. It is recently introduced in Glibc (see commit 6962682ffe5e) and will be in version 2.25.
I've prepared a patch to add strfrom.3 in the man-pages but I'd like to discuss a point for the contribution beforehand:
- strfrom* is similar to snprintf() except for the format string. For instance, it doesn't have the length modifier and accept just a subset of conversion specifiers.
That said, I've doubt if wouldn't be better to place strfrom documentation at snprintf man-page (which is actually printf's) rather than on its own page.
What do you advice me?
- Wainer
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): e277d505-797f-acaf-2fce-56de92db5030-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Hello Wainer,
Quoted 9 lines · Wainer S. Moschetta
Hi all,
The strfrom class of functions convert a floating-point value into string. It is recently introduced in Glibc (see commit
6962682ffe5e) and will be in version 2.25.I've prepared a patch to add strfrom.3 in the man-pages but I'd like to discuss a point for the contribution beforehand:
Quoted 7 lines
- strfrom* is similar to
snprintf()except for the format string. For instance, it doesn't have the length modifier and accept just a subset of conversion specifiers.That said, I've doubt if wouldn't be better to place strfrom documentation at snprintf man-page (which is actually printf's) rather than on its own page.
Thanks. It would be great to get this documentation!
My estimation is that these functions would be better on their own page, rather than in printf(3). The strfrom*() functions provide only a subset of what snprintf(), and I think embedding the description of strfrom*() in printf() means they'd be a bit lost in among all the rest of the text.
Cheers,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): ac388dba-b7e4-b33e-7c43-eda88a8e4ac5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 1/1 Add strfrom.3
The ISO/IEC TS 18661-1 specifies the strfrom() class of functions that convert a float-point value to string.
The strfromd(), strfromf(), and strfroml() functions are introduced (commit 6962682ffe5e) in GNU C Library 2.25.
--- man3/strfrom.3 | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man3/strfromd.3 | 1 + man3/strfromf.3 | 1 + man3/strfroml.3 | 1 + 4 files changed, 223 insertions(+) create mode 100644 man3/strfrom.3 create mode 100644 man3/strfromd.3 create mode 100644 man3/strfromf.3 create mode 100644 man3/strfroml.3
man3/strfrom.3 new file +220 -0
@@ -0,0 +1,220 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROM 3 2016-12-02 "GNU C Library" +.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char * restrict " str ", size_t " n ", const char * restrict " format ", double " fp ");" +.sp +.BI "int strfromf (char * restrict " str ", size_t " n ", const char * restrict " format ", float "fp ");" +.sp +.BI "int strfroml (char * restrict " str ", size_t " n ", const char * restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b +.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. At most +.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4 +.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. This is followed by an optional precision which starts with period character (.), followed by an optional decimal integer. If no integer is specified after the period character, the precision used is zero. Finally, it should have one of the conversion specifiers +.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g , +or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type indicated by the function suffix. Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to C99 standard on conversion of NaN and infinity values: +.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", "-nan", respectively. If +.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. Thus, a return value of +.I n +or more means that the output was truncated. +.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and +.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml () +T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp +Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1. +.SH EXAMPLES +To convert the 12.1 value as a float type to string using decimal notation, resulting in "12.100000": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc (ssize); +strfromf (s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the 12.3456 value as a float type to string using decimal notation with two digits of precision, resulting in "12.35": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc (ssize); +strfromf (s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the 12.345e19 value as a double type to string using scientific notation with zero digits of precision, resulting in "1E+20": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc (ssize); +strfromd (s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO +.BR snprintf (3)
man3/strfromd.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfrom.3
man3/strfromf.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfrom.3
man3/strfroml.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfrom.3
A message that is not in the archive (sent off-list or not yet received): 20161202195509.10640-1-wainersm-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH] Add strfrom.3
Hello Wainer,
Thanks!
This is a very nice first draft. I have a just a few minor suggestions.
1. Name the page "strfromd", rather than "strfrom" (and adjust the link files accordingly, and also the .TH within the file). I suggest this, because this is a typical pattern used in many other pages.
2. Please make this into a patch series, if possible, with the link files each as a separate patch.
3. Add some patches that add strfromd(3) to the SEE ALSO section of other pages, such as printf(3) and atod(3).
Are these functions affected by the locale settings? There should be a statement about this in this page.
Quoted 18 lines · Wainer dos Santos Moschetta
The ISO/IEC TS 18661-1 specifies the
strfrom()class of functions that convert a float-point value to string.The
strfromd(),strfromf(), andstrfroml()functions are introduced (commit6962682ffe5e) in GNU C Library 2.25.Signed-off-by Wainer dos Santos Moschetta <[email protected]>--- man3/strfrom.3 | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man3/strfromd.3 | 1 + man3/strfromf.3 | 1 + man3/strfroml.3 | 1 + 4 files changed, 223 insertions(+) create mode 100644 man3/strfrom.3 create mode 100644 man3/strfromd.3 create mode 100644 man3/strfromf.3 create mode 100644 man3/strfroml.3
Quoted 28 lines
man3/strfrom.3 new file +22
-0@@ -0,0 +1,220 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by
man3/strfrom.3 line 32
Quoted 10 lines
man3/strfrom.3 new file +10
-0+.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROM 3 2016-12-02 "GNU C Library"
So, make this "STRFROMD".
man3/strfrom.3 line 38
Quoted 6 lines
man3/strfrom.3 new file +6
-0+.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char * restrict " str ", size_t " n ", const char * restrict " format ", double " fp ");"
Please wrap these long declarations, and remove the space after "*":
.BI "int strfromd (char *restrict " str ", size_t " n ,
.BI " const char *restrict " format ", double " fp ");"
Quoted 18 lines
man3/strfrom.3 new file +18
-0+.sp +.BI "int strfromf (char * restrict " str ", size_t " n ", const char * restrict " format ", float "fp ");" +.sp +.BI "int strfroml (char * restrict " str ", size_t " n ", const char * restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b
man3/strfrom.3 line 66
Quoted 10 lines
man3/strfrom.3 new file +10
-0+.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. At most
Please start new sentences on new source lines. (And the same for many instances below.)
Quoted 18 lines
man3/strfrom.3 new file +18
-0+.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4
man3/strfrom.3
Quoted 10 lines
man3/strfrom.3 new file +10
-0+.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. This is followed by an optional precision which starts with period character (.), followed by an optional
decimal integer. If no integer is specified after the period character, the precision used is zero. Finally, it should have one of the conversion specifiers
Please wrap source lines to a maximum of 75 characters, and start new sentence on new lines.
Quoted 7 lines
man3/strfrom.3 new file +7
-0+.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g ,
man3/strfrom.3 line 111
Quoted 10 lines
man3/strfrom.3 new file +10
-0+or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type indicated by the function suffix. Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to C99 standard on conversion of NaN and infinity values:
sto/to the/
man3/strfrom.3 line 122
Quoted 11 lines
man3/strfrom.3 new file +11
-0+.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", "-nan", respectively. If
s/"-nan"/or "-nan"/
Quoted 19 lines
man3/strfrom.3 new file +19
-0+.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (),
man3/strfrom.3 line 151
Quoted 10 lines
man3/strfrom.3 new file +10
-0+and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. Thus, a return value of +.I n +or more means that the output was truncated.
s/more/greater/
man3/strfrom.3 line 162
Quoted 11 lines
man3/strfrom.3 new file +11
-0+.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and
s/and/and the/
Quoted 12 lines
man3/strfrom.3 new file +12
-0+.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml ()
man3/strfrom.3 line 184
Quoted 10 lines
man3/strfrom.3 new file +10
-0+T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp +Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1. +.SH EXAMPLES +To convert the 12.1 value as a float type to string using decimal notation, resulting in "12.100000":
s/the 12.1 value/the value 12.1/
(And various other similar fixes below.)
man3/strfrom.3 line 191
Quoted 7 lines
man3/strfrom.3 new file +7
-0+.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc (ssize);
s/malloc /malloc/
(And again below.)
man3/strfrom.3 line 196
Quoted 5 lines
man3/strfrom.3 new file +5
-0+strfromf (s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the 12.3456 value as a float type to string using decimal notation with two digits of precision, resulting in "12.35":
s/string/a string/
Quoted 13 lines
man3/strfrom.3 new file +13
-0+.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc (ssize); +strfromf (s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the 12.345e19 value as a double type to string using scientific notation with zero digits of precision, resulting in "1E+20": +.sp
man3/strfrom.3 line 219
Quoted 10 lines
man3/strfrom.3 new file +10
-0+.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc (ssize); +strfromd (s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO
Add "atod(3)" here.
man3/strfromd.3 line 1
Quoted 8 lines
man3/strfrom.3 new file +1
-0+.BR snprintf (3)man3/strfromd.3 new file +1
-0@@ -0,0 +1 @@ +.so man3/strfrom.3
Remove the above
man3/strfromf.3 line 1
Quoted 7 lines
man3/strfromf.3 new file +1
-0@@ -0,0 +1 @@ +.so man3/strfrom.3
s/strfrom/strfromd/
man3/strfroml.3 line 1
Quoted 7 lines
man3/strfroml.3 new file +1
-0@@ -0,0 +1 @@ +.so man3/strfrom.3
s/strfrom/strfromd/
Cheers,
Michael
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): c5d0be31-9c1d-000a-89ac-a18909ef4ac5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
v2 cover Add strfromd.3: changelog
This patch set have following changes since v1:
- Broke in fine-grained patches.
- Moved content from strfrom.3 to strfromd.3.
- strfromf.3 and strfroml.3 link to strfromd.3.
- Changed strfromd.3:
- Keep source lines less than the 75 characters length limit.
- Wrapped function declarations in 75 chars limit.
- Now start new sentences on new source lines.
- Fixed typos.
- Added NOTES section about locale influence in strfrom* functions.
- Added atof.3 and strtod.3 to SEE ALSO.
- Formatted examples.
- Added strfromd(3) to SEE ALSO of atof(3), printf(3), and strtod(3).
Wainer dos Santos Moschetta (6):
Add strfromd.3
strfromf.3: add link to strfromd(3)
strfroml.3: add link to strfromd(3)
atof.3: SEE ALSO: add strfromd(3)
printf.3: SEE ALSO: add strfromd(3)
strtod.3: SEE ALSO: add strfromd(3)
man3/atof.3 | 1 + man3/printf.3 | 1 + man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man3/strfromf.3 | 1 + man3/strfroml.3 | 1 + man3/strtod.3 | 1 + 6 files changed, 260 insertions(+) create mode 100644 man3/strfromd.3 create mode 100644 man3/strfromf.3 create mode 100644 man3/strfroml.3
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): cover.1480961953.git.wainersm-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
PATCH v2 1/6 Add strfromd.3
The ISO/IEC TS 18661-1 specifies the strfrom() class of functions that convert a float-point value to string.
The strfromd(), strfromf(), and strfroml() functions are introduced (commit 6962682ffe5e) in GNU C Library 2.25.
--- man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 man3/strfromd.3
man3/strfromd.3 new file +255 -0
@@ -0,0 +1,255 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROMD 3 2016-12-02 "GNU C Library" +.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into +a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", double " fp ");" +.br +.BI "int strfromf (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", float "fp ");" +.br +.BI "int strfroml (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b +.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. +At most +.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4 +.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. +This is followed by an optional precision which starts with period +character (.), followed by an optional decimal integer. +If no integer is specified after the period character, the precision used +is zero. +Finally, it should have one of the conversion specifiers +.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g , +or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type +indicated by the function suffix. +Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. +See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to the C99 standard on conversion of NaN and +infinity values: +.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", or "-nan", +respectively. +If +.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. +Thus, a return value of +.I n +or greater means that the output was truncated. +.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and the +.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml () +T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp +Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1. +.SH NOTES +The behavior of +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions depends on the +.B LC_NUMERIC +category of the current locale. + +.SH EXAMPLES +To convert the value 12.1 as a float type to a string using decimal +notation, resulting in "12.100000": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromf(s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the value 12.3456 as a float type to a string using +decimal notation with two digits of precision, resulting in "12.35": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromf(s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the value 12.345e19 as a double type to a string using +scientific notation with zero digits of precision, resulting in "1E+20": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromd(s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO +.BR atof (3), +.BR snprintf (3), +.BR strtod (3)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 22cf57d5501526616e3f63d00102ce7cbf7e7287.1480961953.git.wainersm-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH v2 1/6] Add strfromd.3
Hello Wainer,
Just a few more questions and comments.
Quoted 217 lines · Wainer dos Santos Moschetta
The ISO/IEC TS 18661-1 specifies the
strfrom()class of functions that convert a float-point value to string.The
strfromd(),strfromf(), andstrfroml()functions are introduced (commit6962682ffe5e) in GNU C Library 2.25.Signed-off-by Wainer dos Santos Moschetta <[email protected]>--- man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 man3/strfromd.3man3/strfromd.3 new file +199
-0@@ -0,0 +1,255 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROMD 3 2016-12-02 "GNU C Library" +.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into +a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", double " fp ");" +.br +.BI "int strfromf (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", float "fp ");" +.br +.BI "int strfroml (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b +.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. +At most +.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4 +.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. +This is followed by an optional precision which starts with period +character (.), followed by an optional decimal integer. +If no integer is specified after the period character, the precision used +is zero. +Finally, it should have one of the conversion specifiers +.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g , +or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type +indicated by the function suffix. +Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. +See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to the C99 standard on conversion of NaN and +infinity values: +.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", or "-nan", +respectively. +If +.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. +Thus, a return value of +.I n +or greater means that the output was truncated. +.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and the +.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml () +T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp
man3/strfromd.3 line 209
Quoted 10 lines
man3/strfromd.3 new file +10
-0+Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1. +.SH NOTES +The behavior of +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions depends on the
Is not s/depends on/take account of/ more accurate?
man3/strfromd.3 line 222
Quoted 13 lines
man3/strfromd.3 new file +13
-0+.B LC_NUMERIC +category of the current locale. + +.SH EXAMPLES +To convert the value 12.1 as a float type to a string using decimal +notation, resulting in "12.100000":q +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize);
Why do you use malloc() in these examples, rather than just using (say) a char[10]? (Sorry, I should have asked this before...)
Quoted 23 lines
man3/strfromd.3 new file +23
-0+strfromf(s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the value 12.3456 as a float type to a string using +decimal notation with two digits of precision, resulting in "12.35": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromf(s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the value 12.345e19 as a double type to a string using +scientific notation with zero digits of precision, resulting in "1E+20": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__
man3/strfromd.3 line 255
Quoted 10 lines
man3/strfromd.3 new file +10
-0+#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromd(s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO +.BR atof (3), +.BR snprintf (3), +.BR strtod (3)
Cheers,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): bf67bf0f-0ac8-9d88-3a07-3f705e1f743e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH v2 1/6] Add strfromd.3
Hi Michael,
Thanks for your very good review. See answers below.
Quoted 225 lines · Michael Kerrisk (man-pages)
Hello Wainer,
Just a few more questions and comments.
Quoted 220 lines · Wainer dos Santos Moschetta
The ISO/IEC TS 18661-1 specifies the
strfrom()class of functions that convert a float-point value to string.The
strfromd(),strfromf(), andstrfroml()functions are introduced (commit6962682ffe5e) in GNU C Library 2.25.Signed-off-by Wainer dos Santos Moschetta <[email protected]>--- man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 man3/strfromd.3man3/strfromd.3 new file +202
-0@@ -0,0 +1,255 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROMD 3 2016-12-02 "GNU C Library" +.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into +a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", double " fp ");" +.br +.BI "int strfromf (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", float "fp ");" +.br +.BI "int strfroml (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b +.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. +At most +.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4 +.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. +This is followed by an optional precision which starts with period +character (.), followed by an optional decimal integer. +If no integer is specified after the period character, the precision used +is zero. +Finally, it should have one of the conversion specifiers +.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g , +or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type +indicated by the function suffix. +Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. +See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to the C99 standard on conversion of NaN and +infinity values: +.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", or "-nan", +respectively. +If +.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. +Thus, a return value of +.I n +or greater means that the output was truncated. +.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and the +.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml () +T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp +Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1.
Quoted 8 lines
man3/strfromd.3 line 209
Quoted 7 lines
man3/strfromd.3 new file +7
-0+.SH NOTES +The behavior of +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions depends on theIs not s/depends on/take account of/ more accurate?
Yes, it does. I will send a v3 patch with this change.
Quoted 16 lines
Quoted 4 lines
man3/strfromd.3 new file +3
-0+.B LC_NUMERIC +category of the current locale. +man3/strfromd.3 line 222
Quoted 10 lines
man3/strfromd.3 new file +10
-0+.SH EXAMPLES +To convert the value 12.1 as a float type to a string using decimal +notation, resulting in "12.100000":q +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize);Why do you use
malloc()in these examples, rather than just using (say) a char[10]? (Sorry, I should have asked this before...)
For no specific reason. I've a simple program that uses malloc, checked some of strfrom* features using it. Indeed, using char[10] simplifies the example. I will change it on patch v3 too.
Quoted 37 lines
Quoted 24 lines
man3/strfromd.3 new file +23
-0+strfromf(s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the value 12.3456 as a float type to a string using +decimal notation with two digits of precision, resulting in "12.35": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromf(s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the value 12.345e19 as a double type to a string using +scientific notation with zero digits of precision, resulting in "1E+20": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__man3/strfromd.3 line 255
Quoted 10 lines
man3/strfromd.3 new file +10
-0+#include <stdlib.h> +int ssize = 10; +char *s = (char *) malloc(ssize); +strfromd(s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO +.BR atof (3), +.BR snprintf (3), +.BR strtod (3)Cheers,
Quoted 3 lines
Michael
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
v3 cover Add strfromd.3: changelog
In reply to a message not in the archiveThis patch set has following changes since v2:
- In EXAMPLES, replaced use of malloc with char[ssize]
- In NOTES, s/depends on/take account of
Wainer dos Santos Moschetta (6):
Add strfromd.3
strfromf.3: add link to strfromd(3)
strfroml.3: add link to strfromd(3)
atof.3: SEE ALSO: add strfromd(3)
printf.3: SEE ALSO: add strfromd(3)
strtod.3: SEE ALSO: add strfromd(3)
man3/atof.3 | 1 + man3/printf.3 | 1 + man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man3/strfromf.3 | 1 + man3/strfroml.3 | 1 + man3/strtod.3 | 1 + 6 files changed, 260 insertions(+) create mode 100644 man3/strfromd.3 create mode 100644 man3/strfromf.3 create mode 100644 man3/strfroml.3
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): cover.1481114754.git.wainersm-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
PATCH v3 1/6 Add strfromd.3
The ISO/IEC TS 18661-1 specifies the strfrom() class of functions that convert a float-point value to string.
The strfromd(), strfromf(), and strfroml() functions are introduced (commit 6962682ffe5e) in GNU C Library 2.25.
--- man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 man3/strfromd.3
man3/strfromd.3 new file +255 -0
@@ -0,0 +1,255 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROMD 3 2016-12-02 "GNU C Library" +.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into +a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", double " fp ");" +.br +.BI "int strfromf (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", float "fp ");" +.br +.BI "int strfroml (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b +.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. +At most +.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4 +.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. +This is followed by an optional precision which starts with period +character (.), followed by an optional decimal integer. +If no integer is specified after the period character, the precision used +is zero. +Finally, it should have one of the conversion specifiers +.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g , +or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type +indicated by the function suffix. +Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. +See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to the C99 standard on conversion of NaN and +infinity values: +.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", or "-nan", +respectively. +If +.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. +Thus, a return value of +.I n +or greater means that the output was truncated. +.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and the +.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml () +T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp +Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1. +.SH NOTES +The behavior of +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions take account of the +.B LC_NUMERIC +category of the current locale. + +.SH EXAMPLES +To convert the value 12.1 as a float type to a string using decimal +notation, resulting in "12.100000": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char s[ssize]; +strfromf(s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the value 12.3456 as a float type to a string using +decimal notation with two digits of precision, resulting in "12.35": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char s[ssize]; +strfromf(s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the value 12.345e19 as a double type to a string using +scientific notation with zero digits of precision, resulting in "1E+20": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char s[ssize]; +strfromd(s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO +.BR atof (3), +.BR snprintf (3), +.BR strtod (3)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 2e277803abb58cd3d15ff5d26d667ac095df2562.1481114754.git.wainersm-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH v3 1/6] Add strfromd.3
Hello Wainer,
Quoted 5 lines · Wainer dos Santos Moschetta
The ISO/IEC TS 18661-1 specifies the
strfrom()class of functions that convert a float-point value to string.The
strfromd(),strfromf(), andstrfroml()functions are introduced (commit6962682ffe5e) in GNU C Library 2.25.
Thanks for the excellent page, and the very easy process of working with you![*] I have applied the v3 series of patches and pushed to Git.
Cheers,
Michael
[*] If you get tempted to document some of those other
new functions in glibc 2.25, by all means give in to the temptation :-).
Quoted 268 lines
Signed-off-by Wainer dos Santos Moschetta <[email protected]>--- man3/strfromd.3 | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 man3/strfromd.3man3/strfromd.3 new file +255
-0@@ -0,0 +1,255 @@ +.\" Copyright (c) 2016, IBM Corporation. +.\" Written by Wainer dos Santos Moschetta <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume. +.\" no responsibility for errors or omissions, or for damages resulting. +.\" from the use of the information contained herein. The author(s) may. +.\" not have taken the same level of care in the production of this. +.\" manual, which is licensed free of charge, as they might when working. +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" References consulted: +.\" Glibc 2.25 source code and manual. +.\" C99 standard document. +.\" ISO/IEC TS 18661-1 technical specification. +.\" snprintf and other man.3 pages. +.\" +.TH STRFROMD 3 2016-12-02 "GNU C Library" +.SH NAME +strfromd, strfromf, strfroml \- convert a floating-point value into +a string. +.SH SYNOPSIS +.B #include <stdlib.h> +.sp +.BI "int strfromd (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", double " fp ");" +.br +.BI "int strfromf (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", float "fp ");" +.br +.BI "int strfroml (char *restrict " str ", size_t " n ", +.br +.BI " const char *restrict " format ", long double " fp ");" +.sp +.in -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.ad l +.BR strfromd (), +.BR strfromf (), +.BR strfroml (): +.RS 4 +__STDC_WANT_IEC_60559_BFP_EXT__ +.RE +.ad b +.SH DESCRIPTION +The +.BR strfrom () +class of functions converts a floating-point value +.I fp +into a string of characters +.IR str , +with a configurable +.IR format +string. +At most +.I n +characters are stored into +.IR str . +.sp +The terminating null character ('\\0') is written if and only if +.I n +is sufficiently large, otherwise the written string is truncated at +.I n +characters. +.sp +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are equivalent to +.sp +.in +4 +.BI "snprintf (str, n, format, fp)" +.in +.sp +except for the +.I format +string. +.SS Format of the format string +The +.I format +string must start with the character %. +This is followed by an optional precision which starts with period +character (.), followed by an optional decimal integer. +If no integer is specified after the period character, the precision used +is zero. +Finally, it should have one of the conversion specifiers +.BR a , +.BR A , +.BR e , +.BR E , +.BR f , +.BR F , +.BR g , +or +.BR G . +.sp +The conversion specifier is applied based on the floating-point type +indicated by the function suffix. +Therefore, unlike +.BR snprintf (), +the format string does not have a length modifier character. +See +.BR snprintf (3) +for a detailed description of these conversion specifiers. +.sp +The implementation conforms to the C99 standard on conversion of NaN and +infinity values: +.sp +.in +4 +If +.I fp +is a NaN, +NaN, or -NaN, and +.BR f +(or +.BR a , +.BR e , +.BR g ) +is the conversion specifier, the conversion is to "nan", "nan", or "-nan", +respectively. +If +.B F +(or +.BR A , +.BR E , +.BR G ) +is the conversion specifier, the conversion is to "NAN" or "-NAN". +.sp +Likewise if +.I fp +is infinity, it is converted to [-]inf or [-]INF. +.in +.sp +A malformed +.I format +string results in undefined behavior. +.SH RETURN VALUE +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions return the number of characters that would have been written in +.I str +if +.I n +had enough space, +not counting the terminating null character. +Thus, a return value of +.I n +or greater means that the output was truncated. +.SH VERSIONS +The +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions are available in glibc since version 2.25. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7) +and the +.B POSIX Safety Concepts +section in GNU C Library manual. +.sp +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR strfromd (), +.BR strfromf (), +.BR strfroml () +T} Thread safety MT-Safe locale +\^ Asynchronous signal safety AS-Unsafe heap +\^ Asynchronous cancellation safety AC-Unsafe mem +.TE +.sp +Note: these attributes are preliminary. +.SH CONFORMING TO +C99, ISO/IEC TS 18661-1. +.SH NOTES +The behavior of +.BR strfromd (), +.BR strfromf (), +and +.BR strfroml () +functions take account of the +.B LC_NUMERIC +category of the current locale. + +.SH EXAMPLES +To convert the value 12.1 as a float type to a string using decimal +notation, resulting in "12.100000": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char s[ssize]; +strfromf(s, ssize, "%f", 12.1); +.fi +.in +.sp +To convert the value 12.3456 as a float type to a string using +decimal notation with two digits of precision, resulting in "12.35": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char s[ssize]; +strfromf(s, ssize, "%.2f", 12.3456); +.fi +.in +.sp +To convert the value 12.345e19 as a double type to a string using +scientific notation with zero digits of precision, resulting in "1E+20": +.sp +.in +4 +.nf +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <stdlib.h> +int ssize = 10; +char s[ssize]; +strfromd(s, ssize, "%.E", 12.345e19); +.fi +.in +.SH SEE ALSO +.BR atof (3), +.BR snprintf (3), +.BR strtod (3)
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 2/6 strfromf.3: add link to strfromd(3)
In reply to a message not in the archive--- man3/strfromf.3 | 1 + 1 file changed, 1 insertion(+) create mode 100644 man3/strfromf.3
man3/strfromf.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfromd.3
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 3/6 strfroml.3: add link to strfromd(3)
In reply to a message not in the archive--- man3/strfroml.3 | 1 + 1 file changed, 1 insertion(+) create mode 100644 man3/strfroml.3
man3/strfroml.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfromd.3
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 4/6 atof.3: SEE ALSO: add strfromd(3)
In reply to a message not in the archive--- man3/atof.3 | 1 + 1 file changed, 1 insertion(+)
man3/atof.3 +1 -0
@@ -71,6 +71,7 @@ POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. .SH SEE ALSO .BR atoi (3), .BR atol (3), +.BR strfromd (3), .BR strtod (3), .BR strtol (3), .BR strtoul (3)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 5/6 printf.3: SEE ALSO: add strfromd(3)
In reply to a message not in the archive--- man3/printf.3 | 1 + 1 file changed, 1 insertion(+)
man3/printf.3 +1 -0
@@ -1153,6 +1153,7 @@ error instead of being handled gracefully. .BR puts (3), .BR scanf (3), .BR setlocale (3), +.BR strfromd (3), .BR wcrtomb (3), .BR wprintf (3), .BR locale (5)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 6/6 strtod.3: SEE ALSO: add strfromd(3)
In reply to a message not in the archive--- man3/strtod.3 | 1 + 1 file changed, 1 insertion(+)
man3/strtod.3 +1 -0
@@ -209,5 +209,6 @@ the use of the functions described in this manual page is similar. .BR nan (3), .BR nanf (3), .BR nanl (3), +.BR strfromd (3), .BR strtol (3), .BR strtoul (3)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 2/6 strfromf.3: add link to strfromd(3)
In reply to a message not in the archive--- man3/strfromf.3 | 1 + 1 file changed, 1 insertion(+) create mode 100644 man3/strfromf.3
man3/strfromf.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfromd.3
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 3/6 strfroml.3: add link to strfromd(3)
In reply to a message not in the archive--- man3/strfroml.3 | 1 + 1 file changed, 1 insertion(+) create mode 100644 man3/strfroml.3
man3/strfroml.3 new file +1 -0
@@ -0,0 +1 @@ +.so man3/strfromd.3
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 4/6 atof.3: SEE ALSO: add strfromd(3)
In reply to a message not in the archive--- man3/atof.3 | 1 + 1 file changed, 1 insertion(+)
man3/atof.3 +1 -0
@@ -71,6 +71,7 @@ POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. .SH SEE ALSO .BR atoi (3), .BR atol (3), +.BR strfromd (3), .BR strtod (3), .BR strtol (3), .BR strtoul (3)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 5/6 printf.3: SEE ALSO: add strfromd(3)
In reply to a message not in the archive--- man3/printf.3 | 1 + 1 file changed, 1 insertion(+)
man3/printf.3 +1 -0
@@ -1153,6 +1153,7 @@ error instead of being handled gracefully. .BR puts (3), .BR scanf (3), .BR setlocale (3), +.BR strfromd (3), .BR wcrtomb (3), .BR wprintf (3), .BR locale (5)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 6/6 strtod.3: SEE ALSO: add strfromd(3)
In reply to a message not in the archive--- man3/strtod.3 | 1 + 1 file changed, 1 insertion(+)
man3/strtod.3 +1 -0
@@ -209,5 +209,6 @@ the use of the functions described in this manual page is similar. .BR nan (3), .BR nanf (3), .BR nanl (3), +.BR strfromd (3), .BR strtol (3), .BR strtoul (3)
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html