<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 12 Apr 2026 02:22:30 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>KP - 2018-09-27 02:03:13</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>else if(next == '@') {
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id value = va_arg(arguments, id);
&lt;br /&gt;}
&lt;br /&gt;results into EXC_BAD_ACCESS  see &lt;a href="https://screencast.com/t/74BIGsOq2m"&gt;https://screencast.com/t/74BIGsOq2m&lt;/a&gt; can you suggest a fix?</description><guid isPermaLink="true">9a164101fde6c90b7de7c95c1f4c7076</guid><pubDate>Thu, 27 Sep 2018 02:03:13 GMT</pubDate></item><item><title>sdeitch@robust-sw.com - 2013-06-17 06:34:20</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>hi,
&lt;br /&gt;&amp;nbsp;Very interesting. I am a new reader of your blog and to iOS. I am still trying to build up a appreciation of when to use what approach, hence the following questions..
&lt;br /&gt;
&lt;br /&gt;I am sure that you know that to get the lowest bit you can do intpart &amp;amp; 1 and then shift one place use intpart &amp;gt;&amp;gt;= 1 Since you are "talking" about bits this would be more explicit, was there a reason you did not do this ? 
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;With the writeUnsignedLongLong why did you not just divide by 10, put the results in a temp buffer and place the reverse of the temp buffer in the output?
&lt;br /&gt;
&lt;br /&gt;thanks for your help.</description><guid isPermaLink="true">5311505bdbbe07db95d13793b4f8822e</guid><pubDate>Mon, 17 Jun 2013 06:34:20 GMT</pubDate></item><item><title>mikeash - 2013-06-05 17:03:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Yep, I totally agree, and I'm definitely grateful for the additional information.
&lt;br /&gt;
&lt;br /&gt;This code is definitely not intended for real-world use. After all, Apple already provides a better built-in implementation, so just use theirs....</description><guid isPermaLink="true">f5b0efc4e881c2e3b57d091b0d16f6e5</guid><pubDate>Wed, 05 Jun 2013 17:03:15 GMT</pubDate></item><item><title>Bruce Dawson - 2013-06-05 16:51:08</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>I can't argue with the "Let's Build" ethos.
&lt;br /&gt;
&lt;br /&gt;Just beware of the significant challenges in trying to make printing of doubles and floats both efficient and correctly rounded. For my "Let's Build" code for printing floats I decided to ignore both of these, which allowed for much simpler code (and better elucidation) but clearly made my code less generally useful.
&lt;br /&gt;</description><guid isPermaLink="true">99aadf047d01e224218f50d28ee2081d</guid><pubDate>Wed, 05 Jun 2013 16:51:08 GMT</pubDate></item><item><title>mikeash - 2013-06-04 13:14:34</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Why not use a pre-made function? Because this is Let's Build, not Let's Find Some Existing Code and Call It. Otherwise the post could be reduced down to a single sentence that says, "Just call &lt;code&gt;sprintf&lt;/code&gt;."</description><guid isPermaLink="true">bafc6d7cc0399f294fdacfea5091e9b5</guid><pubDate>Tue, 04 Jun 2013 13:14:34 GMT</pubDate></item><item><title>Bruce Dawson - 2013-06-03 22:00:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Why not use David Gay's dtoa() function? It is a well tested standard conversion function. Any homegrown replacement is likely to reinvent many long since fixed bugs, or at least will have inferior rounding.
&lt;br /&gt;
&lt;br /&gt;See &lt;a href="http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/"&gt;http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/&lt;/a&gt; for examples of conversion bugs. The articles on this site also give some suggestions on tricky values to test on.
&lt;br /&gt;
&lt;br /&gt;Technically it is easy to print floats -- I published some straightforward code here:
&lt;br /&gt;&lt;a href="http://randomascii.wordpress.com/2012/03/08/float-precisionfrom-zero-to-100-digits-2/"&gt;http://randomascii.wordpress.com/2012/03/08/float-precisionfrom-zero-to-100-digits-2/&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;This code can easily be extended to doubles. However making the code efficient without breaking it is very hard. Adding rounding is left as an exercise for the reader.
&lt;br /&gt;</description><guid isPermaLink="true">12f1bac208198af83a8e95edc32ee632</guid><pubDate>Mon, 03 Jun 2013 22:00:21 GMT</pubDate></item><item><title>Matt - 2013-05-21 22:30:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Mike,
&lt;br /&gt;&amp;nbsp;&amp;nbsp;If you're interested in accurate printing/decoding of floating point numbers you should check out Bruce Dawson's blog: Random Ascii - &lt;a href="http://randomascii.wordpress.com/category/floating-point/"&gt;http://randomascii.wordpress.com/category/floating-point/&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;It's worthing noting that almost all vendor implementations of printf- functionality deviate from the ISO spec in some minor ways, which can create issues with cross-platform code (same inputs != same outputs).
&lt;br /&gt;</description><guid isPermaLink="true">c33058780548994aa9513c38c0d4401d</guid><pubDate>Tue, 21 May 2013 22:30:21 GMT</pubDate></item><item><title>mikeash - 2013-05-18 23:15:04</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Thank you for pointing that out, I've fixed it by moving the negative check to the top, and updated the article.</description><guid isPermaLink="true">f1d7f8a335281e9de87eeefc478e502e</guid><pubDate>Sat, 18 May 2013 23:15:04 GMT</pubDate></item><item><title>Jordan Rose - 2013-05-18 05:25:33</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Bug report: writeDouble will print negative infinity as "INFINITY", even though it's distinct from positive infinity.</description><guid isPermaLink="true">59d967d00160cb68b416ada018fdc64a</guid><pubDate>Sat, 18 May 2013 05:25:33 GMT</pubDate></item><item><title>Gwynne Raskind - 2013-05-17 21:59:07</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>&lt;b&gt;Ari&lt;/b&gt;: Unfortunately, no. A real &lt;code&gt;-stringWithFormat&lt;/code&gt; implementation has to handle, among other things, positional parameters and a wide array of options in each format specifier. There's no support in C for modifying the contents of a &lt;code&gt;va_list&lt;/code&gt; on the fly, which would be required for correctly supporting positional parameters when wrapping the existing &lt;code&gt;printf&lt;/code&gt;-style functions. The options are 1) using something other than % as your custom specifier character, or 2) reimplementing &lt;code&gt;sprintf&lt;/code&gt; from the ground up. Apple did the latter in Core Foundation; look at the function &lt;code&gt;__CFStringAppendFormatCore()&lt;/code&gt; in &lt;a href="http://opensource.apple.com/source/CF/CF-744.18/CFString.c"&gt;http://opensource.apple.com/source/CF/CF-744.18/CFString.c&lt;/a&gt; for an incredibly complicated example :).</description><guid isPermaLink="true">b19f2989c0ed9043aabbc8dab0d82eba</guid><pubDate>Fri, 17 May 2013 21:59:07 GMT</pubDate></item><item><title>Ari Weinstein - 2013-05-17 20:24:40</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-05-17-lets-build-stringwithformat.html#comments</link><description>Great article.
&lt;br /&gt;
&lt;br /&gt;All of the various implementations of printing out different types is fun, but if you actually wanted to write your own stringWithFormat:, wouldn't you just handle instances of "%@" and then wrap sprintf?</description><guid isPermaLink="true">2c8f1378df768513f73384306312ef19</guid><pubDate>Fri, 17 May 2013 20:24:40 GMT</pubDate></item></channel></rss>
