{"id":223752,"date":"2012-03-23T14:19:28","date_gmt":"2012-03-23T06:19:28","guid":{"rendered":"http:\/\/blog.yangzhe1991.org\/?p=223752"},"modified":"2014-03-14T20:00:12","modified_gmt":"2014-03-14T12:00:12","slug":"printf-f-lf","status":"publish","type":"post","link":"https:\/\/yangzhe1991.org\/blog\/2012\/03\/printf-f-lf\/","title":{"rendered":"\u8003\u8bc1\uff1a\u5173\u4e8eprintf\u7684%f\u548c%lf&#8230;"},"content":{"rendered":"<p>\u6628\u665aACM-DIY\u7fa4\u6709\u4e00\u4e2a\u4eba\u7814\u7a76double\u7684\u8f93\u51fa\u53d1\u73b01099511627775.9998779296875\u8fd9\u4e2a\u6570\u7406\u8bba\u4e0a\u662f\u53ef\u4ee5\u7528\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u8868\u793a\u7684\uff0c\u4f46\u662f\u5b9e\u9645printf\u8f93\u51fa\u7684\u65f6\u5019\u53d1\u73b0\u53ea\u80fd\u8f93\u51fa\u52301099511627775.9999000000\uff0c\u4e5f\u5c31\u662f\u53ea\u670918\u4e2a\u6709\u6548\u6570\u5b57\u3002\u7136\u540e\u4ed6\u6000\u7591\u662fprintf\u7684\u95ee\u9898\u3002\u7136\u540e\u67d0\u4eba\u7528cout\u8bd5\u4e86\u4e0b\u53d1\u73b0cout\u53ef\u4ee5\u6b63\u5e38\u8f93\u51fa\u5b8c\u6574\u7684\u6d6e\u70b9\u6570\u2026\u2026<\/p>\n<p><!--more--><\/p>\n<p>\u7136\u540e\u53d1\u73b0\uff0c\u4e0d\u540c\u7684\u7f16\u8bd1\u5668\u7ed3\u679c\u80af\u5b9a\u662f\u4e0d\u4e00\u6837\u7684\u3002printf\u90fd\u662f\u9519\u7684\uff0ccout\u5982\u679c\u662f\u6bd4\u8f83\u65b0\u7684gcc\u6216\u5bf9\u5e94\u7684mingw\u5c31\u80fd\u6b63\u786e\u8f93\u51fa\uff0cVS2010\u6216\u65e7\u7248mingw\u90fd\u8ddfprintf\u4e00\u6837\u3002\u5f53\u7136\u4e00\u822c\u60c5\u51b5\u4e0b\u8fd9\u7c7bbug\u4e0d\u4f1a\u5f71\u54cd\u4ec0\u4e48\u3002\u6240\u4ee5\u4e5f\u4e0d\u8003\u7a76\u8fd9\u4e2a\u4e86\u3002<\/p>\n<p>\u5f53\u65f6\u6709\u4eba\u8ba4\u4e3a\u9519\u8bef\u7684\u539f\u56e0\u662f\u56e0\u4e3a\u4ed6\u7528%f\u8f93\u51fa\u800c\u90a3\u4e2a\u4eba\u8ba4\u4e3a\u5e94\u8be5\u7528%lf\uff0c\u5f53\u7136\u4e5f\u6709\u4eba\u8ba4\u4e3a\u4ed6\u53ef\u80fd\u662f\u7528%lf\u624d\u5bfc\u81f4\u8fd9\u4e2a\u9519\u8bef\u5e94\u8be5\u7528%f\u3002\u4e8e\u662f\u8fd9\u5c31\u662f\u4e2a\u8001\u751f\u5e38\u8c08\u7684\u95ee\u9898\u4e86\uff1aprintf\u7684double\u5230\u5e95\u7528\u5565\uff1f\u5f53\u7136scanf\u7684float\u8ddfdouble\u4e0d\u4e00\u6837\u662f\u80af\u5b9a\u7684\u3002\u6240\u4ee5\u4e0d\u8003\u8651\u3002\u5bf9\u4e8eprintf\u7528%lf\u8fd8\u662f%f\u8f93\u51fadouble\u5982\u4eca\u6709\u4e09\u79cd\u89c2\u70b9\uff1a<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>double \u7528%lf\uff0cfloat\u7528%f<\/p>\n<p>\u4e24\u8005\u7528\u54ea\u4e2a\u90fd\u884c\uff0c\u6807\u51c6\u91cc\u90fd\u6709<\/p>\n<p>\u4e24\u8005\u7528\u54ea\u4e2a\u90fd\u884c\u662f\u56e0\u4e3a\u7f16\u8bd1\u5668\u81ea\u884c\u8ba4\u4f5c\u76f8\u540c\uff0c\u6807\u51c6\u91cc\u5176\u5b9e\u53ea\u6709%f\u6ca1\u6709%lf\u56e0\u6b64\u6700\u5408\u6cd5\u7684\u5199\u6cd5\u662f%f\u54ea\u6015%lf\u662f\u5bf9\u7684<\/p>\n<p>&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>\u4e4b\u524d\u6211\u4e00\u76f4\u662f\u7b2c\u4e09\u79cd\u770b\u6cd5\u3002\u56e0\u4e3a\u5728\u5f88\u591a\u573a\u5408\u89c1\u5230\u8bf4\u6807\u51c6\u91cc\u6ca1\u6709lf\u53ea\u6709f\u3002\u4e8e\u662f\u65e0\u804a\uff0c\u8003\u8bc1\u4e86\u4e0b\u3002<\/p>\n<p>\u4ece\u5386\u53f2\u89d2\u5ea6\u8bb2\uff0cC\u8bed\u8a00\u6709\u56db\u4e2a\u7248\u672c\uff1a<\/p>\n<p><a title=\"American National Standards Institute\" href=\"http:\/\/en.wikipedia.org\/wiki\/American_National_Standards_Institute\">American National Standards Institute<\/a>\u00a0C\uff0c\u7b80\u79f0ANSI C\uff0c\u4e5f\u53ebC89\uff1bISO\u91c7\u7eb3C89\uff0c\u53d8\u6210ISO\u6807\u51c6\uff0c\u53ebC90\uff0c\u5176\u5b9e\u8ddfC89\u4e00\u6837\uff1bC99\uff1bC11\u3002<\/p>\n<p>\u6211\u4eca\u5929\u624d\u542c\u8bf4C11\u8fd9\u4e1c\u897f\uff08\u53ea\u542c\u8bf4\u65b0\u7248cpp\uff09\uff0c\u5728<a href=\"http:\/\/www.iso.org\/iso\/catalogue_detail.htm?csnumber=29237\">\u8fd9\u91cc<\/a>\u53ef\u4ee5\u770b\u51fa\uff0c<a href=\"http:\/\/www.iso.org\/iso\/iso_catalogue\/catalogue_ics\/catalogue_detail_ics.htm?csnumber=57853\">ISO\/IEC 9899:2011<\/a>\u624d\u662f\u73b0\u884c\u7248\u672c\u3002\u4e8e\u662f\u627e\u73b0\u884c\u7248\u672c\u7684\u6750\u6599\uff0c\u6ca1\u627e\u5230\u514d\u8d39\u7684\u2026\u2026\u7a81\u7136\u60f3\u8d77\u67d0\u672c\u4e66\u7684\u4f5c\u8005\u66fe\u7ecf\u8bf4\uff0c\u505a\u6807\u51c6\u8fd9\u5e2e\u4eba\u60f3\u9760\u8fd9\u4e2a\u6323\u70b9\u94b1\u4e8e\u662f\u4e0d\u514d\u8d39\u53d1\u5e03\u800c\u662f\u5728\u7f51\u4e0a\u5356\uff0c\u4e0d\u77e5\u9053\u73b0\u5728\u8fd8\u662f\u4e0d\u662f\u2026\u2026\u4f46\u662f\u6211\u641c\u5230\u4e86\u4e00\u4e2a\u8c8c\u4f3c\u662f<a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg14\/www\/docs\/n1570.pdf\">\u8868\u51b3\u7a3f\u6216\u8005\u53ebC11\u8ba8\u8bba\u7a3f\u6216\u8005\u53eb\u8349\u6848<\/a>\u7684\u4e1c\u897f\uff0c\u4f30\u8ba1\u5728printf\u8fd9\u7c7b\u95ee\u9898\u4e0a\u4e0d\u4f1a\u8ddf\u6b63\u5f0f\u7248\u6709\u4ec0\u4e48\u5dee\u5f02\uff0c\u4e8e\u662f\u7528\u8fd9\u4e2a\u8003\u8bc1\u4e86\u4e0b\u3002<\/p>\n<p>\u6b64pdf\u7684\u524d\u8a00\u90e8\u5206\uff0c\u7b2c15\u9875Major changes in the second edition included\u4e2d\u63d0\u5230\uff1a<\/p>\n<p>%lf conversion specifier allowed in printf<\/p>\n<p>329\u9875\uff0cfprintf\u51fd\u6570\u7684\u8bf4\u660e\u4e2d\u63d0\u5230\uff08printf\u5c31\u662fstdio\u7684fprintf\uff09\uff1a<\/p>\n<p>l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a\u00a0long int or unsigned long int argument; that a following n\u00a0conversion specifier applies to a pointer to a long int argument; that a\u00a0following c conversion specifier applies to a wint_t argument; that a\u00a0following s conversion specifier applies to a pointer to a wchar_t\u00a0argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion<br \/>\nspecifier.<\/p>\n<p>\u53e6\u5916\uff0c\u8fd9\u91cc\u8bf4\u00a0the second edition\u662f\u6307C\u8bed\u8a00\u7684\u7b2c\u4e8c\u7248\uff0c\u4e5f\u5c31\u662fC99.\u6362\u53e5\u8bdd\u8bf4\u8fd9\u4e2a\u7279\u6027\u662f\u4eceC99\u5f00\u59cb\u6709\u7684\u3002<\/p>\n<p>\u603b\u4e4b\u5c31\u662f\u4e00\u53e5\u8bdd\uff1a<\/p>\n<p>%f\u548c%lf\u90fd\u5bf9\uff0c\u4e5f\u90fd\u662f\u7b26\u5408C\u6807\u51c6\u7684\u5199\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u665aACM-DIY\u7fa4\u6709\u4e00\u4e2a\u4eba\u7814\u7a76double\u7684\u8f93\u51fa\u53d1\u73b01099511627775.9998779296875\u8fd9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/223752"}],"collection":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/comments?post=223752"}],"version-history":[{"count":1,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/223752\/revisions"}],"predecessor-version":[{"id":224637,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/223752\/revisions\/224637"}],"wp:attachment":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/media?parent=223752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/categories?post=223752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/tags?post=223752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}