<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.opengenie.org/index.php?action=history&amp;feed=atom&amp;title=Common_problems</id>
	<title>Common problems - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.opengenie.org/index.php?action=history&amp;feed=atom&amp;title=Common_problems"/>
	<link rel="alternate" type="text/html" href="http://www.opengenie.org/index.php?title=Common_problems&amp;action=history"/>
	<updated>2026-05-02T17:10:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.13</generator>
	<entry>
		<id>http://www.opengenie.org/index.php?title=Common_problems&amp;diff=20&amp;oldid=prev</id>
		<title>Freddie Akeroyd: New page: ==Why does A/B give the wrong answer?== If A and B are both integers, then integer division is performed; if either is a floating point number then the integer value is first converted int...</title>
		<link rel="alternate" type="text/html" href="http://www.opengenie.org/index.php?title=Common_problems&amp;diff=20&amp;oldid=prev"/>
		<updated>2009-05-27T17:29:01Z</updated>

		<summary type="html">&lt;p&gt;New page: ==Why does A/B give the wrong answer?== If A and B are both integers, then integer division is performed; if either is a floating point number then the integer value is first converted int...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Why does A/B give the wrong answer?==&lt;br /&gt;
If A and B are both integers, then integer division is performed; if either is a floating point number then the integer value is first converted into a floating point number before division is performed. Thus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1/2 == 0       # 1 and 2 are of Integer type&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1/2.0 == 0.5   # 2.0 is a floating point number, so integer 1 is converted to 1.0 before division is done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are unsure what data type two variables may be, then you can force real division using either of these statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RES = AS_REAL(A) / B&lt;br /&gt;
RES = 1.0 * A / B   # equivalent to  (1.0*A)/B  as &amp;quot;*&amp;quot; and &amp;quot;/&amp;quot; are equal priority so the expression is evaluated left to right&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Freddie Akeroyd</name></author>
	</entry>
</feed>