[Vm-dev] [squeak-dev] What should Integer>>digitCompare: return?

Chris Cunningham cunningham.cb at gmail.com
Mon Oct 29 00:24:00 UTC 2018


On Sun, Oct 28, 2018 at 4:54 PM David T. Lewis <lewis at mail.msen.com> wrote:

> On Sun, Oct 28, 2018 at 03:48:58PM -0700, Chris Cunningham wrote:
> > (keyboard failure)
> > On Sun, Oct 28, 2018 at 3:41 PM Chris Cunningham <
> cunningham.cb at gmail.com>
> > wrote:
> >
> > > Looking at LargeIntegers (I'm 64 bit, so these are big):
> > > {
> > > 1152921504606846977 digitCompare:  -1152921504606846977.
> > > 1152921504606846977 digitCompare:  -1152921504606846978.
> > > 1152921504606846978 digitCompare:  -1152921504606846977.
> > > }  "#(0 -1 1)"
> > >
> > > {
> > > 1249 digitCompare: -1249.
> > > 1249 digitCompare: -1250.
> > > 1250 digitCompare: -1249
> > >
> >  }   "#(1 1 1)"
> >
> > The method is actively different for SmallIntegers and LargeIntegers.
> >
> > I'm not sure how much this matters - besides the fact that it is lying
> > around waiting for someone to use it.  For comparisons of integers, the
> > callers check to see if one (or more) of the numbers are negative, then
> > handles the issues here.
>
> I would say that this is crying out for some unit tests :-)
>
> Yes, just need to figure out what the right results are.

>
> >
> > It is also currently used in DateAndTime class methods (#nowWithOffset:
> > [deprecated] and #now:offset:), which is probably safe because now is
> > always after the epoch.  And we hopefully wouldn't use #now:withOffset:
> for
> > pre-epoch times.
> >
> > Is this worth fixing?
> >
>
> Definitely, yes.
>
Good. Then this starts in
   LargeIntegerPlugin>>primDigitCompare:
with this nice comment:
"shortcut: aSmallInteger has to be smaller in Magnitude as aLargeInteger"
 This has been there at least since 2004...

cross posting to the VM Dev list (since it should be handled there first).
I'd be happy to replicate the right answer in the fallback code, and craft
tests, once the right behavior is explained.

Thanks,
cbc

>
> Dave
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20181028/a33a8310/attachment.html>


More information about the Vm-dev mailing list