Park Hyunwoo's Avatar

Park Hyunwoo

@lqez.dev.bsky.social

unemployed @ zerobased.co

49 Followers  |  25 Following  |  8 Posts  |  Joined: 13.06.2023  |  1.7882

Latest posts by lqez.dev on Bluesky

Post image

슬슬 수리점 용품이 갖춰져간다

25.01.2025 09:44 — 👍 0    🔁 0    💬 0    📌 0

그러니까 이에 대해서 만든 자료가 있었지요 cojette.github.io/posts/infcon...

27.12.2024 15:03 — 👍 20    🔁 45    💬 0    📌 1
Post image

작업실 이사 기념 화분 선물 받았다

12.12.2024 14:06 — 👍 2    🔁 0    💬 0    📌 0
Post image

것 참 제법 이름이 길구나

Pie Dome Roof three types of Mushroom cream soup

Pie Dome Roof Chill Con Carne Beef Witch's Soup

11.12.2024 14:47 — 👍 1    🔁 0    💬 0    📌 0
Post image

KFC에는 파이가 날라다니네

10.12.2024 13:39 — 👍 0    🔁 0    💬 0    📌 0
Preview
Python の isnumeric() の謎を追う:"兆" は True、"垓" は False? <p>この記事は <a href="https://adventar.org/calendars/10134">2024 TSG Advent Calendar</a> 初日の記事です。</p> <p><span itemscope="" itemtype="http://schema.org/Photograph"><img class="hatena-fotolife" height="675" itemprop="image" loading="lazy" src="https://cdn-ak.f.st-hatena.com/images/fotolife/s/sh-mug/20241119/20241119233235.png" title="" width="1200"/></span></p> <p><span style="font-size: 300%">…………🤔❓</span></p> <h3 id="Python-の数値文字列判定ロジックを探る"><a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の数値文字列判定ロジックを探る</h3> <h4 id="strisnumeric-メソッドとは">str.isnumeric() メソッドとは?</h4> <p><a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の <code>str.isnumeric()</code> メソッドは、文字列内のすべての文字が数値を表すものであれば True を、そうでなければ False を返します。<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#f-3ca21f31" id="fn-3ca21f31" name="fn-3ca21f31" title='つまり、文字列全体が数の表現として正しいかとは無関係です。たとえば、"123.45".isnumeric() は False、"兆兆".isnumeric() は True を返します。'>*1</a> まず、このメソッドの基本的な動作を見てみましょう。</p> <pre class="code lang-python" data-lang="python" data-unlink=""><span class="synComment"># Python の isnumeric() の動作例</span> <span class="synIdentifier">print</span>(<span class="synConstant">"123"</span>.isnumeric()) <span class="synComment"># True; 1, 2, 3 は数字</span> <span class="synIdentifier">print</span>(<span class="synConstant">"123a"</span>.isnumeric()) <span class="synComment"># False; a は数字ではない</span> <span class="synIdentifier">print</span>(<span class="synConstant">"五千万"</span>.isnumeric()) <span class="synComment"># True; 五、千、万 は数値</span> </pre> <p>漢数字にも対応しており、一見よさそうに見えます。ところが……</p> <pre class="code lang-python" data-lang="python" data-unlink=""><span class="synIdentifier">print</span>(<span class="synConstant">"兆"</span>.isnumeric()) <span class="synComment"># True</span> <span class="synIdentifier">print</span>(<span class="synConstant">"垓"</span>.isnumeric()) <span class="synComment"># False</span> </pre> <p>「兆」と「垓」はどちらも漢数字に使われる文字なのに、なぜ <a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の str.isnumeric() は異なる結果を返すのでしょうか?</p> <h4 id="Python-と-Unicode-文字データベース"><a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> と <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 文字データベース</h4> <p><a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の文字列メソッド <code>str.isnumeric()</code> は、内部的に <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の情報を活用しています。<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> とは、世界中の文字を一元管理するための国際的な規格で、それぞれの文字がどんな性質を持つのかを「<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 文字データベース (UCD)」<sup id="fnref:1"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:1" rel="footnote">1</a></sup> という形で記録しています。データベースには「絵文字かどうか (Emoji)」や「大文字かどうか (Uppercase)」といった属性が文字ごとに記録されています。</p> <p>その中で、この記事で鍵になる情報は <strong>Numeric_Type プロパティ</strong> です。このプロパティは、文字が「数値」として扱われるかを示したもので、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の <code>str.isnumeric()</code> もこの情報を元に判断を行っています。</p> <p>Numeric_Type プロパティには以下の 4 種類があります。<code>str.isnumeric()</code> の正式な仕様<sup id="fnref:2"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:2" rel="footnote">2</a></sup> には、文字がこのうち <strong>Decimal, Digit, Numeric</strong> のいずれかである場合に True を返す、というふうに定めてあります。</p> <table> <thead> <tr> <th> Numeric_Type </th> <th> 説明 </th> <th> 例 </th> </tr> </thead> <tbody> <tr> <td> <strong>Decimal</strong> </td> <td> 十進法 (0~9) で使われる基本的な数字 </td> <td> U+0030~U+0039(アラビア数字 "0"~"9")<br/>U+0660~U+0669(<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A5%A2%A5%E9%A5%D3%A5%A2%B8%EC">アラビア語</a>の数字) </td> </tr> <tr> <td> <strong>Digit</strong> </td> <td> 数字として機能するが、十進法の桁として直接使用されない特殊な数字 </td> <td>U+2070(上付きゼロ "⁰")<br/>U+2460(丸付き数字 "①")</td> </tr> <tr> <td> <strong>Numeric</strong> </td> <td> それ以外の数値を表す文字。整数や分数、負の数など幅広い数値が含まれる </td> <td> U+2155(1/5の分数 "⅕")<br/>U+4E00(漢数字 "一") </td> </tr> <tr> <td> None </td> <td> 上記に該当しない文字 </td> <td> U+0041(<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A5%E9%A5%C6%A5%F3%CA%B8%BB%FA">ラテン文字</a> "A")<br/>U+3042(ひらがな "あ") </td> </tr> </tbody> </table> <h4 id="実際に数詞の-Numeric_Type-を見てみる">実際に数詞の Numeric_Type を見てみる</h4> <p>では、これをふまえて、「兆」「垓」を含む日本語の数詞の Numeric_Type をまとめてデータベース<sup id="fnref:3"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:3" rel="footnote">3</a></sup> で確認してみましょう。</p> <table> <thead> <tr> <th> 文字 </th> <th> <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> </th> <th> Numeric_Type </th> <th> str.isnumeric() </th> </tr> </thead> <tbody> <tr> <td> 万 </td> <td> U+4E07 </td> <td> <strong>Numeric</strong> </td> <td> <strong>True</strong> </td> </tr> <tr> <td> 億 </td> <td> U+5104 </td> <td> <strong>Numeric</strong> </td> <td> <strong>True</strong> </td> </tr> <tr> <td> 兆 </td> <td> U+5146 </td> <td> <strong>Numeric</strong> </td> <td> <strong>True</strong> </td> </tr> <tr> <td> 京 </td> <td> U+4EAC </td> <td> <strong>Numeric</strong> </td> <td> <strong>True</strong> </td> </tr> <tr> <td> 垓 </td> <td> U+5793 </td> <td> None </td> <td> False </td> </tr> <tr> <td> 𥝱 </td> <td> U+25771 </td> <td> None </td> <td> False </td> </tr> <tr> <td> 穣 </td> <td> U+7A63 </td> <td> None </td> <td> False </td> </tr> <tr> <td> 溝 </td> <td> U+6E9D </td> <td> None </td> <td> False </td> </tr> <tr> <td> 澗 </td> <td> U+6F97 </td> <td> None </td> <td> False </td> </tr> <tr> <td> 正 </td> <td> U+6B63 </td> <td> None </td> <td> False </td> </tr> <tr> <td> 載 </td> <td> U+8F09 </td> <td> None </td> <td> False </td> </tr> <tr> <td> 極 </td> <td> U+6975 </td> <td> None </td> <td> False </td> </tr> </tbody> </table> <p>すると確かに、「兆」は Numeric_Type=Numeric に分類されている一方、「垓」は分類されていないことがわかります。これが、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の str.isnumeric() メソッドが「兆」と「垓」で異なる結果を返すことへの直接的な理由です!</p> <p>……しかしながら、上の表を見ていると、新たに一つの疑問が沸き上がってきます。なぜ、<strong><a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> は「垓」以上の数詞に Numeric_Type を割り当てていない</strong>のでしょうか?この謎を解くため、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の数詞の扱いについてもう少し掘り下げていきます。</p> <p></p><fieldset style="padding: 8px 15px; border: 2px solid #6699CC; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px;"> <legend><span style="font-size: 15px; color: #6699CC; font-weight:bold;"> Coffee break ☕ <a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>の扱いが変わった? </span> </legend> すこし面白いのは<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>の扱いです。<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>(U+4EAC) は、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 15.1 で Numeric_Type が None から Numeric に変更されました。この変更が <a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> 3.13 から取り入れれられたため<sup id="fnref:4"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:4" rel="footnote">4</a></sup>、これ以降のバージョンで <code>"京".isnumeric()</code> が True を返すようになりました。 <pre class="code lang-python" data-lang="python" data-unlink=""><span class="synComment"># Python 3.12 以前なら False</span> <span class="synComment"># Python 3.13 以降なら True</span> <span class="synIdentifier">print</span>(<span class="synConstant">"京"</span>.isnumeric()) </pre> <p></p></fieldset> <h3 id="京と垓を分けた-Unicode-の判断を探る"><a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>と「垓」を分けた <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の判断を探る</h3> <p>現行の <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> は<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>までの数詞に Numeric_Type を付与しているのにも関わらず、<strong>「垓」以上の数詞には付与していません</strong>。この線引きは、どのような基準で決まったのでしょうか? それを知るためにも、まずは <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> における漢字と Numeric_Type の関係を知っておく必要があります。</p> <h4 id="漢字の-Numeric_Type-を決める仕組み">漢字の Numeric_Type を決める仕組み</h4> <p><a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の漢字(CJK 統合漢字)に関する情報は、UCD とは別の <strong><a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> Han Database (Unihan)</strong><sup id="fnref:5"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:5" rel="footnote">5</a></sup> というデータベースに収録されています。このデータベースには、各漢字の読みや意味、部首だけでなく、数値に関する情報も格納されています。</p> <p>Unihan には kPrimaryNumeric という項目があり、ここにはその漢字が表す数値(たとえば「万」は10<sup>4</sup>)が定義されています。 ある漢字に kPrimaryNumeric が付与されると、それに対応して UCD で Numeric_Type=Numeric が設定される、つまりその漢字が <strong>「数を表す文字」として扱われる</strong>仕組みになっています。</p> <p></p><fieldset style="padding: 8px 15px; border: 2px solid #6699CC; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px;"> <legend><span style="font-size: 15px; color: #6699CC; font-weight:bold;"> Coffee break ☕ Unihan と Numeric_Type </span> </legend> 漢字に Numeric_Type を付与する仕組みは、実際はもう少しいろいろあります。Unihan には kPrimaryNumeric の他にも <ul> <li>kAccountingNumeric: 領収書などで使われる<strong>「壱」「弐」「参」</strong>などの文字</li> <li>kOtherNumeric: 数字として扱うのが一般的でない<strong>「幺」「㠪」</strong>などの文字</li> </ul> <p>などの数値に関するフィールドがいくつかあり、これらのどれかが設定されている場合に Numeric_Type=Numeric が付与される、という仕組みになっています。 </p></fieldset> <h4 id="京と垓の境界線L222-223-提案と-Unicode-技術委員会の判断"><a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>と「垓」の境界線:L2/22-223 提案と <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 技術委員会の判断</h4> <p>つい最近の <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 15.0(2022 年 9 月制定)まで、「万」「億」「兆」までが Numeric_Type を持つ数詞として扱われ、<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>「垓」以降の数詞は Numeric_Type が付与されていませんでした。</p> <p>ここでターニングポイントとなるのが、2022 年 10 月に <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 技術委員会 (<a class="keyword" href="https://d.hatena.ne.jp/keyword/UTC">UTC</a>) に提出された <strong>L2/22-223</strong><sup id="fnref:6"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:6" rel="footnote">6</a></sup> という提案です。L2/22-223 は、Unihan の数値フィールドに関する様々な修正を提案しています。</p> <p>特にその中で、<strong><a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>以上の数詞(京、垓、𥝱、穣、溝、澗)など文字</strong> にも日本語で数値としての用例があることから、kPrimaryNumeric プロパティを追加する、すなわち<strong>新たに Numeric_Type を付与する</strong>ことを提案しているのです! 下の表の太字は、実際に L2/22-223 で追加が提案された kPrimaryNumeric の値です。</p> <table> <thead> <tr> <th> 文字 </th> <th> <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> </th> <th> kPrimaryNumeric(提案は太字) </th> </tr> </thead> <tbody> <tr> <td> 兆 </td> <td> U+5146 </td> <td> 10<sup>12</sup>, <strong>10<sup>6</sup></strong> <a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#f-3d6c48f0" id="fn-3d6c48f0" name="fn-3d6c48f0" title="中国やベトナムで 106 を「兆」と書く慣習があり、現在でも中国本土で SI 接頭辞 106 を表す文字として「兆」を使うようです。">*2</a> </td> </tr> <tr> <td> 京 </td> <td> U+4EAC </td> <td> <strong>10<sup>16</sup></strong> </td> </tr> <tr> <td> 垓 </td> <td> U+5793 </td> <td> <strong>10<sup>20</sup></strong> </td> </tr> <tr> <td> 𥝱 </td> <td> U+25771 </td> <td> <strong>10<sup>24</sup></strong> </td> </tr> <tr> <td> 穣 </td> <td> U+7A63 </td> <td> <strong>10<sup>28</sup></strong> </td> </tr> <tr> <td> 溝 </td> <td> U+6E9D </td> <td> <strong>10<sup>32</sup></strong> </td> </tr> <tr> <td> 澗 </td> <td> U+6F97 </td> <td> <strong>10<sup>36</sup></strong> </td> </tr> </tbody> </table> <p>そして、この L2/22-223 提案をとりまとめた <a class="keyword" href="https://d.hatena.ne.jp/keyword/UTC">UTC</a> の CJK &amp; Unihan 作業部会も、<a class="keyword" href="https://d.hatena.ne.jp/keyword/UTC">UTC</a> に対して上表のすべてを受け入れるよう勧告しました<sup id="fnref:7"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:7" rel="footnote">7</a></sup>。</p> <p>しかしながら、最終的な <a class="keyword" href="https://d.hatena.ne.jp/keyword/UTC">UTC</a> での議論の結果<sup id="fnref:8"><a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn:8" rel="footnote">8</a></sup>、「兆」の 10<sup>6</sup> と<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>の 10<sup>16</sup> のみが <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 15.1 に追加され、他の数詞への kPrimaryNumeric 付与は見送られることとなりました。この決定により、<strong><a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>(U+4EAC) が数値として扱われる最後の文字として認められ</strong>、それ以上の数詞(垓、𥝱など)は対象外となってしまいました。</p> <blockquote><p>[173-A45] Action Item for John Jenkins, CJK: Apply the adjustments to the kAccountingNumeric, kOtherNumeric, and kPrimaryNumeric properties, based on document L2/22-223, as amended in Section 11 of document L2/22-247, and <strong>excluding any property values greater than that for U+4EAC</strong>, for <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> Version 15.1.</p></blockquote> <h4 id="結局なぜ京だけが追加されたのか">結局、なぜ<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>だけが追加されたのか?</h4> <p><a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>までが採用された顛末について、公開資料から読み取れるのはここまでです。しかし、これらの記録を読んでも、具体的に「なぜ『垓』以降が除外されたのか?」という理由は記されていません。</p> <p>そこで、この疑問を解消するために、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の専門家であり、先ほどの勧告を行った CJK &amp; Unihan 作業部会の議長でもある <strong><a class="keyword" href="https://d.hatena.ne.jp/keyword/Ken%20Lunde">Ken Lunde</a></strong> 博士に直接問い合わせを行いました。氏の返信によれば、<strong><a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>(10000000000000000) より上の数詞が除外された理由は、オーバーフローの懸念にある</strong>とのことです。以下は博士からの返信の引用です:</p> <p></p><blockquote class="twitter-tweet" data-conversation="none" data-lang="ja"><p dir="ltr" lang="en">See Consensus 173-C11 from <a href="https://twitter.com/hashtag/UTC173?src=hash&amp;ref_src=twsrc%5Etfw">#UTC173</a>, along with the associated action items, specifically 173-A45. Summary: Any <a class="keyword" href="https://d.hatena.ne.jp/keyword/value">value</a> over 10000000000000000 was explicitly excluded due to overflow concerns. <a href="https://t.co/4mlIljLhhl">https://t.co/4mlIljLhhl</a></p>— <a class="keyword" href="https://d.hatena.ne.jp/keyword/Ken%20Lunde">Ken Lunde</a> 小林剣 (@ken_lunde) <a href="https://twitter.com/ken_lunde/status/1857834598178370041?ref_src=twsrc%5Etfw">2024年11月16日</a></blockquote> <script async="" charset="utf-8" src="https://platform.twitter.com/widgets.js"></script> <p>このような判断が行われた背景には、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> が幅広いシステムや環境で採用されていることが影響しています。オーバーフローのリスクを抱える値を Numeric_Type に含めると、数値処理を行う多くの実装に影響を及ぼす可能性がある、という判断がなされたと考えることができます。</p> <p>実際、64 bit 符号なし整数型が表現できる 0~2<sup>64</sup> -1(およそ 1.8×10<sup>19</sup>)の上界は<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>(10<sup>16</sup>) と「垓」(10<sup>20</sup>) の間に位置します。さらに、一部のシステムでは数値を倍精度<a class="keyword" href="https://d.hatena.ne.jp/keyword/%C9%E2%C6%B0%BE%AE%BF%F4%C5%C0%BF%F4">浮動小数点数</a>型で表現しますが、この型で安全に整数を表現できる上限 <a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#f-7815dffe" id="fn-7815dffe" name="fn-7815dffe" title="JavaScript の Number.MAX_SAFE_INTEGER のことだと思ってください。">*3</a> は約 9×10<sup>15</sup> です。この範囲を超える<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>(10<sup>16</sup>) が Numeric_Type を持つのは、この制約を直接反映したものではないかもしれませんが、それでも比較的小さな値として許容された可能性はあります。</p> <p>あくまで推測ですが、128 bit 整数や任意精度演算が一般的になるような環境が普及すれば、「垓」以降の数詞にも Numeric_Type が付与される可能性があるかもしれません。たとえば、128 bit 符号なし整数を使えば、およそ 3.4×10<sup>38</sup> までの値を安全に表現できます。この範囲なら「澗」(10<sup>36</sup>) も含めることができます。<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> における数詞の扱いも変わっていくには、すなわち <a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の <code>str.isnumeric()</code> が「垓」以降の数詞を数値として扱うようになるには、さらなる計算機環境の進化を待つ必要があるかもしれません。</p> <h3 id="まとめ">まとめ</h3> <p><a class="keyword" href="https://d.hatena.ne.jp/keyword/Python">Python</a> の <code>str.isnumeric()</code> メソッドは、文字列内のすべての文字が「数を表す文字」であるかを判定しますが、<code>"兆"</code> には True、<code>"垓"</code> には False を返します。この理由は、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の Numeric_Type プロパティが「垓」以上の数詞には付与されていないことにありました。</p> <p>さらにその理由を探ると、「垓」~「澗」に対する <a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の数値フィールド修正の提案があったものの、オーバーフローのリスクを懸念して<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A1%D6%B5%FE%A1%D7">「京」</a>までの数詞のみが採用されたことがわかりました。</p> <p><a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> のプロパティ設定には文字の意味以上に、技術的制約など多様な観点から仕様が検討されているのです。</p> <h3 id="謝辞">謝辞</h3> <p>本記事の執筆にあたり、<a href="https://x.com/ken_lunde">Ken Lunde</a> 博士から貴重な情報提供をいただきました。特に、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> の数値扱いに関する技術的な背景についての理解を深めることができましたことに感謝しています。また、<a class="keyword" href="https://d.hatena.ne.jp/keyword/Unicode">Unicode</a> 議事録の<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A5%B5%A1%BC%A5%D9%A5%A4">サーベイ</a>などに、幅広く助力していただいた <a href="https://x.com/hakatashi">hakatashi</a> 氏にもここに謝意を表します。</p> <h3 id="ゴママヨコーナー">ゴママヨコーナー</h3> <p>気軽に読める記事を目指していたのに、すごくまじめな内容になってしまったので、ゴママヨコーナーで中和したいと思います。</p> <ul> <li>「垓」以上 ←⁉</li> <li>Numeric_Type プロパティ ←⁉</li> </ul> <p>他に見つけたらぜひ教えてください。</p> <div class="footnotes"> <hr/> <ol> <li id="fn:1"> <a href="https://www.unicode.org/reports/tr44/">Unicode® Standard Annex #44 - Unicode Character Database</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:1" rev="footnote">↩</a></li> <li id="fn:2"> <a href="https://docs.python.org/3.14/library/stdtypes.html#str.isnumeric">Python documentation - Built-in Types</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:2" rev="footnote">↩</a></li> <li id="fn:3"> <a href="https://www.unicode.org/Public/16.0.0/ucd/extracted/DerivedNumericType.txt">Unicode Character Database - Numeric_Type</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:3" rev="footnote">↩</a></li> <li id="fn:4"> <a href="https://docs.python.org/3/whatsnew/3.13.html#unicodedata">What's New in Python 3.13 - unicodedata</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:4" rev="footnote">↩</a></li> <li id="fn:5"> <a href="https://www.unicode.org/reports/tr38/">Unicode® Standard Annex #38 - Unicode Han Database (Unihan)</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:5" rev="footnote">↩</a></li> <li id="fn:6"> <a href="https://www.unicode.org/L2/L2022/22223-unihan-numeric.pdf">L2/22-223: Proposed Updates and Expansions of Unihan Numeric Fields</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:6" rev="footnote">↩</a></li> <li id="fn:7"> <a href="https://www.unicode.org/L2/L2022/22247-cjk-unihan-group-utc173.pdf">L2/22-247: CJK &amp; Unihan Group Recommendations for UTC #173 Meeting</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:7" rev="footnote">↩</a></li> <li id="fn:8"> <a href="https://www.unicode.org/L2/L2022/22241.htm#173-A45">UTC #173 Minutes</a>、参照日: 2024-11-17<a href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fnref:8" rev="footnote">↩</a></li> </ol> </div> <div class="footnote"> <p class="footnote"><a class="footnote-number" href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn-3ca21f31" id="f-3ca21f31" name="f-3ca21f31">*1</a><span class="footnote-delimiter">:</span><span class="footnote-text">つまり、文字列全体が数の表現として正しいかとは無関係です。たとえば、"123.45".isnumeric() は False、"兆兆".isnumeric() は True を返します。</span></p> <p class="footnote"><a class="footnote-number" href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn-3d6c48f0" id="f-3d6c48f0" name="f-3d6c48f0">*2</a><span class="footnote-delimiter">:</span><span class="footnote-text">中国や<a class="keyword" href="https://d.hatena.ne.jp/keyword/%A5%D9%A5%C8%A5%CA%A5%E0">ベトナム</a>で 10<sup>6</sup> を「兆」と書く慣習があり、現在でも中国本土で SI 接頭辞 10<sup>6</sup> を表す文字として「兆」を使うようです。</span></p> <p class="footnote"><a class="footnote-number" href="https://shmug.hatenablog.com/entry/2024/12/01/000000#fn-7815dffe" id="f-7815dffe" name="f-7815dffe">*3</a><span class="footnote-delimiter">:</span><span class="footnote-text"><a class="keyword" href="https://d.hatena.ne.jp/keyword/JavaScript">JavaScript</a> の Number.MAX_SAFE_INTEGER のことだと思ってください。</span></p> </div>

