1<html lang="en"> 2<head> 3<title>quadmath_snprintf - GCC libquadmath</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="GCC libquadmath"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="I_002fO-Library-Routines.html#I_002fO-Library-Routines" title="I/O Library Routines"> 9<link rel="prev" href="strtoflt128.html#strtoflt128" title="strtoflt128"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 2010 Free Software Foundation, Inc. 13 14 Permission is granted to copy, distribute and/or modify this 15 document under the terms of the GNU Free Documentation License, 16 Version 1.2 or any later version published by the Free Software 17 Foundation; with no Invariant Sections, with the Front-Cover Texts 18 being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) 19 below. A copy of the license is included in the section entitled 20 ``GNU Free Documentation License.'' 21 22 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy 23 and modify this GNU manual. 24 --> 25<meta http-equiv="Content-Style-Type" content="text/css"> 26<style type="text/css"><!-- 27 pre.display { font-family:inherit } 28 pre.format { font-family:inherit } 29 pre.smalldisplay { font-family:inherit; font-size:smaller } 30 pre.smallformat { font-family:inherit; font-size:smaller } 31 pre.smallexample { font-size:smaller } 32 pre.smalllisp { font-size:smaller } 33 span.sc { font-variant:small-caps } 34 span.roman { font-family:serif; font-weight:normal; } 35 span.sansserif { font-family:sans-serif; font-weight:normal; } 36--></style> 37<link rel="stylesheet" type="text/css" href="../cs.css"> 38</head> 39<body> 40<div class="node"> 41<a name="quadmath_snprintf"></a> 42<a name="quadmath_005fsnprintf"></a> 43<p> 44Previous: <a rel="previous" accesskey="p" href="strtoflt128.html#strtoflt128">strtoflt128</a>, 45Up: <a rel="up" accesskey="u" href="I_002fO-Library-Routines.html#I_002fO-Library-Routines">I/O Library Routines</a> 46<hr> 47</div> 48 49<h3 class="section">3.2 <code>quadmath_snprintf</code> — Convert to string</h3> 50 51<p>The function <code>quadmath_snprintf</code> converts a <code>__float128</code> floating-point 52number into a string. It is a specialized alternative to <code>snprintf</code>, where 53the format string is restricted to a single conversion specifier with <code>Q</code> 54modifier and conversion specifier <code>e</code>, <code>E</code>, <code>f</code>, <code>F</code>, <code>g</code>, 55<code>G</code>, <code>a</code> or <code>A</code>, with no extra characters before or after the 56conversion specifier. The <code>%m$</code> or <code>*m$</code> style must not be used in 57the format. 58 59 <dl> 60<dt>Syntax<dd><code>int quadmath_snprintf (char *s, size_t size, const char *format, ...)</code> 61 62 <br><dt><em>Arguments</em>:<dd> 63 <p><table summary=""><tr align="left"><td valign="top" width="15%"><var>s</var> </td><td valign="top" width="70%">output string 64<br></td></tr><tr align="left"><td valign="top" width="15%"><var>size</var> </td><td valign="top" width="70%">byte size of the string, including tailing NUL 65<br></td></tr><tr align="left"><td valign="top" width="15%"><var>format</var> </td><td valign="top" width="70%">conversion specifier string 66 <br></td></tr></table> 67 68 <br><dt>Example<dd> 69 <pre class="smallexample"> #include <quadmath.h> 70 #include <stdlib.h> 71 #include <stdio.h> 72 73 int main () 74 { 75 __float128 r; 76 int prec = 20; 77 int width = 46; 78 char buf[128]; 79 80 r = 2.0q; 81 r = sqrtq (r); 82 int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r); 83 if ((size_t) n < sizeof buf) 84 printf ("%s\n", buf); 85 /* Prints: +1.41421356237309504880e+00 */ 86 quadmath_snprintf (buf, sizeof buf, "%Qa", r); 87 if ((size_t) n < sizeof buf) 88 printf ("%s\n", buf); 89 /* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */ 90 n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r); 91 if (n > -1) 92 { 93 char *str = malloc (n + 1); 94 if (str) 95 { 96 quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r); 97 printf ("%s\n", str); 98 /* Prints: +1.41421356237309504880e+00 */ 99 } 100 free (str); 101 } 102 return 0; 103 } 104</pre> 105 </dl> 106 107 <p>On some targets when supported by the C library hooks are installed 108for <code>printf</code> family of functions, so that <code>printf ("%Qe", 1.2Q);</code> 109etc. works too. 110 111<!-- --> 112<!-- GNU Free Documentation License --> 113<!-- --> 114<!-- Special handling for inclusion in the install manual. --> 115<!-- man begin DESCRIPTION --> 116 </body></html> 117 118