{"id":5152,"date":"2013-10-10T12:53:58","date_gmt":"2013-10-10T11:53:58","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=5152"},"modified":"2013-10-10T12:57:35","modified_gmt":"2013-10-10T11:57:35","slug":"python-division-by-zero-is-not-ieee-compliant","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=5152","title":{"rendered":"Python division by zero is not IEEE compliant"},"content":{"rendered":"<p>From the wikipedia page on <a href=\"http:\/\/en.wikipedia.org\/wiki\/Division_by_zero\">Division by Zero<\/a>: <em>&#8220;The IEEE 754 standard\u00a0specifies that every floating point arithmetic operation, including division by zero, has a well-defined result&#8221;.<\/em><\/p>\n<p><a href=\"http:\/\/www.mathworks.co.uk\/products\/matlab\/\">MATLAB<\/a> supports this fully:<\/p>\n<pre>&gt;&gt; 1\/0\r\nans =\r\n   Inf\r\n&gt;&gt; 1\/(-0)\r\nans =\r\n  -Inf\r\n&gt;&gt; 0\/0\r\nans =\r\n   NaN<\/pre>\n<p><a href=\"http:\/\/julialang.org\/\">Julia<\/a> is almost there, but doesn&#8217;t handled the signed 0 correctly (This is using Version 0.2.0-prerelease+3768 on Windows)<\/p>\n<pre>julia&gt; 1\/0\r\nInf\r\n\r\njulia&gt; 1\/(-0)\r\nInf\r\n\r\njulia&gt; 0\/0\r\nNaN<\/pre>\n<p><a href=\"http:\/\/www.python.org\/\">Python<\/a> throws an exception. (Python 2.7.5 using IPython shell)<\/p>\n<pre>In [4]: 1.0\/0.0\r\n---------------------------------------------------------------------------\r\nZeroDivisionError                         Traceback (most recent call last)\r\n in ()\r\n----&gt; 1 1.0\/0.0\r\n\r\nZeroDivisionError: float division by zero\r\n\r\nIn [5]: 1.0\/(-0.0)\r\n---------------------------------------------------------------------------\r\nZeroDivisionError                         Traceback (most recent call last)\r\n in ()\r\n----&gt; 1 1.0\/(-0.0)\r\n\r\nZeroDivisionError: float division by zero\r\n\r\nIn [6]: 0.0\/0.0\r\n---------------------------------------------------------------------------\r\nZeroDivisionError                         Traceback (most recent call last)\r\n in ()\r\n----&gt; 1 0.0\/0.0\r\n\r\nZeroDivisionError: float division by zero<\/pre>\n<p><strong>Update:<\/strong><br \/>\nJulia <strong>does<\/strong> do things correctly, provided I make it clear that I am working with floating point numbers:<\/p>\n<pre>julia&gt; 1.0\/0.0\r\nInf\r\n\r\njulia&gt; 1.0\/(-0.0)\r\n-Inf\r\n\r\njulia&gt; 0.0\/0.0\r\nNaN<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>From the wikipedia page on Division by Zero: &#8220;The IEEE 754 standard\u00a0specifies that every floating point arithmetic operation, including division by zero, has a well-defined result&#8221;. MATLAB supports this fully: &gt;&gt; 1\/0 ans = Inf &gt;&gt; 1\/(-0) ans = -Inf &gt;&gt; 0\/0 ans = NaN Julia is almost there, but doesn&#8217;t handled the signed 0 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[59,11,7,31],"tags":[],"class_list":["post-5152","post","type-post","status-publish","format-standard","hentry","category-julia","category-matlab","category-programming","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1l6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5152"}],"version-history":[{"count":6,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5152\/revisions"}],"predecessor-version":[{"id":5167,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5152\/revisions\/5167"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}