{"id":5852,"date":"2015-09-05T16:02:47","date_gmt":"2015-09-05T15:02:47","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=5852"},"modified":"2015-09-05T17:08:57","modified_gmt":"2015-09-05T16:08:57","slug":"differing-behaviour-of-numpys-log1p-function-across-platforms","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=5852","title":{"rendered":"Differing behaviour of numpy&#8217;s log1p function across platforms"},"content":{"rendered":"<p>The test suite of a project I&#8217;m working on is poking around at the\u00a0extreme edges of the range of double precision numbers. I noticed a difference between Windows and other platforms that I can&#8217;t yet fully explain. On Windows, the test suite was pumping out RuntimeWarnings that we don&#8217;t see in Linux or Mac. I&#8217;ve distilled the issue down to a single <a href=\"http:\/\/www.numpy.org\/\">numpy<\/a> command:<\/p>\n<pre>np.log1p(1.7976931348622732e+308)<\/pre>\n<p>On Windows 7 Anaconda Python 2.3, this gives a RuntimeWarning and returns inf whereas on Linux and Mac OS X it evaluates to 709.78-ish<\/p>\n<p>Numpy version is 1.9.2 in all cases.<\/p>\n<p><strong>64 bit Windows 7<\/strong><\/p>\n<pre>Python 2.7.10 |Continuum Analytics, Inc.| (default, May 28 2015, 16:44:52) [MSC\r\nv.1500 64 bit (AMD64)] on win32\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\nAnaconda is brought to you by Continuum Analytics.\r\nPlease check out: http:\/\/continuum.io\/thanks and https:\/\/binstar.org\r\n&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; np.log1p(1.7976931348622732e+308)\r\n__main__:1: RuntimeWarning: overflow encountered in log1p\r\ninf\r\n<\/pre>\n<p><strong>64 bit Linux<\/strong><\/p>\n<pre>Python 2.7.9 (default, Apr  2 2015, 15:33:21) \r\n[GCC 4.9.2] on linux2\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; np.log1p(1.7976931348622732e+308)\r\n709.78271289338397\r\n<\/pre>\n<p><strong>Mac OS X<\/strong><\/p>\n<pre>Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42) \r\n[GCC 4.2.1 (Apple Inc. build 5577)] on darwin\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\nAnaconda is brought to you by Continuum Analytics.\r\nPlease check out: http:\/\/continuum.io\/thanks and https:\/\/binstar.org\r\n&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; np.log1p(1.7976931348622732e+308)\r\n709.78271289338397\r\n<\/pre>\n<p>The argument to <a href=\"http:\/\/docs.scipy.org\/doc\/numpy\/reference\/generated\/numpy.log1p.html\">log1p<\/a> is getting close to the largest double precision number:<\/p>\n<pre>&gt;&gt;&gt; sys.float_info.max\r\n1.7976931348623157e+308\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The test suite of a project I&#8217;m working on is poking around at the\u00a0extreme edges of the range of double precision numbers. I noticed a difference between Windows and other platforms that I can&#8217;t yet fully explain. On Windows, the test suite was pumping out RuntimeWarnings that we don&#8217;t see in Linux or Mac. I&#8217;ve [&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":[4,76,31],"tags":[],"class_list":["post-5852","post","type-post","status-publish","format-standard","hentry","category-math-software","category-numerics","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1wo","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5852","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=5852"}],"version-history":[{"count":6,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5852\/revisions"}],"predecessor-version":[{"id":5859,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5852\/revisions\/5859"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}