{"id":207793,"date":"2025-07-08T12:09:20","date_gmt":"2025-07-08T04:09:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207793\/"},"modified":"2025-07-08T12:09:20","modified_gmt":"2025-07-08T04:09:20","slug":"go1-10-%e4%b9%8b%e5%89%8d%e7%9a%84%e5%a4%a9%e8%8a%b1%e6%9d%bf%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207793\/","title":{"rendered":"go1.10 \u4e4b\u524d\u7684\u5929\u82b1\u677f\u529f\u80fd"},"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>go1.10 \u4e4b\u524d\u7684\u5929\u82b1\u677f\u529f\u80fd<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-25 17:39:31<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300ago1.10 \u4e4b\u524d\u7684\u5929\u82b1\u677f\u529f\u80fd\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u9700\u8981\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u201cCeil\u201d\u51fd\u6570\uff0c\u5b83\u7684\u5de5\u4f5c\u65b9\u5f0f\u7c7b\u4f3c\u4e8e go1.10 \u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u5c31\u50cf\u6211\u4eec\u5728 v1.9 \u4e0a\u4e00\u6837\uff08obv \u4e0d\u4f1a\u90a3\u4e48\u9ad8\u6548\uff0c\u4f46\u6ca1\u5173\u7cfb\uff09 \u4f8b\u5982 <code>Ceil(0.33) = 1.00 <\/code><\/p>\n<p>\u6211\u5df2\u7ecf\u770b\u5230\u4e86\u4e00\u4e9b\u901a\u7528\u7684\u6700\u8fd1\u6574\u6570\u820d\u5165\u89e3\u51b3\u65b9\u6848\uff0c\u4f46\u662f\uff0c\u60f3\u77e5\u9053\u662f\u5426\u6709\u4eba\u4e3a v1.9 \u5b9e\u73b0\u4e86\u7b49\u6548\u7684\u201cCeil\u201d\u51fd\u6570\u4f5c\u4e3a\u89e3\u51b3\u65b9\u6cd5\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u7531\u4e8ego\u662f\u5f00\u6e90\u7684\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4ed6\u4eec\u7684\u4ee3\u7801\uff1a<\/p>\n<p>\u6211\u5df2\u7ecf\u7814\u7a76\u4e86\u4ee3\u7801\u5e76\u4e3a\u60a8\u63d0\u53d6\u4e86\u6240\u6709\u7684\u96f6\u788e\u5185\u5bb9\u5230\u4e2d\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"unsafe\"\n)\n\nfunc main() {\n    fmt.Println(ceil(1.5))\n    fmt.Println(ceil(0.5))\n    fmt.Println(ceil(0.0))\n    fmt.Println(ceil(-0.5))\n    fmt.Println(ceil(-1.5))\n}\n\nfunc ceil(x float64) float64 {\n    return -floor(-x)\n}\n\nfunc floor(x float64) float64 {\n    if x == 0 || isNaN(x) || isInf(x, 0) {\n        return x\n    }\n    if x &lt; 0 {\n        d, fract := modf(-x)\n        if fract != 0.0 {\n            d = d + 1\n        }\n        return -d\n    }\n    d, _ := modf(x)\n    return d\n}\n\nfunc isNaN(f float64) (is bool) {\n    return f != f\n}\n\nfunc isInf(f float64, sign int) bool {\n    return sign &gt;= 0 &amp;&amp; f &gt; maxFloat64 || sign &lt;= 0 &amp;&amp; f &lt; -maxFloat64\n}\n\nfunc modf(f float64) (int float64, frac float64) {\n    if f &lt; 1 {\n        switch {\n        case f &lt; 0:\n            int, frac = modf(-f)\n            return -int, -frac\n        case f == 0:\n            return f, f\n        }\n        return 0, f\n    }\n\n    x := float64bits(f)\n    e := uint(x&gt;&gt;shift)&amp;mask - bias\n\n    if e &lt; 64-12 {\n        x &amp;^= 1&lt;&lt;(64-12-e) - 1\n    }\n    int = float64frombits(x)\n    frac = f - int\n    return\n}\n\nconst (\n    maxFloat64 = 1.797693134862315708145274237317043567981e+308\n    mask       = 0x7FF\n    shift      = 64 - 11 - 1\n    bias       = 1023\n)\n\nfunc float64bits(f float64) uint64 {\n    return *(*uint64)(unsafe.Pointer(&amp;f))\n}\n\nfunc float64frombits(b uint64) float64 {\n    return *(*float64)(unsafe.Pointer(&amp;b))\n}<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300ago1.10 \u4e4b\u524d\u7684\u5929\u82b1\u677f\u529f\u80fd\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207793","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207793"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207793\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}