<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Eliot,<br>
<br>
On Cuis I have been recently working on hash consistency for numeric
types, making same value (or different values that compare as equal
due to rounding) answer same hash regardless of class. But I have
missed the SmallInteger / LargeInteger consistency across 32 / 64
bits images. Thanks! Fixes for Cuis now at GitHub repo. In
particular, it is necessary for the following to answer the same
values in 32 and 64 bits (it wasn't the case!):<br>
<br>
<br>
largeInteger := (LargePositiveInteger new: 4)<br>
digitAt: 1 put: 1;<br>
digitAt: 2 put: 2;<br>
digitAt: 3 put: 3;<br>
digitAt: 4 put: 4;<br>
yourself.<br>
smallInteger := largeInteger normalize.<br>
float := smallInteger asFloat.<br>
boxedFloat := BoxedFloat64 new basicAt: 1 put: (float basicAt: 1);
basicAt: 2 put: (float basicAt: 2); yourself.<br>
{largeInteger class. smallInteger class. float class. boxedFloat
class.<br>
largeInteger hash. smallInteger hash. float hash. boxedFloat hash }
print.<br>
<br>
<br>
<br>
largeInteger _ (LargePositiveInteger new: 4)<br>
digitAt: 1 put: 1;<br>
digitAt: 2 put: 2;<br>
digitAt: 3 put: 3;<br>
digitAt: 4 put: 80;<br>
yourself.<br>
smallIntIn64ButLargeIntIn32Bits := largeInteger normalize.<br>
float := smallIntIn64ButLargeIntIn32Bits asFloat.<br>
boxedFloat := BoxedFloat64 new basicAt: 1 put: (float basicAt: 1);
basicAt: 2 put: (float basicAt: 2); yourself.<br>
{largeInteger class. smallIntIn64ButLargeIntIn32Bits class. float
class. boxedFloat class.<br>
largeInteger hash. smallIntIn64ButLargeIntIn32Bits hash. float hash.
boxedFloat hash } print.<br>
<br>
<br>
Note that I also included consistency between un-normalized
LargeIntegers in the SmallInteger range (just in case).<br>
<br>
On 11/21/2018 3:45 PM, Eliot Miranda via Cuis-dev wrote:
<blockquote
cite="mid:CAC20JE2WhuQGhWHXoAfS6QzV-gkGQ1OV8Wd77N32yA75Pf7wtw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi All,
<div><br>
</div>
<div> right now we have the following
definition of
Large(Positive)Integer>>hash:</div>
<div><br>
</div>
<div>
<div>hash</div>
<div><span class="gmail-Apple-tab-span"
style="white-space: pre;"> </span>^ByteArray
hashBytes: self startingWith: self
species hash</div>
<div><br>
</div>
<div>which means that for all integers
outside of the 32-bit SmallInteger
range (-2 ^ 30 to 2 ^ 30 - 1), the
32-bit system and the 64-bit system
answer different values for hash.</div>
<div><br>
</div>
<div>e.g. in 64 bits: (2 raisedTo: 30)
hash 1073741824</div>
<div> but in 32 bits: (2 raisedTo: 30)
hash 230045764</div>
<div><br>
</div>
<div>This is unsatisfactory. I propose
changing
Large(Positive)Integer>>hash to</div>
<div><br>
</div>
<div>
<div>hash</div>
<div><span
class="gmail-Apple-tab-span"
style="white-space: pre;"> </span>^self
digitLength <= 8</div>
<div><span style="white-space: pre;">
</span><span style="white-space:
pre;"> ifTrue: [self]</span></div>
<div><span style="white-space: pre;">
</span><span style="white-space:
pre;"> ifFalse: [</span>ByteArray
hashBytes: self startingWith: self
species hash]</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>P.S. Note that this will not break
Float hash, which is defined as</div>
<div><br>
</div>
<div>Float>>hash</div>
<div><span class="gmail-Apple-tab-span"
style="white-space: pre;"> </span>"Hash
is reimplemented because = is
implemented. Both words of the float
are used. (The bitShift:'s ensure that
the intermediate results do not become
a large integer.) Care is taken to
answer same hash as an equal Integer."</div>
<div><br>
</div>
<div><span class="gmail-Apple-tab-span"
style="white-space: pre;"> </span>(self
isFinite and: [self fractionPart =
0.0]) ifTrue: [^self truncated hash].</div>
<div><span class="gmail-Apple-tab-span"
style="white-space: pre;"> </span>^
((self basicAt: 1) bitShift: -4) +</div>
<div><span class="gmail-Apple-tab-span"
style="white-space: pre;"> </span>
((self basicAt: 2) bitShift: -4)</div>
<div><br>
</div>
<div>P.P.S. I *think* that "(self
isFinite and: [self fractionPart =
0.0])" is equivalent to "self - self =
self fractionPart" ;-)</div>
<div><br>
</div>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div><span style="font-size: small;
border-collapse: separate;">
<div>_,,,^..^,,,_<br>
</div>
<div>best, Eliot</div>
</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
</blockquote>
<br>
Cheers,<br>
<pre class="moz-signature" cols="72">--
Juan Vuletich
<a class="moz-txt-link-abbreviated" href="http://www.cuis-smalltalk.org">www.cuis-smalltalk.org</a>
<a class="moz-txt-link-freetext" href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a class="moz-txt-link-freetext" href="https://github.com/jvuletich">https://github.com/jvuletich</a>
<a class="moz-txt-link-freetext" href="https://www.linkedin.com/in/juan-vuletich-75611b3">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</body>
</html>