{"id":90461,"date":"2003-08-11T13:37:00","date_gmt":"2003-08-11T13:37:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20030811-00\/?p=90461\/"},"modified":"2003-08-11T13:37:00","modified_gmt":"2003-08-11T13:37:00","slug":"answers-to-exercises-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030811-00\/?p=90461\/","title":{"rendered":"Answers to exercises"},"content":{"rendered":"\n<p>         What is the significance of the <code>(int)<\/code> cast in the computation of <code>dLines<\/code>?      <\/p>\n<p>         It isn&#8217;t. I got the question wrong. The real question should have been &#8220;What is the         significance of the <code>(int)<\/code> cast in the computation of <code>g_iWheelCarryover<\/code>?&#8221;      <\/p>\n<p>         The answer is to ensure that the computation is performed with signed integers throughout.         If the cast were missing, then the computation would have been unsigned (since mixing         signed and unsigned yields unsigned). <code>dLines<\/code> is a signed integer, let&#8217;s         say it&#8217;s <code>-1<\/code>. Multiply by <code>WHEEL_DELTA<\/code> yields <code>-120<\/code>.         Now convert it to an unsigned integer and you get a number in excess of four billion.         Divided by <code>uScroll<\/code> (typically 3) yields a number greater than one billion,         which is incorrect.      <\/p>\n<p>         Assuming you don&#8217;t have a high-resolution wheel mouse, how would you test that your         sub-detent mouse wheel handling was working properly?     <\/p>\n<p>         This is an easy one. Insert temporary code at the top of the <code>OnMouseWheel<\/code> function         that says <code>zDelta \/= 4<\/code>. Ta-da, your mouse now has quadruple its original resolution.     <\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the significance of the (int) cast in the computation of dLines? It isn&#8217;t. I got the question wrong. The real question should have been &#8220;What is the significance of the (int) cast in the computation of g_iWheelCarryover?&#8221; The answer is to ensure that the computation is performed with signed integers throughout. If the [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-90461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>What is the significance of the (int) cast in the computation of dLines? It isn&#8217;t. I got the question wrong. The real question should have been &#8220;What is the significance of the (int) cast in the computation of g_iWheelCarryover?&#8221; The answer is to ensure that the computation is performed with signed integers throughout. If the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/90461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=90461"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/90461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=90461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=90461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=90461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}