Hi Nicolas,
i see <g> the region is plastered with pitfalls and you already gave some serious thoughts to them. so yes, something closer to #closeTo:
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)
<= DhbFloatingPointMachine new defaultNumericalPrecision ifTrue:[^true].
^self = aNumber asFloat
or: [(self - aNumber) abs / norm < aSmallNumber]
what about that?
the problem of comparisons with non-Numbers, that #closeTo: catches, is obviously still there. i had added #equalsTo: to DhbMatrix, DualNumber, SequenceableCollection etc, but i have to admit eg not yet to Complex. otoh #closeTo: is too strict in this case anyway and eg Point has therefore its own #closeTo:. so perhaps that shortcoming, that one needs to give non-Numbers its own #equalsTo:, is acceptable?
wernerOn Wed, May 4, 2016 at 9:47 PM, Nicolas Cellier <[hidden email]> wrote:Maybe something closer to closeTo:, just without hardcoded relative precision.I would attack the asFloat defense with:Hi Werner,http://bugs.squeak.org/view.php?id=6729
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=7368
(999e1000 relativelyEqualsTo: 998e1000 upTo: 1/100) which I expect to be true--2016-05-04 19:58 GMT+02:00 werner kassens <[hidden email]>:Number>>relativelyEqualsTo: aNumber upTo: aSmallNumberHi Nicolas,<g> this is funny indeed. what do think about this change:
"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.
Free forum by Nabble | Edit this page |