{"id":2236,"date":"2010-02-17T19:27:33","date_gmt":"2010-02-18T00:27:33","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=2236"},"modified":"2018-08-31T15:04:29","modified_gmt":"2018-08-31T19:04:29","slug":"labor-of-division","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2010\/02\/17\/labor-of-division\/","title":{"rendered":"Dividing by Multiplying"},"content":{"rendered":"<p><a href=\"http:\/\/ridiculousfish.com\/blog\/archives\/2010\/02\/15\/labor-of-division-episode-1\/\">Peter Ammon<\/a>:<\/p>\n<blockquote cite=\"http:\/\/ridiculousfish.com\/blog\/archives\/2010\/02\/15\/labor-of-division-episode-1\/\"><p>Every divisor has a magic number, and most have more than one!  A magic number for <i>d<\/i> is nothing more than a precomputed quotient: a power of 2 divided by <i>d<\/i> and then rounded up.  At runtime, we do the same thing, except backwards: multiply by this magic number and then divide by the power of 2, rounding down.  The tricky part is finding a power big enough that the &ldquo;rounding up&rdquo; part doesn&rsquo;t hurt anything.  If we are lucky, a multiple of <i>d<\/i> will happen to be only slightly larger than a power of 2, so rounding up doesn&rsquo;t change much and our magic number will fit in 32 bits.  If we are unlucky, well, we can always fall back to a 33 bit number, which is almost as efficient.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Peter Ammon: Every divisor has a magic number, and most have more than one! A magic number for d is nothing more than a precomputed quotient: a power of 2 divided by d and then rounded up. At runtime, we do the same thing, except backwards: multiply by this magic number and then divide by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-08-31T19:04:10Z","apple_news_api_id":"fd9769f7-7159-40ea-af9e-2d91f22e1cb2","apple_news_api_modified_at":"2018-08-31T19:04:32Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/A_Zdp93FZQOqvni2R8i4csg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[259,138,71],"class_list":["post-2236","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-math","tag-optimization","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=2236"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2236\/revisions"}],"predecessor-version":[{"id":22591,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2236\/revisions\/22591"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=2236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=2236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=2236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}