Login  Register

Re: equalsTo: is naive

Posted by Nicolas Cellier on May 04, 2016; 7:13pm
URL: https://forum.world.st/equalsTo-is-naive-tp4893595p4893624.html

Hi Werner,
if we are perpetually reinventing the wheel, life is easy: I just have to perpetually exhume old bug reports ;)
http://bugs.squeak.org/view.php?id=6729
http://bugs.squeak.org/view.php?id=7368

I would attack the asFloat defense with:

(999e1000 relativelyEqualsTo: 998e1000 upTo: 1/100) which I expect to be true

Maybe something closer to closeTo:, just without hardcoded relative precision.

2016-05-04 19:58 GMT+02:00 werner kassens <[hidden email]>:
Hi Nicolas,
<g> this is funny indeed. what do think about this change:
Number>>relativelyEqualsTo: aNumber upTo: aSmallNumber
        "compare to Float>>closeTo:
        generally called from Number>>equalsTo:
         (c) Copyrights Didier BESSET, 1999, all rights reserved.
         Initial code: 21/4/99 "
    | norm |
    norm := self abs max: aNumber abs.
    ^norm <= DhbFloatingPointMachine new defaultNumericalPrecision
        or: [ (self - aNumber) abs asFloat < ( aSmallNumber * norm)]

just the #asFloat added. would that still be buggy?
werner

On Wed, May 4, 2016 at 4:32 PM, Nicolas Cellier <[hidden email]> wrote:
try this snippet:

Float fmax asInteger * (3/2) equalsTo: 0

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.