<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Algorithm on omegaatt</title>
    <link>https://www.omegaatt.com/tags/algorithm/</link>
    <description>Recent content in Algorithm on omegaatt</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>zh-TW</language>
    <managingEditor>raiven.kao@gmail.com (Raiven Kao)</managingEditor>
    <webMaster>raiven.kao@gmail.com (Raiven Kao)</webMaster>
    <copyright>Raiven Kao 2020 - 2026</copyright>
    <lastBuildDate>Wed, 26 Aug 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.omegaatt.com/tags/algorithm/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Unrounded Scaling：Go 1.27 浮點數轉換演算法的深度拆解</title>
      <link>https://www.omegaatt.com/blogs/develop/2026/golang_unrounded_scaling/</link>
      <pubDate>Wed, 26 Aug 2026 00:00:00 +0000</pubDate><author>raiven.kao@gmail.com (Raiven Kao)</author>
      <guid>https://www.omegaatt.com/blogs/develop/2026/golang_unrounded_scaling/</guid>
      <description>&lt;h2 id=&#34;前言&#34;&gt;前言&lt;/h2&gt;
&lt;p&gt;如果你對浮點數還不了解，可以服用這個&lt;a href=&#34;https://www.youtube.com/watch?v=g1r3iLejTw0&amp;amp;list=PLwy0WTzBokTMHqq_-TQRNmaHWEuPgsGUc&#34;&gt;影片&lt;/a&gt;。&lt;/p&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#34;https://www.youtube.com/embed/g1r3iLejTw0?si=bRcAcBeUxO5bfX-m&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;TL;DR 前面三分之二是演算法拆解，有興趣再啃。只想知道「Go 1.27 實際上改了什麼、變多快、輸出有沒有跑掉」的話，可以直接跳到 &lt;a href=&#34;#go-127-%E5%88%B0%E5%BA%95%E6%94%B9%E4%BA%86%E4%BB%80%E9%BA%BC&#34;&gt;Go 1.27 到底改了什麼&lt;/a&gt;，結論是 878 行三套演算法變成 290 行一套、快了 11–21%、輸出零變化。&lt;/p&gt;
&lt;p&gt;我把 Go 升到 1.27 之後，照慣例翻了一遍 &lt;a href=&#34;https://go.dev/doc/go1.27&#34;&gt;release notes&lt;/a&gt;，也寫了&lt;a href=&#34;https://www.omegaatt.com/blogs/develop/2026/golang_1_27_new_features/&#34;&gt;新特性整理&lt;/a&gt;。整份文件從頭到尾沒有一個字提到 &lt;code&gt;strconv&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;但是 Go 1.27 把 &lt;code&gt;fmt.Sprintf(&amp;quot;%v&amp;quot;, f)&lt;/code&gt;、&lt;code&gt;strconv.ParseFloat&lt;/code&gt;、&lt;code&gt;json.Marshal&lt;/code&gt; 底下那顆浮點數轉換引擎整個換掉了。舊的實作是三套演算法各自為政：最短列印用 Dragonbox、固定位數列印用 Ryū 風格的程式碼、解析用 Eisel-Lemire，新的實作是一個叫 unrounded scaling 的東西，作者是 Russ Cox，論文是 2026 年 1 月才發表的。&lt;/p&gt;
&lt;p&gt;這件事之所以值得寫一篇，是因為 Russ Cox 在 2011 年寫過一篇 &lt;a href=&#34;https://research.swtch.com/ftoa&#34;&gt;Floating Point to Decimal Conversion is Easy&lt;/a&gt;，副標題是 Part 1。文章的論點是：&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Floating point to decimal conversions have a reputation for being difficult. At heart, they&amp;rsquo;re really very simple and straightforward.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
