Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0007368 [Squeak] Kernel minor always 07-14-09 07:06 04-18-10 22:05
Reporter nicolas cellier View Status public  
Assigned To nicolas cellier
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version trunk Product Version 3.10.2
  Product Build
Summary 0007368: 1.0 closeTo: 200 factorial
Description self deny: (1.0 closeTo: 200 factorial).

(1.0 closeTo: 100 factorial) is false as expected.
(1 closeTo: 200 factorial) is also false as expected.

See also 0006729
Steps To Reproduce
Additional Information The trick for doing a fuzzy compare will trigger a coercion of the huge integer to Float infinity.

    fuzz := (self abs max: num abs) * 0.0001.

Then comparison will just lead to Float infinity <= Float infinity which happens to be true, thanks to IEEE754 weird rules (See 0006729 )

    ^ (self - num) abs <= fuzz

A protection against infinity has been placed above, but it does not apply because (200 factorial isFinite).

    self isInfinite == num isInfinite ifFalse: [^ false].
Attached Files  M7368-closeTo-Patch-nice.1.cs [^] (611 bytes) 07-14-09 07:35
 M7368-closeTo-Test-nice.1.cs [^] (992 bytes) 07-14-09 07:36
 M7368-closeTo-Patch-nice.2.cs [^] (427 bytes) 07-16-09 23:01
 M7368-closeTo-Patch-nice.3.cs [^] (345 bytes) 07-16-09 23:07
 M7368-closeTo-Test-nice.2.cs [^] (1,844 bytes) 07-19-09 17:32
 M7368-closeTo-Patch-nice.4.cs [^] (599 bytes) 07-19-09 17:32

- Relationships

- Notes
(0013186 - 314 - 392 - 392 - 392 - 392 - 392)
nicolas cellier
07-14-09 07:17

For the fun of it, please note:

(1.0 closeTo: 200 factorial) -> true.
(200 factorial closeTo: 1.0) -> false.

You can also play with:

{
Float infinity closeTo: 200 factorial.
200 factorial closeTo: Float infinity.
}.

I wish you good luck before you find an implementation passing all these tricks :)
 
(0013187 - 163 - 217 - 217 - 217 - 217 - 217)
nicolas cellier
07-14-09 07:37

"fix begin"
Installer mantis bug: 7368 fix:'M7368-closeTo-Patch-nice.1.cs'.
"fix test"
Installer mantis bug: 7368 fix:'M7368-closeTo-Test-nice.1.cs'.
"fix end"
 
(0013188 - 137 - 155 - 155 - 233 - 233 - 233)
nicolas cellier
07-14-09 07:39

I gave it a try.
These tests and patch supersedes 0006729.

In this implementation, (FloatInfinity closeTo: 200 factorial) will be true.
 
(0013196 - 310 - 482 - 482 - 482 - 482 - 482)
bonzini
07-16-09 06:13

Alternatively, this is also good:

        "Needed to return true for +Inf/+Inf and -Inf/-Inf"
        self = num ifTrue: [^true].
        ^(self - num) abs / (self abs max: num abs) <= 0.0001

If one is finite and the other is not, the final comparison becomes NaN / NaN <= 0.0001 which is always false.
 
(0013197 - 191 - 310 - 310 - 401 - 401 - 401)
nicolas cellier
07-16-09 19:29
edited on: 07-16-09 19:30

Yes, sounds simpler, Inf/Inf -> Nan.
If 0003374 is applied though, we should write
        self = num asFloat ifTrue: [^true].
because
        Float infinity noLongerEqual: 200 factorial.

 
(0013198 - 436 - 629 - 629 - 739 - 739 - 739)
nicolas cellier
07-16-09 23:06

M7368-closeTo-Patch-nice.2.cs (forgot to remove = 0 tests)
and M7368-closeTo-Patch-nice.3.cs are a lot simpler thanks to Paolo
closeTo: num
     "are these two numbers close?"
    num isNumber ifFalse: [^[self = num] ifError: [false]].
    ^self = num asFloat
        or: [(self - num) abs / (self abs max: num abs) < 0.0001]

Note that I changed <= 0.0001 into < 0.0001.
This in case 0007260 is not already applied in your favourite squeak VM
 
(0013203 - 163 - 217 - 217 - 217 - 217 - 217)
nicolas cellier
07-19-09 11:46

"fix begin"
Installer mantis bug: 7368 fix:'M7368-closeTo-Patch-nice.3.cs'.
"fix test"
Installer mantis bug: 7368 fix:'M7368-closeTo-Test-nice.1.cs'.
"fix end"
 
(0013204 - 75 - 81 - 81 - 81 - 81 - 81)
nicolas cellier
07-19-09 17:33

Hmm not enough tests written... :(
The = 0 tests were necessary of course.
 
(0013205 - 163 - 217 - 217 - 217 - 217 - 217)
nicolas cellier
07-19-09 17:33

"fix begin"
Installer mantis bug: 7368 fix:'M7368-closeTo-Patch-nice.4.cs'.
"fix test"
Installer mantis bug: 7368 fix:'M7368-closeTo-Test-nice.2.cs'.
"fix end"
 
(0013273 - 59 - 59 - 209 - 209 - 209 - 209)
nicolas cellier
08-24-09 20:10

Fixed in http://source.squeak.org/trunk/Kernel-nice.193.mcz [^]
 

- Issue History
Date Modified Username Field Change
07-14-09 07:06 nicolas cellier New Issue
07-14-09 07:17 nicolas cellier Note Added: 0013186
07-14-09 07:35 nicolas cellier File Added: M7368-closeTo-Patch-nice.1.cs
07-14-09 07:36 nicolas cellier File Added: M7368-closeTo-Test-nice.1.cs
07-14-09 07:37 nicolas cellier Note Added: 0013187
07-14-09 07:39 nicolas cellier Note Added: 0013188
07-16-09 06:13 bonzini Note Added: 0013196
07-16-09 19:29 nicolas cellier Note Added: 0013197
07-16-09 19:30 nicolas cellier Note Edited: 0013197
07-16-09 23:01 nicolas cellier File Added: M7368-closeTo-Patch-nice.2.cs
07-16-09 23:06 nicolas cellier Note Added: 0013198
07-16-09 23:07 nicolas cellier File Added: M7368-closeTo-Patch-nice.3.cs
07-19-09 11:46 nicolas cellier Note Added: 0013203
07-19-09 17:32 nicolas cellier File Added: M7368-closeTo-Test-nice.2.cs
07-19-09 17:32 nicolas cellier File Added: M7368-closeTo-Patch-nice.4.cs
07-19-09 17:33 nicolas cellier Note Added: 0013204
07-19-09 17:33 nicolas cellier Note Added: 0013205
08-24-09 20:10 nicolas cellier Note Added: 0013273
09-03-09 21:05 nicolas cellier Issue Monitored: nicolas cellier
09-03-09 21:05 nicolas cellier Issue End Monitor: nicolas cellier
09-03-09 21:09 nicolas cellier Status new => resolved
09-03-09 21:09 nicolas cellier Fixed in Version  => trunk
09-03-09 21:09 nicolas cellier Resolution open => fixed
09-03-09 21:09 nicolas cellier Assigned To  => nicolas cellier
04-18-10 22:05 andreas Status resolved => closed


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
96 total queries executed.
53 unique queries executed.
Powered by Mantis Bugtracker