<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>andthennothing.net: Modulus</title>
  <subtitle type="html">&amp;ldquo;first there was a three-legged monkey...&amp;rdquo;</subtitle>
  <id>tag:andthennothing.net,2005:Typo</id>
  <generator uri="http://typo.leetsoft.com" version="4.0">Typo</generator>
  <link href="http://andthennothing.net/xml/atom10/article/139/feed.xml" rel="self" type="application/xml+atom"/>
  <link href="http://andthennothing.net/archives/2004/11/10/modulus" rel="alternate" type="text/html"/>
  <updated>2007-01-26T05:03:29+00:00</updated>
  <entry>
    <author>
      <name>Jonas Bengtsson</name>
      <email>jonas.b@home.se</email>
    </author>
    <id>urn:uuid:daeffaf0-5644-4c78-8798-0e4b36f8fd20</id>
    <published>2004-11-10T22:59:00+00:00</published>
    <updated>2007-01-26T05:03:29+00:00</updated>
    <title>Modulus</title>
    <link href="http://andthennothing.net/archives/2004/11/10/modulus" rel="alternate" type="text/html"/>
    <category term="python" scheme="http://andthennothing.net/tags/139"/>
    <category term="java" scheme="http://andthennothing.net/tags/139"/>
    <content type="html">In &lt;a href="http://www.python.org/"&gt;Python&lt;/a&gt; I get this:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_python "&gt;&amp;gt;&amp;gt;&amp;gt; 2 % 5
2
&amp;gt;&amp;gt;&amp;gt; -2 % 5
3
&amp;gt;&amp;gt;&amp;gt; 2 % -5
-3
&amp;gt;&amp;gt;&amp;gt; -2 % -5
-2&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
But in &lt;a href="http://www.java.com/"&gt;Java&lt;/a&gt; I get this:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_java "&gt;System.out.println(2%5);  //2
System.out.println(-2%5);  //-2
System.out.println(2%-5);  //2
System.out.println(-2%-5);  //-2&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Who&amp;#8217;s right I don&amp;#8217;t know. I guess that you might say that the way Java does it is more correct since no division is taking place. But the way I wanted it to work today at work (coding C++) is the Python way.</content>
  </entry>
</feed>
