TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

“Fixing” the rules of division

13 pointsby memorableover 2 years ago

2 comments

eesmithover 2 years ago
Ahh, so Ruby doesn&#x27;t - and can&#x27;t[1] - support constant folding.<p>In CPython, because monkey-patching like this isn&#x27;t supported, the byte compiler turns a &quot;0&#x2F;2&quot; into a &quot;0.0&quot;, as you can see with:<p><pre><code> &gt;&gt;&gt; def f(): ... return 0 &#x2F; 2 ... &gt;&gt;&gt; import dis &gt;&gt;&gt; dis.dis(f) 2 0 LOAD_CONST 1 (0.0) 2 RETURN_VALUE </code></pre> [1] EDIT: except through something like whole-program analysis.
评论 #33566519 未加载
Joker_vDover 2 years ago
&gt; Long division makes my head hurt!<p>Well, I suspect it has something to do with writing out the process of 5772 &#x2F; 37 as<p><pre><code> 156 ______ 37 | 5772 37 --- 207 185 ---- 222 222 --- 0 </code></pre> because it a) reverses the order of dividend and divisor for no good reason; b) the result goes up instead of to the right or down. Why not write it like this<p><pre><code> 5772 | 37 37 +---- --- 156 207 185 ---- 222 222 --- 0 </code></pre> instead? In fact, I think we could replace the corner with just normal slash, &quot;&#x2F;&quot;, write = to the right of the divisor and spell out the digits of the result to the right of it; the substraction chain will still go down the page.
评论 #33565848 未加载
评论 #33565681 未加载