Unicode에서 「兆」(조)는 Numeric_Type에 들어가는데 「垓」(해)는 Numeric_Type에 안 들어간다고. 왜 그런가 하니 10,000,000,000,000,000보다 큰 수는 오버플로가 날 수 있기 때문에 일부러 뺐다고 한다.

https://shmug.hatenablog.com/entry/2024/12/01/000000

02.12.2024 07:47 — 👍 18    🔁 40    💬 0    📌 1
Post image Post image Post image Post image

이틀이 무슨 일주일 같았다

29.11.2024 16:53 — 👍 0    🔁 0    💬 0    📌 0
Post image

이건 SaaS에서도 잘해야 한다고 생각하는데 어떤 회사가 잘하고 있지? 피그마? 노션?

28.11.2024 06:47 — 👍 0    🔁 0    💬 0    📌 0

옆으로 살짝 더 옮겨앉으면 ‘그 카페’가 무너지는…?!

28.11.2024 06:46 — 👍 2    🔁 0    💬 0    📌 0

오늘 새 결제 모듈 업데이트 배포하고 테스트하는데 애플워치에서 '두근거리는 결제였나요?' 라고 알람이 왔다는 백엔드 개발자의 얘기... 그래 두근거렸겠지 ㅇㅇ...

26.11.2024 04:51 — 👍 2    🔁 2    💬 0    📌 0
Post image Post image

판겨 정ㅋ벅ㅋ 계획 #palmcity

26.11.2024 05:04 — 👍 5    🔁 1    💬 0    📌 0

@lqez.dev is following 20 prominent accounts