{"id":9,"date":"2008-02-26T09:43:58","date_gmt":"2008-02-26T14:43:58","guid":{"rendered":"http:\/\/blog.inthewings.net\/?p=9"},"modified":"2011-03-03T12:28:09","modified_gmt":"2011-03-03T17:28:09","slug":"modulo-arithmetic-issues","status":"publish","type":"post","link":"https:\/\/blog.inthewings.net\/?p=9","title":{"rendered":"Modulo Arithmetic Issues"},"content":{"rendered":"<p>Interesting&#8230; I don&#8217;t know if I got the bonus question right or not, but now I am finding some interesting things about it. It turns out that I am both right and wrong about the properties of taking the modulo of a negative number.<\/p>\n<p>I did quite a bit of testing to make sure that when you take the modulo of a negative number, you receive either a negative number or zero. This was true whether I used php, emacs, bc, or an online calculator I found.<\/p>\n<p>However, apparently when programmers were first writing the modulo routines they decided on a slightly different approach as to what modulo actually meant and came up with the current solution, which generates a negative number. Hence:<\/p>\n<p>The mathematical definition:<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Modular_arithmetic\">http:\/\/en.wikipedia.org\/wiki\/Modular_arithmetic<\/a><\/p>\n<p>The Computer Science definition:<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Modulo_operation\">http:\/\/en.wikipedia.org\/wiki\/Modulo_operation<\/a><\/p>\n<p>So, looking at these there is a difference between the two, but I favor the computer science version in this case since we are dealing with indexes that are to be used on a computer system where this is defined in the CS method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interesting&#8230; I don&#8217;t know if I got the bonus question right or not, but now I am finding some interesting things about it. It turns out that I am both right and wrong about the properties of taking the modulo of a negative number. I did quite a bit of testing to make sure that when you take the modulo of a negative number, you receive either a negative number or zero. This was true whether I used php, emacs, bc, or an online calculator I found. However, apparently when programmers were first writing the modulo routines they decided on a slightly different approach as to what modulo actually meant and came up with the current solution, which generates a negative number. Hence: The mathematical definition: http:\/\/en.wikipedia.org\/wiki\/Modular_arithmetic The Computer Science definition: http:\/\/en.wikipedia.org\/wiki\/Modulo_operation So, looking at these there is a difference between the two, but I favor the computer science version in this case since we are dealing with indexes that are to be used on a computer system where this is defined in the CS method.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129],"tags":[18],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-school","tag-modulo"],"_links":{"self":[{"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":1,"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions\/190"}],"wp:attachment":[{"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.inthewings.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}