Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004315 [Squeak] Kernel minor always 07-23-06 20:44 10-15-09 20:26
Reporter wiz View Status public  
Assigned To
Priority normal Resolution won't fix  
Status closed   Product Version 3.9
Summary 0004315: [Bug] Should (0.5 - ( 0.5 - 0.1 ) = 0.1 ) be true or false.
Description
For this one evauluate

(0.5 - ( 0.5 - 0.1 ) = 0.1 )
in a work space

compare to
(0.5 - ( 0.5 - 0.2 ) = 0.2 )

Additional Information I am using sq 7046 with SqVm3.8.9b7 on an iMac G3 running OS 9.1 .


The edge if equality for addition and subtraction for floats seems to be fail when the operands exceed a factor of 4 of each other in magnitude.

Is this a bug?

It seems to me a awfully high intolerance.

Yours in service, --Jerome Peace

Attached Files

- Relationships

- Notes
(0006261 - 890 - 964 - 1468 - 1468 - 1468 - 1468)
nicolas cellier
07-29-06 02:17
edited on: 07-29-06 02:20

It is not a bug. Float are inexact representation (rounded fractions) and you should never rely on a strict equality test after performing inexact operations, unless maybe for these special floats: integers (small ones) and fractions with denominator being power of 2.

Just code the test in C and you'll see nothing better.

Unless you are on x86 and use compiler optimisation, in which case intel floating point registers having extended precision you can go a little further with bits...

But the result would depend on compiler options.

BTW, 0.1 is not 1/10, though current Smalltalk implementation answer true to this test. That's maybe what makes you overtrust Float.
(see http://bugs.impara.de/view.php?id=3374 [^] or http://groups.google.com/group/comp.lang.smalltalk/browse_thread/thread/59287ffa46b28a5a/b6a6e19f5975d098?lnk=gst&q=equality+is+not&rnum=1#b6a6e19f5975d098). [^]

 
(0006263 - 381 - 435 - 435 - 435 - 435 - 435)
nicolas cellier
07-29-06 03:35

If you want to play with decimal representation, you'd better use ScaledDecimal

(0.5s1 - ( 0.5s1 - 0.1s1 ) = 0.1s1 )
(0.5s1 - ( 0.5s1 - 0.2s1 ) = 0.2s1 )

But do not trust what is displayed: ScaledDecimal display only a truncated result to the number of decimals you asked. Internally, it holds an exact fraction.

(0.5s1*0.5s1) -> 0.2s1
(0.5s1*0.5s1) asFraction -> (1/4)
 
(0013366 - 179 - 191 - 191 - 191 - 191 - 191)
nicolas cellier
10-15-09 20:26

This is the natural behavior of Float operations which are inexact.
This is a feature and cannot be solved.
Use exact Fraction and ScaledDecimal when you expect exact arithmetic
 

- Issue History
Date Modified Username Field Change
07-23-06 20:44 wiz New Issue
07-29-06 02:17 nicolas cellier Note Added: 0006261
07-29-06 02:20 nicolas cellier Note Edited: 0006261
07-29-06 03:35 nicolas cellier Note Added: 0006263
10-15-09 20:26 nicolas cellier Status new => closed
10-15-09 20:26 nicolas cellier Note Added: 0013366
10-15-09 20:26 nicolas cellier Resolution open => won't fix


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