<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 17, 2014 at 1:22 PM, Chris Muller <span dir="ltr">&lt;<a href="mailto:ma.chris.m@gmail.com" target="_blank">ma.chris.m@gmail.com</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">&gt; On Wed, Dec 17, 2014 at 11:23 AM, Chris Muller &lt;<a href="mailto:asqueaker@gmail.com">asqueaker@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Dec 17, 2014 at 12:55 PM, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; Hi Chris,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Dec 17, 2014, at 9:17 AM, Chris Muller &lt;<a href="mailto:asqueaker@gmail.com">asqueaker@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; On Wed, Dec 17, 2014 at 12:20 AM, Eliot Miranda<br>
&gt;&gt; &gt;&gt; &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt; Hi Chris,<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; On Dec 16, 2014, at 7:24 PM, Chris Muller &lt;<a href="mailto:asqueaker@gmail.com">asqueaker@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt; I wish to access some of the Float constants without a message send.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I&#39;m curious.  Why?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Speed.  I need a fast map of the 32-bit Float range to unsigned 32-bit<br>
&gt;&gt; &gt;&gt; integer range such that comparisons within the integer range are<br>
&gt;&gt; &gt;&gt; consistent with comparisons of their floats.<br>
&gt;&gt;<br>
&gt;&gt; Ah, I can see how my wording created an ambiguous meaning..<br>
&gt;&gt;<br>
&gt;&gt; &gt; So am I right in thunking that you want that if the Float has an integer<br>
&gt;&gt; &gt; equivalent the float and integer have the same hashKey32 and if they don&#39;t,<br>
&gt;&gt; &gt; you don&#39;t care as long as the hash is well-distributed?<br>
&gt;&gt;<br>
&gt;&gt; No I meant that I need to pickle Floats as an 32-bit Integer,<br>
&gt;<br>
&gt;<br>
&gt; Now I&#39;m really confused.  How come you can get away with 32-bits when Floats<br>
&gt; are 64-bits?<br>
<br>
</span>Because I need speed and efficiency more than precision.  I&#39;ll be<br>
loading _billions_ of 64-bit Squeak Floats into a indexing system that<br>
operates on 32-bit integers (it can operate at any size even 256-bit<br>
but it operates much faster in a 32-bit range due to a lot smaller and<br>
fewer LargeIntegers and performance takes precedence).<br>
<span class=""><br>
&gt;&gt; but<br>
&gt;&gt; while in their pickled Integer state, I need to run #&gt; and #&lt;<br>
&gt;&gt; comparisons against other pickled Floats (e.g., as their Integer<br>
&gt;&gt; representation) and need those comparisons to produce the same results<br>
&gt;&gt; as if they were still in their Float state.<br>
&gt;&gt;<br>
&gt;&gt; For example, the reason I cannot simply use asIEEE32Bit is because<br>
&gt;&gt; negative floats have a high-order bit set, and so the pickled<br>
&gt;&gt; represetnations don&#39;t compare correctly:<br>
&gt;&gt;<br>
&gt;&gt;   -4.321 asIEEE32Bit &lt; 1.2345 asIEEE32Bit   &quot;false&quot;  &lt;--- I need true<br>
&gt;<br>
&gt;<br>
&gt; So you need an sign-insensitive absolute comparison?  Easy to synthesize:<br>
&gt;<br>
&gt; (self at: 1) bitAnd:  16r7FFFFFFF) &lt;&lt; 32 + (self at: 2)<br>
<br>
</span>No, I need it to be sign-sensitive.  That does not pass the example I<br>
gave.  Here are the two number lines again from my original email.  I<br>
need to map Floats from:<br>
<br>
  -Infinity&lt;-----------&gt; +Infinity<br>
<br>
to Integers in the range:<br>
<br>
    0&lt;------------&gt;((2^32)-1)<br>
<br>
-Infinity needs to map to 0 and +Infinity to (2^32)-1.<br>
<span class=""><br>
&gt; This will put Infinity beyond the finite values.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; 32-bit unsigned so I made -Infinity to be 0, +Infinity to be (2^32)-1.<br>
&gt;&gt; But since NaN needs representation too, I decided to put it at the<br>
&gt;&gt; top, so I bumped +Infinity down to (2^32)-2..<br>
&gt;<br>
&gt;<br>
&gt; Again floats are 64-bit not 32-bit so I don&#39;t see how this can work.<br>
<br>
</span>Squeak Floats are 64-bit, but they can be easily converted to 32-bit<br>
floats for a loss in precision.<br>
<span class=""><br>
&gt; If you<br>
&gt; want something that orders things absolutely then something like this, which<br>
&gt; is close to my immediate float representation will work.  It effectively<br>
&gt; rotates, putting the sign in the lsb:<br>
&gt;<br>
&gt;     | mostSignificantWord |<br>
&gt;     mostSignificantWord  := self at: 1.<br>
&gt;     ^(mostSignificantWord bitAnd:  16r7FFFFFFF) &lt;&lt; 33 + ((self at: 2) &lt;&lt; 1)<br>
&gt; + (mostSignificantWord &gt;&gt; 31)<br>
&gt;<br>
&gt; This doesn&#39;t work for +/-0.0 since they have a zero exponent, but that&#39;s the<br>
&gt; only exception<br>
<br>
</span>It benches to 18% faster than my range-checking but fails the example.<br>
<br>
    -4.321 eliotHashKey32 &lt; 1.2345 eliotHashKey32   &quot;false&quot;  &lt;--- I need true<br></blockquote><div><br></div><div>So you want the sign inverted then, right?</div><div><br></div><div><div style="color:rgb(0,0,0);font-size:13px">    | mostSignificantWord |</div><div style="color:rgb(0,0,0);font-size:13px">    mostSignificantWord := self at: 1.</div><div style="color:rgb(0,0,0);font-size:13px">    mostSignificantWord := mostSignificantWord bitXor: 16r80000000.<br></div><div style="color:rgb(0,0,0);font-size:13px">    ^mostSignificantWord &lt;&lt; 32 + (self at: 2)</div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
+/- 0.0 doesn&#39;t matter, I only need one 0.0.<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature">best,<div>Eliot</div></div>
</div></div>