<!-- 
RSS generated by JIRA (4.4#649-r158309) at Mon May 20 11:06:31 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/CLJS-370/CLJS-370.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[CLJS-370] Incorrect behavior of integer? for integral floating point expressions</title>
                <link>http://dev.clojure.org/jira/browse/CLJS-370</link>
                <project id="10040" key="CLJS">ClojureScript</project>
                        <description>&lt;p&gt;This includes infinity, exponential expressions, etc.&lt;/p&gt;

&lt;p&gt;See: &lt;a href=&quot;http://stackoverflow.com/questions/3885817/how-to-check-if-a-number-is-float-or-integer&quot;&gt;http://stackoverflow.com/questions/3885817/how-to-check-if-a-number-is-float-or-integer&lt;/a&gt;&lt;/p&gt;</description>
                <environment></environment>
            <key id="15671">CLJS-370</key>
            <summary>Incorrect behavior of integer? for integral floating point expressions</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="4" iconUrl="http://dev.clojure.org/jira/images/icons/priority_minor.gif">Minor</priority>
                    <status id="5" iconUrl="http://dev.clojure.org/jira/images/icons/status_resolved.gif">Resolved</status>
                    <resolution id="1">Completed</resolution>
                                <assignee username="-1">Unassigned</assignee>
                                <reporter username="bbloom">Brandon Bloom</reporter>
                        <labels>
                        <label>patch</label>
                        <label>patch,</label>
                    </labels>
                <created>Mon, 3 Sep 2012 15:28:18 -0500</created>
                <updated>Wed, 5 Sep 2012 11:40:48 -0500</updated>
                    <resolved>Wed, 5 Sep 2012 10:07:21 -0500</resolved>
                                                                    <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="29349" author="dnolen" created="Mon, 3 Sep 2012 16:26:17 -0500"  >&lt;p&gt;changing the behavior of integer? outside of a more comprehensive numeric discussion is low priority. The current implementation is already suboptimal in its coercion of numbers to strings.&lt;/p&gt;</comment>
                    <comment id="29350" author="bbloom" created="Mon, 3 Sep 2012 17:31:31 -0500"  >&lt;p&gt;I&apos;m not changing the behavior of integer?, I&apos;m fixing it. Also, regarding the suboptimal nature of string coercion, the following benchmark seems to show this isn&apos;t an issue at all:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;Benchmarking with V8
[n 5], (old-integer? n), 1000000 runs, 0 msecs
[n 5.5], (old-integer? n), 1000000 runs, 0 msecs
[n 5.0E300], (old-integer? n), 1000000 runs, 0 msecs
[n &quot;&quot;], (old-integer? n), 1000000 runs, 0 msecs
[n 5], (integer? n), 1000000 runs, 0 msecs
[n 5.5], (integer? n), 1000000 runs, 0 msecs
[n 5.0E300], (integer? n), 1000000 runs, 0 msecs
[n &quot;&quot;], (integer? n), 1000000 runs, 0 msecs


Benchmarking with SpiderMonkey
[n 5], (old-integer? n), 1000000 runs, 0 msecs
[n 5.5], (old-integer? n), 1000000 runs, 0 msecs
[n 5.0E300], (old-integer? n), 1000000 runs, 0 msecs
[n &quot;&quot;], (old-integer? n), 1000000 runs, 0 msecs
[n 5], (integer? n), 1000000 runs, 0 msecs
[n 5.5], (integer? n), 1000000 runs, 0 msecs
[n 5.0E300], (integer? n), 1000000 runs, 0 msecs
[n &quot;&quot;], (integer? n), 1000000 runs, 0 msecs


Benchmarking with JavaScriptCore
[n 5], (old-integer? n), 1000000 runs, 0 msecs
[n 5.5], (old-integer? n), 1000000 runs, 0 msecs
[n 5.0E300], (old-integer? n), 1000000 runs, 0 msecs
[n &quot;&quot;], (old-integer? n), 1000000 runs, 0 msecs
[n 5], (integer? n), 1000000 runs, 0 msecs
[n 5.5], (integer? n), 1000000 runs, 0 msecs
[n 5.0E300], (integer? n), 1000000 runs, 0 msecs
[n &quot;&quot;], (integer? n), 1000000 runs, 0 msecs&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="29357" author="dnolen" created="Tue, 4 Sep 2012 10:02:32 -0500"  >&lt;p&gt;Those benchmarks are not revealing anything. Advanced compilation is eliminating that code. Try with :simple or :whitespace.&lt;/p&gt;</comment>
                    <comment id="29373" author="bbloom" created="Tue, 4 Sep 2012 23:13:39 -0500"  >&lt;p&gt;&lt;b&gt;sigh&lt;/b&gt; I&apos;ve once again shown my profiling ineptitude. Here&apos;s results running with whitespace optimizations:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;Benchmarking with V8
[n 5], (old-integer? n), 1000000 runs, 924 msecs
[n 5.5], (old-integer? n), 1000000 runs, 1097 msecs
[n 5.0E300], (old-integer? n), 1000000 runs, 1009 msecs
[n &quot;&quot;], (old-integer? n), 1000000 runs, 77 msecs
[n 5], (integer? n), 1000000 runs, 210 msecs
[n 5.5], (integer? n), 1000000 runs, 556 msecs
[n 5.0E300], (integer? n), 1000000 runs, 731 msecs
[n &quot;&quot;], (integer? n), 1000000 runs, 78 msecs


Benchmarking with SpiderMonkey
[n 5], (old-integer? n), 1000000 runs, 236 msecs
[n 5.5], (old-integer? n), 1000000 runs, 362 msecs
[n 5.0E300], (old-integer? n), 1000000 runs, 2885 msecs
[n &quot;&quot;], (old-integer? n), 1000000 runs, 94 msecs
[n 5], (integer? n), 1000000 runs, 216 msecs
[n 5.5], (integer? n), 1000000 runs, 230 msecs
[n 5.0E300], (integer? n), 1000000 runs, 1360 msecs
[n &quot;&quot;], (integer? n), 1000000 runs, 98 msecs


Benchmarking with JavaScriptCore
[n 5], (old-integer? n), 1000000 runs, 471 msecs
[n 5.5], (old-integer? n), 1000000 runs, 467 msecs
[n 5.0E300], (old-integer? n), 1000000 runs, 771 msecs
[n &quot;&quot;], (old-integer? n), 1000000 runs, 212 msecs
[n 5], (integer? n), 1000000 runs, 882 msecs
[n 5.5], (integer? n), 1000000 runs, 756 msecs
[n 5.0E300], (integer? n), 1000000 runs, 851 msecs
[n &quot;&quot;], (integer? n), 1000000 runs, 213 msecs&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Seems like a win on V8 &amp;amp; SpiderMonkey, but a small loss on JavaScriptCore.&lt;/p&gt;</comment>
                    <comment id="29374" author="dnolen" created="Tue, 4 Sep 2012 23:40:29 -0500"  >&lt;p&gt;The slow down on JSC gives me pause. WebKit is ubiquitous in the mobile space. &lt;/p&gt;

&lt;p&gt;I&apos;m also not convinced we need to handle Infinity or NaN (though others may differ on that point). Perhaps we can in some debug mode intelligently detect and error out precisely where these kinds of mistakes may occur.&lt;/p&gt;</comment>
                    <comment id="29375" author="bbloom" created="Wed, 5 Sep 2012 01:19:27 -0500"  >&lt;p&gt;It seems like a bad precedent to favor micro-optimization over correctness when speed is easily obtainable through platform interop.&lt;/p&gt;

&lt;p&gt;Infinity, NaN, and floating point exponentiation expressions are not integers. I changed the function&apos;s behavior to match JVM Clojure&apos;s. We&apos;re going to need a reliable integer predicate if we want to implement ratios and other compound numeric types. &lt;/p&gt;

&lt;p&gt;If you need need a fast predicate for numbers, the number? predicate only checks type. It&apos;s behavior also matches JVM Clojure&apos;s: it accepts infinity, NaN, etc. If you need a fast integer test, but insist that edge cases like 5e300 are exceptional and ignorable, then you can micro-optimize by calling the necessary javascript primitives yourself.&lt;/p&gt;</comment>
                    <comment id="29378" author="dnolen" created="Wed, 5 Sep 2012 09:55:28 -0500"  >&lt;p&gt;On my machine your patch is slower across all JS engines w/ JSC faring the worst at nearly 2X. I do agree that the behavior is better. However moving forward this means that even simple functions like even? are 100X slower than their Clojure JVM counterparts. There&apos;s nothing &quot;micro-optimization&quot; about 2 orders of magnitude.&lt;/p&gt;</comment>
                    <comment id="29379" author="dnolen" created="Wed, 5 Sep 2012 10:06:12 -0500"  >&lt;p&gt;Oops after a lot more testing and playing around with your patch I turned out to be very wrong! It looks your patch + a boolean type hint is a win across the board on all engines, both in terms of performance and correctness.&lt;/p&gt;</comment>
                    <comment id="29380" author="dnolen" created="Wed, 5 Sep 2012 10:07:21 -0500"  >&lt;p&gt;fixed, &lt;a href=&quot;http://github.com/clojure/clojurescript/commit/3c210d9430b30ffeac9600ae4851e1c347c2cced&quot;&gt;http://github.com/clojure/clojurescript/commit/3c210d9430b30ffeac9600ae4851e1c347c2cced&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="29382" author="bbloom" created="Wed, 5 Sep 2012 11:40:48 -0500"  >&lt;p&gt;Heh. Performance is hard &lt;img class=&quot;emoticon&quot; src=&quot;http://dev.clojure.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11474" name="CLJS-370-v1.patch" size="1708" author="bbloom" created="Mon, 3 Sep 2012 15:29:58 -0500" />
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                            <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                <customfieldname>Patch</customfieldname>
                <customfieldvalues>
                        <customfieldvalue key="10002">Code and Test</customfieldvalue>

                </customfieldvalues>
            </customfield>
                                                                                        </customfields>
    </item>
</channel>
</rss>