{"id":7917,"date":"2023-01-28T13:35:23","date_gmt":"2023-01-28T05:35:23","guid":{"rendered":"https:\/\/egonlin.com\/?p=7917"},"modified":"2023-01-28T13:35:23","modified_gmt":"2023-01-28T05:35:23","slug":"13-%e5%9f%ba%e6%9c%ac%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e4%b9%8b%e6%95%b4%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=7917","title":{"rendered":"13 \u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u6574\u578b"},"content":{"rendered":"<h1>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u6574\u578b<\/h1>\n<h2>\u4e00 \u6574\u578b\u4ecb\u7ecd<\/h2>\n<p>Go\u8bed\u8a00\u4e2d\u63d0\u4f9b\u4e86\u4e0d\u540c\u7c7b\u578b\u7684\u6574\u578b\uff0c\u4e3b\u8981\u5206\u4e3a\u6709\u7b26\u53f7\u548c\u65e0\u7b26\u53f7\u4e24\u5927\u7c7b<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>uint8<\/td>\n<td>\u65e0\u7b26\u53f7 8\u4f4d\u6574\u578b (0 \u5230 255)\uff0c\u5bf9\u5e94go\u8bed\u8a00\u7684byte\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>uint16<\/td>\n<td>\u65e0\u7b26\u53f7 16\u4f4d\u6574\u578b (0 \u5230 65535)<\/td>\n<\/tr>\n<tr>\n<td>uint32<\/td>\n<td>\u65e0\u7b26\u53f7 32\u4f4d\u6574\u578b (0 \u5230 4294967295)<\/td>\n<\/tr>\n<tr>\n<td>uint64<\/td>\n<td>\u65e0\u7b26\u53f7 64\u4f4d\u6574\u578b (0 \u5230 18446744073709551615)<\/td>\n<\/tr>\n<tr>\n<td>int8<\/td>\n<td>\u6709\u7b26\u53f7 8\u4f4d\u6574\u578b (-128 \u5230 127)<\/td>\n<\/tr>\n<tr>\n<td>int16<\/td>\n<td>\u6709\u7b26\u53f7 16\u4f4d\u6574\u578b (-32768 \u5230 32767)\uff0c\u5bf9\u5e94C\u8bed\u8a00\u4e2d\u7684short\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>int32<\/td>\n<td>\u6709\u7b26\u53f7 32\u4f4d\u6574\u578b (-2147483648 \u5230 2147483647)\uff0c\u5bf9\u5e94go\u8bed\u8a00\u7684rune\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>int64<\/td>\n<td>\u6709\u7b26\u53f7 64\u4f4d\u6574\u578b (-9223372036854775808 \u5230 9223372036854775807)\uff0c\u5bf9\u5e94C\u8bed\u8a00\u4e2d\u7684long\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6b64\u5916\u8fd8\u6709\u4e09\u4e2a\u7279\u6b8a\u7684\u6574\u578b\uff0c\u5176\u4e2dint\u662f\u6240\u6709\u6574\u578b\u91cc\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\uff0c\u4e5f\u662f\u7c7b\u578b\u63a8\u5bfc\u7684\u9ed8\u8ba4\u7c7b\u578b\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>uint<\/td>\n<td>\u572832\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eunit32\u4e00\u6837\uff0c 64\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eunit64\u4e00\u6837<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>\u572832\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eint32\u4e00\u6837\uff0c 64\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eint64\u4e00\u6837<\/td>\n<\/tr>\n<tr>\n<td>uintptr<\/td>\n<td>\u65e0\u7b26\u53f7\u6574\u578b\uff0c\u6ca1\u6709\u6307\u5b9a\u5177\u4f53\u7684bit\u5927\u5c0f\u4f46\u662f\u8db3\u4ee5\u5bb9\u7eb3\u6307\u9488\uff0c\u6240\u4ee5uintptr\u901a\u5e38\u7528\u4e8e\u5b58\u653e\u4e00\u4e2a\u6307\u9488\u3002uintptr\u7c7b\u578b\u53ea\u6709\u5728\u5e95\u5c42\u7f16\u7a0b\u662f\u624d\u9700\u8981\uff0c\u7279\u522b\u662fGo\u8bed\u8a00\u548cC\u8bed\u8a00\u51fd\u6570\u5e93\u6216\u64cd\u4f5c\u7cfb\u7edf\u63a5\u53e3\u76f8\u4ea4\u4e92\u7684\u5730\u65b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e8c \u58f0\u660e\u4e0e\u521d\u59cb\u5316<\/h2>\n<p>\u58f0\u660e\u8bed\u6cd5\u5982\u4e0b\uff0c\u91cd\u70b9\u5173\u6ce8\u4e00\u4e0b\u5b57\u9762\u91cf\u5373\u53ef<\/p>\n<pre><code class=\"language-go\">var \u53d8\u91cf\u540d \u6574\u578b\u7c7b\u578b = \u521d\u59cb\u5316\u8868\u8fbe\u5f0f\/\u5b57\u9762\u91cf<\/code><\/pre>\n<p>Go1.13\u7248\u672c\u4e4b\u540e\u5f15\u5165\u4e86\u6570\u5b57\u5b57\u9762\u91cf\u8bed\u6cd5Number literals syntax\uff0c\u8fd9\u6837\u4fbf\u4e8e\u5f00\u53d1\u8005\u4ee5\u4e8c\u8fdb\u5236\u3001\u516b\u8fdb\u5236\u6216\u5341\u516d\u8fdb\u5236\u6d6e\u70b9\u6570\u7684\u683c\u5f0f\u5b9a\u4e49\u6570\u5b57\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-go\">\/\/ \u65e0\u524d\u7f00\u4ee3\u8868\u5341\u8fdb\u5236\nv:=10\n\/\/ \u4ee50b\u4e3a\u524d\u7f00\u7684\u4e8c\u8fdb\u5236\nv := 0b00101101\n\/\/ \u4ee50o\u4e3a\u524d\u7f00\u7684\u516b\u8fdb\u5236\nv := 0o711 \n\/\/ \u4ee50x\u4e3a\u524d\u7f00\u7684\u5341\u516d\u8fdb\u5236\nv := 0xap-2\uff0c\u4ee3\u8868\u5341\u516d\u8fdb\u5236\u7684 a \u9664\u4ee5 2\u00b2\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u768410\/4\u5f97 2.5\u3002\n\n\/\/ \u800c\u4e14\u8fd8\u5141\u8bb8\u6211\u4eec\u7528 _ \u6765\u5206\u9694\u6570\u5b57\nv := 123_456 \u7b49\u4e8e 123456\u3002<\/code><\/pre>\n<p>ps\uff1a\u6211\u4eec\u53ef\u4ee5\u501f\u52a9fmt\u51fd\u6570\u6765\u5c06\u4e00\u4e2a\u6574\u6570\u4ee5\u4e0d\u540c\u8fdb\u5236\u5f62\u5f0f\u5c55\u793a\u3002<\/p>\n<pre><code class=\"language-go\">x:=57\n\/\/x:=0b111001 \n\/\/x:=0o71\n\/\/x:=0x39\n\n\/\/ \u8f93\u51fa(\u4e0d\u5e26\u524d\u7f00)\nfmt.Printf(&quot;%d\\n&quot;,x) \/\/ 57\nfmt.Printf(&quot;%b\\n&quot;,x) \/\/ 111001\nfmt.Printf(&quot;%o\\n&quot;,x) \/\/ 71\nfmt.Printf(&quot;%x\\n&quot;,x) \/\/ 39\n\n\/\/ \u8f93\u51fa(\u5e26\u524d\u7f00)\nfmt.Printf(&quot;%#d\\n&quot;,x) \/\/ 57\nfmt.Printf(&quot;%#b\\n&quot;,x) \/\/ 0b111001\nfmt.Printf(&quot;%#o\\n&quot;,x) \/\/ 071\nfmt.Printf(&quot;%#x\\n&quot;,x) \/\/ 0x39\n\n\/\/ [1]\u4ee3\u8868\u53d6\u5f97\u662f\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\uff0c[2]\u4ee3\u8868\u53d6\u5f97\u662f\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\nx:=57\ny:=33\nfmt.Printf(&quot;%[1]d   %[1]b   %[1]o  %[1]x\uff0c%[2]d   %[2]b   %[2]o  %[2]x &quot;,x,y)<\/code><\/pre>\n<p><strong>\u6ce8\u610f\u70b9<\/strong><\/p>\n<ul>\n<li>1\u3001go\u8bed\u8a00\u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u6570\u636e\u7c7b\u578b\u6709\u660e\u786e\u7684\u8fb9\u754c\uff0c\u4f8b\u5982\uff1aint\u572832\u4f4d\u5e73\u53f0\u4e0b\u88ab\u89e3\u6790\u6210\u4e8632\u4f4d\uff0c\u867d\u7136\u5b83\u7684\u5bbd\u5ea6\u4e0eint32\u4e00\u6837\uff0c\u4f46\u5b83\u4e0eint32\u4e5f\u662f\u4e0d\u540c\u7684\u7c7b\u578b\uff0cint64\u540c\u7406\uff0c\u5728\u9700\u8981\u5c06int\u5f53\u4f5cint32\u7c7b\u578b\u7684\u5730\u65b9\u9700\u8981\u6211\u4eec\u81ea\u5df1\u505a\u663e\u5f0f\u7684\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\/\u5f3a\u5236\u8f6c\u6362\uff0c\u53cd\u4e4b\u4ea6\u7136\uff0c<\/li>\n<\/ul>\n<pre><code class=\"language-go\">var x int\nvar y int64\nfmt.Println(x + y)  \/\/ \u62a5\u9519\uff1amismatched types int and int64<\/code><\/pre>\n<ul>\n<li>2\u3001len()\u8fd4\u56de\u7684\u662f\u4e00\u4e2aint\u7c7b\u578b\uff0c\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u5207\u7247\u6216 map \u7684\u5143\u7d20\u6570\u91cf\u7b49\u90fd\u53ef\u4ee5\u7528<code>int<\/code>\u6765\u8868\u793a\u3002<\/li>\n<li>3\u3001\u5728\u6d89\u53ca\u5230\u4e8c\u8fdb\u5236\u4f20\u8f93\u3001\u8bfb\u5199\u6587\u4ef6\u7684\u7ed3\u6784\u63cf\u8ff0\u65f6\uff0c\u4e3a\u4e86\u4fdd\u6301\u6587\u4ef6\u7684\u7ed3\u6784\u4e0d\u4f1a\u53d7\u5230\u4e0d\u540c\u7f16\u8bd1\u76ee\u6807\u5e73\u53f0\u5b57\u8282\u957f\u5ea6\u7684\u5f71\u54cd\uff0c\u4e0d\u8981\u4f7f\u7528<code>int<\/code>\u548c <code>uint<\/code>\u3002<\/li>\n<\/ul>\n<h2>\u4e09 \u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h2>\n<p>\u6574\u578b\u4e0e\u6d6e\u70b9\u578b\u4e3a\u517c\u5bb9\u7c7b\u578b\uff0c\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\uff0c\u672c\u8282\u6211\u4eec\u4e3b\u8981\u4ecb\u7ecd\uff1a<strong>\u6574\u578b\u3001\u6d6e\u70b9\u578b\u8f6c\u4e3a&#8212;&gt;\u6574\u578b<\/strong><\/p>\n<p>\u4e00\uff1a\u663e\u5f0f\u8f6c\u6362\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p>1.1\u3001<strong>\u65e0\u7c7b\u578b\u7684\u91cf\uff08\u65e0\u7c7b\u578b\u7684\u6574\u6570\u3001\u65e0\u7c7b\u578b\u7684\u6d6e\u70b9\u6570\uff09\u53ef\u4ee5\u8f6c\u4e3a\u6574\u578b\uff0c\u8d85\u51fa\u76ee\u6807\u7c7b\u578b\u503c\u57df\u8303\u56f4\u5c31\u62a5\u9519<\/strong><\/p>\n<p>\u4f8b1\uff1a\u65e0\u7c7b\u578b\u7684\u6574\u578b\u5b57\u9762\u91cf&#8212;&gt;\u6574\u578b\uff0c\u8d85\u51fa\u76ee\u6807\u6574\u578b\u7684\u503c\u57df\u8303\u56f4\u5c31\u4f1a\u62a5\u9519<\/p>\n<pre><code class=\"language-go\">int(10)      \/\/ ok\nuint8(256)   \/\/ \u9519\u8bef\uff0c\u65e0\u7c7b\u578b\u7684\u6574\u578b\u5b57\u9762\u91cf256\u8d85\u8fc7uint8\u6700\u5927\u5b58\u503c\u8303\u56f4<\/code><\/pre>\n<p>\u4f8b2\uff1a\u65e0\u7c7b\u578b\u7684\u6d6e\u70b9\u578b\u5b57\u9762\u91cf&#8212;&gt;\u6574\u578b\uff0c\u82e5\u6d6e\u70b9\u6570\u9700\u8981\u88ab\u622a\u65ad\u5c31\u4f1a\u62a5\u9519\uff0c\u9700\u8981\u622a\u65ad\u4e5f\u5c31\u662f\u8d85\u51fa\u4e86\u8303\u56f4<\/p>\n<pre><code class=\"language-go\">int(10.0)    \/\/ ok\uff0c\u5b57\u9762\u91cf10.0\u4e0d\u9700\u8981\u622a\u65ad\u5c31\u53ef\u4ee5\u8f6c\u6362\u4e3a\u6574\u578b\nint(10.3)    \/\/ \u9519\u8bef\uff0c\u9700\u8981\u622a\u65ad\u5c31\u4e0d\u884c\n\n\u590d\u6570\u8f6c\u6574\u578b\u4e5f\u662f\u4e00\u4e2a\u9053\u7406\nfmt.Println(int(10+2i))   \/\/ \u9519\u8bef\uff0c\u9700\u8981\u622a\u65ad\u5c31\u4e0d\u884c<\/code><\/pre>\n<\/li>\n<li>\n<p>1.2\u3001<strong>\u6709\u7c7b\u578b\u7684\u91cf\uff08\u6709\u7c7b\u578b\u7684\u6574\u6570\u3001\u6709\u7c7b\u578b\u7684\u6d6e\u70b9\u6570\uff09\u4e5f\u53ef\u4ee5\u8f6c\u4e3a\u6574\u578b\uff0c\u8d85\u51fa\u76ee\u6807\u7c7b\u578b\u503c\u57df\u8303\u56f4\u4e0d\u62a5\u9519\uff0c\u4f46\u662f\u6574\u6570\u4f1a\u6ea2\u51fa\u3001\u6d6e\u70b9\u6570\u5219\u4e22\u5931\u7cbe\u5ea6\uff0c\u5e94\u8be5\u5c3d\u91cf\u907f\u514d<\/strong><\/p>\n<p>\u4f8b1\uff1a\u6709\u7c7b\u578b\u7684\u6574\u6570&#8212;&gt;\u6574\u578b\uff0c\u8d85\u51fa\u503c\u57df\u8303\u56f4\u4e0d\u62a5\u9519\uff0c\u4f46\u662f\u503c\u4f1a\u6ea2\u51fa<\/p>\n<pre><code class=\"language-go\">var x int32 = 256\nfmt.Println(uint8(x))  \/\/ \u5927\u5c3a\u5bf8\u8f6c\u5c0f\u5c3a\u5bf8\uff0c\u503c\u6ea2\u51fa\uff0c\u8f93\u51fa\u4e3a0<\/code><\/pre>\n<p>\u4f8b2\uff1a\u6709\u7c7b\u578b\u7684\u6d6e\u70b9\u6570&#8212;&gt;\u6574\u578b\uff0c\u5b58\u5728\u9700\u8981\u622a\u65ad\u7684\u503c\u4e0d\u62a5\u9519\uff0c\u4f46\u662f\u4f1a\u76f4\u63a5\u4e22\u5230\u5c0f\u6570\u70b9\u540e\u7684\u5185\u5bb9\u3001\u7cbe\u5ea6\u4e27\u5931<\/p>\n<pre><code class=\"language-go\">var f float64 = 10.9 \nfmt.Println(int(f))   \/\/ 10<\/code><\/pre>\n<p>\u5f3a\u8c03\uff1a\u6211\u4eec\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u6ea2\u51fa\u6216\u4e22\u5931\u7cbe\u5ea6\uff01\uff01\uff01<br \/>\n\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u6574\u578b\u7684\u8f6c\u6362\u90fd\u4e0d\u8981\u8d85\u8fc7\u76ee\u6807\u7c7b\u578b\u503c\u57df\uff0c\u5982\u6b64\uff0c\u5219\u53ea\u6539\u53d8\u4e86\u7c7b\u578b\uff0c\u5e76\u672a\u6539\u53d8\u6570\u503c\uff0c\u770b\u4f3c\u6ca1\u5565\u7528\uff0c\u5176\u5b9e\u4e0d\u7136\uff0c\u5728\u6709\u4e9b\u573a\u666f\u4e0b\u4f60\u5fc5\u987b\u8fd9\u4e48\u505a\u6765\u544a\u8bc9\u7f16\u8bd1\u5668\u5982\u4f55\u89e3\u91ca\u8fd9\u4e2a\u503c\uff0c\u4ee5\u8fbe\u5230\u9075\u5faa\u5f3a\u7c7b\u578b\u539f\u5219\u7684\u76ee\u7684\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-go\">var x int32\ny := 666 \/\/ y\u5c06\u4f1a\u88ab\u81ea\u52a8\u63a8\u5bfc\u4e3aint\u7c7b\u578b\n\/\/ x = y \/\/ \u7f16\u8bd1\u9519\u8bef\uff0c\u56e0\u4e3ay\u662fint\u7c7b\u578b\uff0c\u800cx\u662fint32\u7c7b\u578b\uff0c\u6240\u4ee5\u65e0\u6cd5\u5c06y\u7684\u503c\u8d4b\u503c\u7ed9x\nx = int32(y) \/\/ \u4f7f\u7528\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u53ef\u4ee5\u89e3\u51b3\u4e0a\u8ff0\u9519\u8bef\uff0c\u6b64\u5904\u5e76\u6ca1\u6709\u6539\u53d8y\u7684\u503c\uff0c\u53ea\u662f\u544a\u8bc9\u4e86\u7f16\u8bd1\u5668y\u7684\u7c7b\u578b\u4e3aint32\uff0c\u4e0ex\u7684\u7c7b\u578b\u4fdd\u5b58\u4e00\u81f4\uff0c\u56e0\u6b64\u53ef\u4ee5\u8d4b\u503c\n\nvar apples int32 = 1\nvar oranges int16 = 2\n\/\/var compote int = apples + oranges  \/\/ \u7f16\u8bd1\u9519\u8bef\uff1a\u7b97\u672f\u548c\u903b\u8f91\u8fd0\u7b97\u7684\u4e8c\u5143\u64cd\u4f5c\u4e2d\u5fc5\u987b\u662f\u76f8\u540c\u7684\u7c7b\u578b\u3002\nvar compote = int(apples) + int(oranges)  \/\/ \u9700\u8981\u4e00\u4e2a\u663e\u5f0f\u7684\u8f6c\u6362\u5c06\u4e00\u4e2a\u503c\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u5316\u4f4d\u53e6\u4e00\u79cd\u7c7b\u578b\uff0c\u867d\u7136\u8fd9\u5076\u5c14\u4f1a\u5bfc\u81f4\u9700\u8981\u5f88\u957f\u7684\u8868\u8fbe\u5f0f\uff0c\u4f46\u662f\u5b83\u6d88\u9664\u4e86\u6240\u6709\u548c\u7c7b\u578b\u76f8\u5173\u7684\u95ee\u9898\uff0c\u800c\u4e14\u4e5f\u4f7f\u5f97\u7a0b\u5e8f\u5bb9\u6613\u7406\u89e3\u3002\nfmt.Println(compote) \/\/ 3<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u4e8c\uff1a\u9690\u5f0f\u8f6c\u6362\uff0c\u53ea\u9488\u5bf9\u65e0\u7c7b\u578b\u7684\u91cf\uff0c\u5e95\u5c42\u53d1\u751f\u7684\u5c31\u662fT(x)<\/p>\n<pre><code class=\"language-go\">var age uint8\nage = 256 \/\/ \u5e95\u5c42\u9690\u5f0f\u6267\u884cuint8(256)\uff0c\u629b\u51fa\u5f02\u5e38\uff1aconstant 256 overflows uint8<\/code><\/pre>\n<h2>\u56db \u57fa\u672c\u64cd\u4f5c<\/h2>\n<h3>4.1 \u4e8c\u5143\u8fd0\u7b97<\/h3>\n<p>\u6574\u578b\u5c5e\u4e8e\u6570\u5b57\uff0c\u6570\u5b57\u4e4b\u95f4\u652f\u6301\u52a0\u51cf\u4e58\u9664\u7b49\u7b97\u6570\u8fd0\u7b97\u4ee5\u53ca\u6bd4\u8f83\u8fd0\u7b97\uff0c\u4f46\u4ec5\u9650\u4e8e\u540c\u7c7b\u578b\u4e4b\u95f4\uff0c\u975e\u540c\u7c7b\u578b\u7ecf\u9690\u5f0f\u6216\u663e\u5f0f\u8f6c\u6362\u6210\u76f8\u540c\u7c7b\u578b\u540e\u4e5f\u53ef\u4ee5\uff0c\u793a\u4f8b\u5982\u4e0b<\/p>\n<p>\uff081\uff09\u7b97\u6570\u8fd0\u7b97<\/p>\n<pre><code class=\"language-go\">\/\/ \u4f8b1\uff1a\u663e\u5f0f\u8f6c\u6362\nvar x int64 = 10\nvar y int32 = 20\nfmt.Println(x + y)  \/\/ \u9519\u8bef\uff1amismatched types int64 and int32\nfmt.Println(x + int64(y))  \/\/ \u6b63\u786e\n\n\/\/ \u4f8b2\uff1a\u9690\u5f0f\u8f6c\u6362\nvar x int64 = 10\nfmt.Println(x + 10.3) \/\/ \u9690\u5f0f\u8f6c\u6362int64(10.3)\uff0c\u9519\u8bef\uff1aconstant 10.3 truncated to integer\nfmt.Println(x + 10.0) \/\/ \u9690\u5f0f\u8f6c\u6362int64(10.0)\uff0c\u6b63\u786e\uff0c\u7ed3\u679c\u4e3a\uff1a20\n\n\/\/ \u4f8b3\uff1a\u663e\u5f0f\u8f6c\u6362\nvar x int32 = 1\nvar y int16 = 2\nvar z = int(x) + int(y)\nfmt.Println(z) \/\/ 3<\/code><\/pre>\n<p>\uff082\uff09\u76f8\u7b49\u6027\u6bd4\u8f83<\/p>\n<pre><code class=\"language-go\">\/\/ \u540c\u7c7b\u578bok\nvar x int64 = 10\nvar y int64 = 10\nfmt.Println(x == y) \/\/ true\nfmt.Println(x != y) \/\/ false\n\n\/\/ \u4e0d\u540c\u7c7b\u578b\u5219\u7f16\u8bd1\u9519\u8bef\n\/\/ \u518d\u6b21\u5f3a\u8c03\uff1a\u65e0\u8bba\u4ec0\u4e48\u7c7b\u578b\uff0c\u5bbd\u5ea6\u6216\u957f\u5ea6\u90fd\u662f\u5176\u91cd\u8981\u7684\u7ec4\u6210\u90e8\u5206\nvar i int32 = 10\nvar j int64 = 20\nfmt.Println(i == j)  \/\/ \u7f16\u8bd1\u9519\u8bef\n\n\/\/ \u6d89\u53ca\u5230\u65e0\u7c7b\u578b\u7684\u91cf(\u65e0\u7c7b\u578b\u7684\u5e38\u91cf\u6216\u5b57\u9762\u91cf)\uff0c\u4f1a\u9690\u5f0f\u8f6c\u6362\u6210\u76f8\u5e94\u7c7b\u578b\uff0c\u8f6c\u6362\u5408\u6cd5\u5c31\u53ef\u4ee5\u8fdb\u884c\u76f8\u7b49\u6027\u5224\u65ad\u3002\nvar x int64 = 10\nfmt.Println(x == 10)  \/\/ \u53ef\u4ee5\u6bd4\u8f83\uff0c\u56e0\u4e3a\u5e95\u5c42\uff1ax == int64(10)\uff0c\u7f16\u8bd1\u901a\u8fc7\nfmt.Println(x == 10.3) \/\/ \u62a5\u9519\uff0c\u56e0\u4e3a\u5e95\u5c42:x == int64(10.3)\uff0c\u7f16\u8bd1\u9519\u8bef<\/code><\/pre>\n<p>\uff083\uff09\u6bd4\u5927\u5c0f<\/p>\n<pre><code class=\"language-go\">var x int32 = 10\nvar y int64 = 3\n\n\/\/ \u663e\u5f0f\nfmt.Println(x &gt; y)          \/\/ \u7f16\u8bd1\u9519\u8bef\nfmt.Println(x &gt; int32(y))   \/\/ \u7f16\u8bd1\u901a\u8fc7\n\n\/\/ \u9690\u5f0f\nfmt.Println(x &gt; 3)      \/\/ x &gt; int32(3)\uff0c\u7f16\u8bd1\u901a\u8fc7\nfmt.Println(x &gt; 3.1)    \/\/ x &gt; int32(3.1)\uff0c\u7f16\u8bd1\u5931\u8d25\n\n\/\/ \u9690\u5f0f\uff1a\nfmt.Println(10 &gt; 3.1)   \/\/ \u4f18\u5148\u7ea7float&gt;int\uff0c\u6240\u4ee5\u5e95\u5c42float64(10) &gt; float64(3.1)\uff0c\u7f16\u8bd1\u901a\u8fc7<\/code><\/pre>\n<h2>\u4e94 \u5728\u51fd\u6570\u53c2\u6570\u4e2d\u4f20\u9012<\/h2>\n<p>\u503c\u4f20\u9012<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u6574\u578b \u4e00 \u6574\u578b\u4ecb\u7ecd Go\u8bed\u8a00\u4e2d\u63d0\u4f9b\u4e86\u4e0d\u540c\u7c7b\u578b\u7684\u6574\u578b\uff0c\u4e3b\u8981\u5206\u4e3a\u6709\u7b26\u53f7\u548c\u65e0\u7b26\u53f7\u4e24\u5927\u7c7b \u7c7b\u578b \u63cf\u8ff0 u [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,449],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/7917"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7917"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/7917\/revisions"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}