{"id":42792,"date":"2024-12-01T13:28:43","date_gmt":"2024-12-01T05:28:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42792\/"},"modified":"2024-12-01T13:28:43","modified_gmt":"2024-12-01T05:28:43","slug":"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%a4%8d11000-1-%e5%92%8c-1100-10","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42792\/","title":{"rendered":"\u5982\u4f55\u4fee\u590d\u201c(1&lt;&lt;100)*0.1 \u548c (1&lt;&lt;100)\/10\u201d"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u4fee\u590d\u201c(1&lt;&lt;100)*0.1 \u548c (1&lt;&lt;100)\/10\u201d<\/span><\/p>\n<h1>\u5982\u4f55\u4fee\u590d\u201c(1&lt;&lt;100)*0.1 \u548c (1&lt;&lt;100)\/10\u201d<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-26 09:09:33<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u600e\u4e48\u5165\u95e8Golang\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5982\u4f55\u4fee\u590d\u201c(1<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5728<em>a tour of go<\/em>\u4e2d\uff0c<em>\u6570\u503c\u5e38\u91cf<\/em>\u90e8\u5206\uff0c\u4ee3\u7801\u662f<\/p>\n<pre>package main\n\nimport \"fmt\"\n\nconst (\n    \/\/ Create a huge number by shifting a 1 bit left 100 places.\n    \/\/ In other words, the binary number that is 1 followed by 100 zeroes.\n    Big = 1 &lt;&lt; 100\n    \/\/ Shift it right again 99 places, so we end up with 1&lt;&lt;1, or 2.\n    Small = Big &gt;&gt; 99\n)\n\nfunc needInt(x int) int { return x*10 + 1 }\n\nfunc needFloat(x float64) float64 { return x * 0.1 }\n\nfunc main() {\n    fmt.Println(needInt(Small))\n    fmt.Println(needFloat(Small))\n    fmt.Println(needFloat(Big))\n\n    fmt.Println(Big * 0.1) \/\/one\n    fmt.Println(Big \/ 10)  \/\/two\n}<\/pre>\n<p><code>fmt.println(big*0.1)<\/code> \u8f93\u51fa <code>1.2676506002282295e+29<\/code>, \u4f46\u662f <code>fmt.println(big \/ 10)<\/code> \u629b\u51fa\u9519\u8bef\uff1a<code>constant 126765060022822940149670320537 \u6ea2\u51fa int<\/code>\uff0c \u4ed6\u4eec\u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u6458\u81ea go \u535a\u5ba2 \uff1a<\/p>\n<p>\u6570\u5b57\u5e38\u91cf\u5b58\u5728\u4e8e\u4efb\u610f\u7cbe\u5ea6\u7684\u6570\u5b57\u7a7a\u95f4\u4e2d\uff1b\u4ed6\u4eec \u53ea\u662f\u666e\u901a\u6570\u5b57\u3002\u4f46\u662f\u5f53\u5b83\u4eec\u88ab\u5206\u914d\u7ed9\u4e00\u4e2a\u53d8\u91cf\u65f6 \u503c\u5fc5\u987b\u80fd\u591f\u9002\u5408\u76ee\u7684\u5730\u3002<\/p>\n<p>\u4e00\u4e2a\u4f8b\u5b50\u53ef\u4ee5\u8ba9\u8fd9\u4e00\u70b9\u66f4\u6e05\u695a\uff1a<\/p>\n<pre>const f = 1 &lt;&lt; 31\n\nx := f \/ 10  \/\/ what type is x?\ny := f * 0.1 \/\/ what type is y?\n\nfmt.printf(\" 10 : type = %8t\\n\", 10)    \/\/ int\nfmt.printf(\"0.1 : type = %8t\\n\\n\", 0.1) \/\/ float64\n\nfmt.printf(\" x  : type = %8t  value = %v\\n\", x, x)\nfmt.printf(\" y  : type = %8t  value = %v\\n\", y, y)<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>10 : type =      int\n0.1 : type =  float64\n\n x  : type =      int  value = 214748364\n y  : type =  float64  value = 2.147483648e+08<\/pre>\n<ul>\n<li><code>x<\/code> \u662f <code>int<\/code>\uff0c\u56e0\u4e3a\u9664\u6570 <code>10<\/code> \u88ab\u89e3\u91ca\u4e3a <code>int<\/code>\u3002<\/li>\n<li><code>y<\/code> \u662f <code>float64<\/code>\uff0c\u56e0\u4e3a\u4e58\u6570 <code>0.1<\/code> \u88ab\u89e3\u91ca\u4e3a <code>float64<\/code>\u3002<\/li>\n<\/ul>\n<p>\u5728\u793a\u4f8b\u4e2d\uff0cconst \u662f <code>1&lt;&lt;100<\/code>\uff0c\u5b83\u592a\u5927\uff0c\u65e0\u6cd5\u653e\u5165 <code>int<\/code>\uff0832 \u4f4d\uff09\uff0c\u56e0\u6b64\u7a0b\u5e8f\u751a\u81f3\u65e0\u6cd5\u7f16\u8bd1\uff0c\u56e0\u4e3a\u8be5\u6570\u5b57\u65e0\u6cd5\u5b58\u50a8\u5230\u5206\u914d\u7684\u5185\u5b58\u7c7b\u578b\u4e2d\uff1a100\u4f4d\u4e0d\u9002\u5408 32 \u4f4d <code>int<\/code>\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4fee\u590d\u201c(1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u4fee\u590d\u201c(1&lt;&lt;100)*0.1 \u548c (1&lt;&lt;100)\/10\u201d \u5982\u4f55\u4fee\u590d\u201c(1&lt;&lt;100)*0.1 \u548c (1&lt;&lt;100)\/10\u201d \u6765\u6e90\uff1astackoverflow 2024-04-26 09:09:33 0\u6d4f\u89c8 \u6536\u85cf \u600e\u4e48\u5165\u95e8Golang\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5982\u4f55\u4fee\u590d\u201c(1 \u95ee\u9898\u5185\u5bb9 \u5728a tour of go\u4e2d\uff0c\u6570\u503c\u5e38\u91cf\u90e8\u5206\uff0c\u4ee3\u7801\u662f package main import &#8220;fmt&#8221; const ( \/\/ Create a huge number by shifting a 1 bit left 100 places. \/\/ In other words, the binary number that is 1 followed by 100 zeroes. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42792","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=42792"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42792\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}