{"id":7919,"date":"2023-01-28T13:43:00","date_gmt":"2023-01-28T05:43:00","guid":{"rendered":"https:\/\/egonlin.com\/?p=7919"},"modified":"2023-01-28T13:43:00","modified_gmt":"2023-01-28T05:43:00","slug":"14-%e5%9f%ba%e6%9c%ac%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e4%b9%8b%e6%b5%ae%e7%82%b9%e4%b8%8e%e5%a4%8d%e6%95%b0","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=7919","title":{"rendered":"14 \u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u6d6e\u70b9\u4e0e\u590d\u6570"},"content":{"rendered":"<h1>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u6d6e\u70b9\u4e0e\u590d\u6570<\/h1>\n<h2>\u4e00 \u6d6e\u70b9\u578b\u4ecb\u7ecd<\/h2>\n<p>Go\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e24\u79cd\u7cbe\u5ea6\u7684\u6d6e\u70b9\u6570\uff0c\u5355\u7cbe\u5ea6float32\u548c\u53cc\u7cbe\u5ea6float64\u3002\u5b83\u4eec\u7684\u7b97\u672f\u89c4\u8303\u7531IEEE754\u6d6e\u70b9\u6570\u56fd\u9645\u6807\u51c6\u5b9a\u4e49\uff0c\u8be5\u6d6e\u70b9\u6570\u89c4\u8303\u88ab\u6240\u6709\u73b0\u4ee3\u7684CPU\u652f\u6301\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u8303\u56f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>float32<\/td>\n<td>\u6700\u5c0f\u8fd1\u4f3c\u503c1.4e-45\uff0c\u5177\u4f53\u53ef\u4ee5\u7528\u901a\u8fc7math.SmallestNonzeroFloat32\u67e5\u770b<br \/>\u6700\u5927\u8fd1\u4f3c\u503c\u5927\u7ea6\u662f3.4e38\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7math.MaxFloat32\u67e5\u770b<\/td>\n<\/tr>\n<tr>\n<td>float64<\/td>\n<td>\u6700\u5c0f\u8fd1\u4f3c\u503c4.9e-324\uff0c\u5177\u4f53\u53ef\u4ee5\u7528\u901a\u8fc7math.SmallestNonzeroFloat64\u67e5\u770b<br \/>\u6700\u5927\u8fd1\u4f3c\u503c\u5927\u7ea6\u662f1.8e308\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7math.MaxFloat64\u67e5\u770b<\/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<\/p>\n<pre><code class=\"language-go\">var \u53d8\u91cf\u540d \u6d6e\u70b9\u578b\u7c7b\u578b = \u521d\u59cb\u5316\u8868\u8fbe\u5f0f\/\u5b57\u9762\u91cf<\/code><\/pre>\n<p>\u683c\u5f0f\u5316\u8f93\u51fa<\/p>\n<pre><code class=\"language-go\">var f float64 = 3.931\nfmt.Printf(&quot;%8.3f\\n&quot;, f) \/\/ \u603b\u5bbd\u5ea6\u4e3a8\uff0c\u4fdd\u75593\u4f4d\u5c0f\u6570\uff08\u56db\u820d\u4e94\u5165\uff09\uff0c\u4e0d\u591f\u5728\u5de6\u4fa7\u586b\u5145\u7a7a\u683c\uff0c\u8f93\u51fa\u4e3a3.931\uff0c\u524d\u9762\u67093\u4e2a\u586b\u5145\u7684\u7a7a\u683c<\/code><\/pre>\n<p><strong>\u6ce8\u610f\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>1\u3001\u5bbd\u5ea6\u4e5f\u662f\u7c7b\u578b\u7684\u4e00\u90e8\u5206\uff0cfloat32\u4e0efloat64\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u7c7b\u578b<\/li>\n<\/ul>\n<pre><code class=\"language-go\">var x float32 = 10.1\nvar y float64\ny = x  \/\/ \u9519\u8bef<\/code><\/pre>\n<ul>\n<li>2\u3001\u7c7b\u578b\u63a8\u5bfc\u7684\u6d6e\u70b9\u578b\u9ed8\u8ba4\u4e3afloat64<\/li>\n<\/ul>\n<pre><code class=\"language-go\">f := 3.931\nfmt.Printf(&quot;%T\\n&quot;,f)  \/\/ float64<\/code><\/pre>\n<ul>\n<li>3\u3001\u5982\u679c\u4e0d\u52a0\u5c0f\u6570\u70b9\uff0c\u9ed8\u8ba4\u4f1a\u88ab\u63a8\u5bfc\u4e3a\u6574\u578b\u800c\u4e0d\u662f\u6d6e\u70b9\u578b<\/li>\n<\/ul>\n<pre><code class=\"language-go\">f := 3\nfmt.Printf(&quot;%T\\n&quot;,f)  \/\/ int\n\nf1 := 3.0\nfmt.Printf(&quot;%T\\n&quot;,f1)  \/\/ float64<\/code><\/pre>\n<ul>\n<li>4\u3001\u901a\u5e38\u5e94\u8be5\u4f18\u5148\u4f7f\u7528float64\uff0c\u56e0float64\u7684\u7cbe\u5ea6\u4ee5\u53ca\u8868\u793a\u7684\u6b63\u6574\u6570\u8303\u56f4\u90fd\u8981\u6bd4float32\u5927<\/li>\n<\/ul>\n<pre><code class=\"language-go\">var x float32 =3.6666666666666666666666666666666666666666\nfmt.Println(x)  \/\/ 3.6666667\nvar y float64 =3.6666666666666666666666666666666666666666\nfmt.Println(y)  \/\/ 3.6666666666666665 ,\u5f88\u660e\u663efloat64\u7cbe\u5ea6\u4e5f\u8981\u641e\u4e00\u4e9b\n\n\/\/ ps\uff1a\u5982\u679c\u6211\u4eec\u5b58\u4e3a\u65e0\u7c7b\u578b\u5e38\u91cf\uff0c\u5c06\u4f1a\u83b7\u53d6\u66f4\u9ad8\u7684\u7cbe\u5ea6<\/code><\/pre>\n<ul>\n<li>5\u3001\u9488\u5bf9\u5b57\u9762\u503c\u8fd0\u7b9710+10.3\u4f1a\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3afloat64\uff0c\u7ed3\u679c\u4e5f\u4e3afloat64\uff0c\u5173\u4e8e\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u8be6\u89c1\u4e0b\u4e00\u5c0f\u8282<\/li>\n<\/ul>\n<pre><code class=\"language-go\">fmt.Printf(&quot;%T\\n&quot;, 10+10.3)           \/\/ float64\nfmt.Printf(&quot;%T\\n&quot;, 10+float32(10.3))    \/\/ float32<\/code><\/pre>\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;\u6d6e\u70b9\u578b<\/strong>\uff0c\u5176\u5b9e\u4e0e\u4e0a\u4e00\u5c0f\u8282\u4ecb\u7ecd\u7684\u8f6c\u6362\u5957\u8def\u90fd\u662f\u4e00\u6837\u7684\uff0c\u5982\u4e0b<\/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\u6d6e\u70b9\u578b\uff0c\u8d85\u51fa\u76ee\u6807\u7c7b\u578b\u503c\u57df\u8303\u56f4\u5c31\u62a5\u9519<\/strong><\/p>\n<pre><code class=\"language-go\">fmt.Println(math.MaxFloat32)  \/\/ 3.4028234663852886e+38\uff0c\u79d1\u5b66\u8ba1\u6570\u6cd5\uff0ce+38\u4ee3\u886810\u768438\u6b21\u65b9\nfmt.Println(math.SmallestNonzeroFloat32)  \/\/ 1.401298464324817e-45\n\n\/\/ \u8d85\u51fa\u8303\u56f4\u5219\u62a5\u9519\nfmt.Println(float32(1000000000000000000000000000000000000000))  \/\/ \u8d85\u8fc7\u6700\u5927\u503c\n\n\/\/ ps\uff1a\u5728\u6ca1\u6709\u8d85\u8fc7\u503c\u57df\u8303\u56f4\u7684\u60c5\u51b5\u4e0b\uff0c\u56e0\u4e3a\u7cbe\u5ea6\u5f71\u54cd\uff0c\u4e0b\u8ff0\u4e09\u884c\u7ed3\u679c\u90fd\u4e00\u6837\nfmt.Println(float32(340282346638528860000000000000000000000))  \/\/ 3.4028235e+38\nfmt.Println(float32(340282346638528865555555555555555555555))  \/\/ 3.4028235e+38\nfmt.Println(float32(340282346638528869999999999999999999999))  \/\/ 3.4028235e+38<\/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\u6d6e\u70b9\u578b\uff0c\u8d85\u51fa\u76ee\u6807\u7c7b\u578b\u503c\u57df\u8303\u56f4\u4e0d\u62a5\u9519\uff0c\u4f46\u662f\u6d6e\u70b9\u6570\u4f1a\u6ea2\u51fa\uff0c\u5e94\u8be5\u5c3d\u91cf\u907f\u514d<\/strong><\/p>\n<pre><code class=\"language-go\">fmt.Println(math.MaxFloat64)  \/\/ 1.7976931348623157e+308\nvar x float64 = 1.7976931348623157e+308\n\nfmt.Println(float32(x))  \/\/ \u8f93\u51fa+Inf\u4ee3\u8868\u6ea2\u51fa<\/code><\/pre>\n<p>\u5f3a\u8c03\uff1a\u6211\u4eec\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u6ea2\u51fa\uff01\uff01\u5927\u591a\u6570\u60c5\u51b5\u60c5\u51b5\u4e0b\uff0c\u53ea\u662f\u4e3a\u4e86\u7edf\u4e00\u7c7b\u578b\uff0c\u800c\u4e0d\u8981\u6539\u53d8\u539f\u503c<\/p>\n<pre><code class=\"language-go\">var apples int32 = 1\nvar oranges int16 = 2\nvar compote = float32(apples) + float32(oranges)\nfmt.Printf(\"%T,%v\\n\",compote,compote) \/\/ float32,3<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u4e8c\uff1a\u9690\u5f0f\u8f6c\u6362\uff0c\u53ea\u9488\u5bf9\u65e0\u7c7b\u578b\u7684\u91cf<\/p>\n<pre><code class=\"language-go\">var x float64 = 10.3\nfmt.Printf(&quot;%T\\n&quot;,x + 10.66)  \/\/ float64<\/code><\/pre>\n<h2>\u56db \u57fa\u672c\u64cd\u4f5c<\/h2>\n<h3>4.1 \u4e8c\u5143\u8fd0\u7b97<\/h3>\n<p>\u6d6e\u70b9\u578b\u4e5f\u5c5e\u4e8e\u6570\u5b57\uff0c\u91cd\u7533\u4e00\u904d\uff1a\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\u3002\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 float64 = 10\nvar y float32 = 20\nfmt.Println(x + y)  \/\/ \u9519\u8bef\uff1amismatched types float64 and float32\nfmt.Println(x + float64(y))  \/\/ \u6b63\u786e\n\n\/\/ \u4f8b2\uff1a\u9690\u5f0f\u8f6c\u6362\nvar x float64 = 10\nfmt.Println(x + 10.3) \/\/ \u9690\u5f0f\u8f6c\u6362float64(10.3)\uff0c\u6b63\u786e\uff0c\u7ed3\u679c\u4e3a\uff1a20.3\nfmt.Println(x + 10.0) \/\/ \u9690\u5f0f\u8f6c\u6362float64(10.0)\uff0c\u6b63\u786e\uff0c\u7ed3\u679c\u4e3a\uff1a20\n\n\/\/ \u4f8b3\uff1a\u663e\u5f0f\u8f6c\u6362\nvar x int32 = 1\nvar y int64 = 2\nvar z = float64(x) + float64(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 float64 = 10.3\nvar y float64 = 10.3\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\n\/\/var i float64 = 10.3\n\/\/var j float32 = 10.3\n\/\/fmt.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 m float64 = 10.3\nfmt.Println(m == 10.3)  \/\/ \u53ef\u4ee5\u6bd4\u8f83\uff0c\u56e0\u4e3a\u5e95\u5c42\uff1ax == float64(10.3)\uff0c\u7f16\u8bd1\u901a\u8fc7\nfmt.Println(m == 10)    \/\/ \u53ef\u4ee5\u6bd4\u8f83\uff0c\u56e0\u4e3a\u5e95\u5c42\uff1ax == float64(10)\uff0c\u7f16\u8bd1\u901a\u8fc7<\/code><\/pre>\n<p>\uff083\uff09\u6bd4\u5927\u5c0f<\/p>\n<pre><code class=\"language-go\">var x float32 = 10\nvar y float64 = 3\n\n\/\/ \u663e\u5f0f\n\/\/fmt.Println(x &gt; y)           \/\/ \u7f16\u8bd1\u9519\u8bef\nfmt.Println(x &gt; float32(y))    \/\/ \u7f16\u8bd1\u901a\u8fc7\n\n\/\/ \u9690\u5f0f\nfmt.Println(x &gt; 3)      \/\/ x &gt; float32(3)\uff0c\u7f16\u8bd1\u901a\u8fc7\nfmt.Println(x &gt; 3.1)    \/\/ x &gt; float32(3.1)\uff0c\u7f16\u8bd1\u901a\u8fc7\n\n\/\/ \u9690\u5f0f\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<h3>4.2 \u6d6e\u70b9\u6570\u7cbe\u5ea6\u95ee\u9898\u63d0<\/h3>\n<p>\u56e0\u4e3a\u6d6e\u70b9\u6570\u4e0d\u662f\u4e00\u79cd\u7cbe\u786e\u7684\u8868\u8fbe\u65b9\u5f0f\uff0c\u6240\u4ee5\u50cf\u6574\u578b\u90a3\u6837\u76f4\u63a5\u7528==\u6765\u5224\u65ad\u4e24\u4e2a\u6d6e\u70b9\u6570\u662f\u5426\u76f8\u7b49\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e0d\u7a33\u5b9a\u7684\u7ed3\u679c\uff0c\u4f8b\u5982<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n)\nfunc main() {\n    x := 0.1\n    y := 0.2\n\n    res := x + y\n    fmt.Println(res)        \/\/ 0.30000000000000004\n    fmt.Println(res == 0.3) \/\/ false\n\n}<\/code><\/pre>\n<p>\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848\u8be6\u89c1\u300a\u9644\u5f55\uff1a\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\u95ee\u9898\u300b\uff0c\u7cbe\u5ea6\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u89c1\u4f60\u6587\u7ae0\u672b\u5c3e\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u65e0\u7c7b\u578b\u7684\u5e38\u91cf\u6709\u66f4\u9ad8\u7684\u8ba1\u7b97\u7cbe\u5ea6<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\n    const x = 0.1\n    const y = 0.2\n\n    res := x + y\n    fmt.Println(res)        \/\/ 0.3\n    fmt.Println(res == 0.3) \/\/ true\n\n    var m = 0.3\n    fmt.Println(m == 0.1+0.2) \/\/ true\n<\/code><\/pre>\n<h3>4.3 \u975e\u6570<\/h3>\n<p>\u4e86\u89e3\uff1a\u6d6e\u70b9\u6570\u91cc\u6709\u4e2a\u53eb\u975e\u6570\u7684\u4e1c\u897f<\/p>\n<pre><code class=\"language-go\">fmt.Println(math.NaN()) \/\/ NaN\n\nvar z float32\nfmt.Println(z) \/\/ 0\nfmt.Println(z\/z) \/\/ NaN\n\nx:=z\/z\nfmt.Println(x &lt; x) \/\/ false\nfmt.Println(x &gt; x) \/\/ false \nfmt.Println(x == x) \/\/ false\nfmt.Println(x != x) \/\/ true<\/code><\/pre>\n<h2>\u4e94 \u5728\u51fd\u6570\u53c2\u6570\u4e2d\u4f20\u9012<\/h2>\n<p>\u503c\u4f20\u9012<\/p>\n<h2>\u516d \u590d\u6570<\/h2>\n<pre><code>Go\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e24\u79cd\u7cbe\u5ea6\u7684\u590d\u6570\u7c7b\u578b\uff1acomplex64\u548ccomplex128\uff0c\u590d\u6570\u5b9e\u9645\u4e0a\u7531\u4e24\u4e2a\u5b9e\u6570\uff08\u5728\u8ba1\u7b97\u673a\u4e2d\u7528\u6d6e\u70b9\u6570\u8868\u793a\uff0ccomplex64\u5bf9\u5e94\u7684\u662ffloat32\uff0ccomplex128\u5bf9\u5e94\u7684\u662ffloat64\uff09\u6784\u6210\uff0c\u4e00\u4e2a\u8868\u793a\u5b9e\u90e8\uff08real\uff09\uff0c\u4e00\u4e2a\u8868\u793a\u865a\u90e8\uff08imag\uff09\u3002<\/code><\/pre>\n<p>\u5185\u7f6e\u7684complex\u51fd\u6570\u7528\u4e8e\u6784\u5efa\u590d\u6570\uff0c\u5185\u5efa\u7684real\u548cimag\u51fd\u6570\u5206\u522b\u8fd4\u56de\u590d\u6570\u7684\u5b9e\u90e8\u548c\u865a\u90e8\uff1a<\/p>\n<pre><code class=\"language-go\">var x complex128 = complex(1, 2) \/\/ 1+2i\nvar y complex128 = complex(3, 4) \/\/ 3+4i\nfmt.Println(x*y)                 \/\/ &quot;(-5+10i)&quot;\nfmt.Println(real(x*y))           \/\/ &quot;-5&quot;\nfmt.Println(imag(x*y))           \/\/ &quot;10&quot;<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u4e2a\u6d6e\u70b9\u6570\u9762\u503c\u6216\u4e00\u4e2a\u5341\u8fdb\u5236\u6574\u6570\u9762\u503c\u540e\u9762\u8ddf\u7740\u4e00\u4e2ai\uff0c\u4f8b\u59823.141592i\u62162i\uff0c\u5b83\u5c06\u6784\u6210\u4e00\u4e2a\u590d\u6570\u7684\u865a\u90e8\uff0c\u590d\u6570\u7684\u5b9e\u90e8\u662f0\uff1a<\/p>\n<pre><code class=\"language-go\">fmt.Println(1i * 1i) \/\/ i^2 = -1 \uff0c\u5b9e\u90e8\u4e3a-1\uff0c\u865a\u90e8\u4e3a0\uff0c\u7ed3\u679c\u8bb0\u4e3a\u590d\u6570\u5f62\u5f0f(-1+0i)\n<\/code><\/pre>\n<p>\u5728\u5e38\u91cf\u7b97\u672f\u89c4\u5219\u4e0b\uff0c\u4e00\u4e2a\u590d\u6570\u5e38\u91cf\u53ef\u4ee5\u52a0\u5230\u53e6\u4e00\u4e2a\u666e\u901a\u6570\u503c\u5e38\u91cf\uff08\u6574\u6570\u6216\u6d6e\u70b9\u6570\u3001\u5b9e\u90e8\u6216\u865a\u90e8\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u81ea\u7136\u7684\u65b9\u5f0f\u4e66\u5199\u590d\u6570\uff0c\u5c31\u50cf1+2i\u6216\u4e0e\u4e4b\u7b49\u4ef7\u7684\u5199\u6cd52i+1\u3002\u4e0a\u9762x\u548cy\u7684\u58f0\u660e\u8bed\u53e5\u8fd8\u53ef\u4ee5\u7b80\u5316\uff1a<\/p>\n<pre><code class=\"language-Go\">x := 1 + 2i\ny := 3 + 4i<\/code><\/pre>\n<p>\u590d\u6570\u4e5f\u53ef\u4ee5\u7528==\u548c!=\u8fdb\u884c\u76f8\u7b49\u6bd4\u8f83\u3002\u53ea\u6709\u4e24\u4e2a\u590d\u6570\u7684\u5b9e\u90e8\u548c\u865a\u90e8\u90fd\u76f8\u7b49\u7684\u65f6\u5019\u5b83\u4eec\u624d\u662f\u76f8\u7b49\u7684\uff08\u8bd1\u6ce8\uff1a\u6d6e\u70b9\u6570\u7684\u76f8\u7b49\u6bd4\u8f83\u662f\u5371\u9669\u7684\uff0c\u9700\u8981\u7279\u522b\u5c0f\u5fc3\u5904\u7406\u7cbe\u5ea6\u95ee\u9898\uff09\u3002<\/p>\n<p>math\/cmplx\u5305\u63d0\u4f9b\u4e86\u590d\u6570\u5904\u7406\u7684\u8bb8\u591a\u51fd\u6570\uff0c\u4f8b\u5982\u6c42\u590d\u6570\u7684\u5e73\u65b9\u6839\u51fd\u6570\u548c\u6c42\u5e42\u51fd\u6570\uff0c\u66f4\u591a\u5173\u4e8e\u590d\u6570\u7684\u51fd\u6570\uff0c\u8bf7\u67e5\u9605math\/cmplx\u6807\u51c6\u5e93\u7684\u6587\u6863\u3002<\/p>\n<pre><code class=\"language-Go\">fmt.Println(cmplx.Sqrt(-1)) \/\/ &quot;(0+1i)&quot;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u6d6e\u70b9\u4e0e\u590d\u6570 \u4e00 \u6d6e\u70b9\u578b\u4ecb\u7ecd Go\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e24\u79cd\u7cbe\u5ea6\u7684\u6d6e\u70b9\u6570\uff0c\u5355\u7cbe\u5ea6float32\u548c\u53cc\u7cbe\u5ea6floa [&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\/7919"}],"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=7919"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/7919\/revisions"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}