Horrible problem?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Horrible problem?

강진오
Hello.
I have a question.
I tested Random class>>theItsCompletelyBrokenTest to test my system.
The comment of the method says that my system would be horrible if the result is not these values:
#(0.149243269650845 0.331633021743797 0.75619644800024 0.393701540023881 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512 0.696074432551896 0.922987899707159)
 
but my result was more precious:
#(0.1492432696508445 0.331633021743797 0.756196448000239 0.3937015400238808 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512 0.696074432551895 0.922987899707159)
 
Is it because my system has errors or the comment is obsolete or incorrect?


Reply | Threaded
Open this post in threaded view
|

Re: Horrible problem?

강진오
I also tested bucketTest: and It returned:
85 121 104 117 103 109 98 112 114 85 100 93 102 93 90 96 85 88 123 82
2012/3/3 강진오 <[hidden email]>
Hello.
I have a question.
I tested Random class>>theItsCompletelyBrokenTest to test my system.
The comment of the method says that my system would be horrible if the result is not these values:
#(0.149243269650845 0.331633021743797 0.75619644800024 0.393701540023881 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512 0.696074432551896 0.922987899707159)
 
but my result was more precious:
#(0.1492432696508445 0.331633021743797 0.756196448000239 0.3937015400238808 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512 0.696074432551895 0.922987899707159)
 
Is it because my system has errors or the comment is obsolete or incorrect?



Reply | Threaded
Open this post in threaded view
|

Re: Horrible problem?

Bob Arning-2
In reply to this post by 강진오
The comment says: "If they are not these values (accounting for precision of printing)..."

So it looks like the writer of the comment was allowing for just what occurred for you, the precision to which the numbers was printed having changed. It looks like there was a change made to Float>>absPrintOn:base:
in 2010 (well after the Random test was written) that may have led to this difference.

Cheers,
Bob

On 3/3/12 3:43 AM, 강진오 wrote:
Hello.
I have a question.
I tested Random class>>theItsCompletelyBrokenTest to test my system.
The comment of the method says that my system would be horrible if the result is not these values:
#(0.149243269650845 0.331633021743797 0.75619644800024 0.393701540023881 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512 0.696074432551896 0.922987899707159)
 
but my result was more precious:
#(0.1492432696508445 0.331633021743797 0.756196448000239 0.3937015400238808 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512 0.696074432551895 0.922987899707159)
 
Is it because my system has errors or the comment is obsolete or incorrect?



    


Reply | Threaded
Open this post in threaded view
|

Re: Horrible problem?

Nicolas Cellier
Le 3 mars 2012 12:02, Bob Arning <[hidden email]> a écrit :

> The comment says: "If they are not these values (accounting for precision of
> printing)..."
>
> So it looks like the writer of the comment was allowing for just what
> occurred for you, the precision to which the numbers was printed having
> changed. It looks like there was a change made to Float>>absPrintOn:base: in
> 2010 (well after the Random test was written) that may have led to this
> difference.
>
> Cheers,
> Bob
>

No, I don't think the 2010 edition did change printing.
The printing changed in 1998 when the scheme method for printing a
Float accurately was introduced in Squeak.

Now, the absPrintOn:base: still is inexact.
That means I have this test failure:

| a b |
a := Float pi.
b := a predecessor.
self assert: a ~= b ==> [a printString ~= b printString].

Two different Float can have same printString representation.
Consequently, of course you can't reconstruct a Float from its
printString representation.

| a b |
a := Float pi.
b := a predecessor.
self assert: (Float readFromString: b printString) = b.

To correct these bad properties, I proposed to use
absPrintExactlyOn:base: and there is a mcz in the inbox to that aim.
Until then, never ever base such tests on printString representation.
Currently storeString prints a Float "exactly"

Float pi predecessor printString '3.141592653589793'
Float pi predecessor storeString '3.1415926535897927'

Also note that "exactly" is a misnomer.
absPrintExactlyOn:base: prints the SHORTEST decimal form that would be
converted back to the same Float, not the EXACT one.

Since a Float internal representation is a Fraction with a power of 2
at denominator, it can be printed exactly in base 10 (or any other
even basis) with a finite number of digits.
So the EXACT representation is

Float pi predecessor asFraction asScaledDecimal
 3.141592653589792671908753618481568992137908935546875s51

Of course it's rather a good thing to print the shortest form:

0.1 storeString
->'0.1'

0.1 asFraction asScaledDecimal
-> 0.1000000000000000055511151231257827021181583404541015625s55

Nicolas

>
> On 3/3/12 3:43 AM, 강진오 wrote:
>
> Hello.
> I have a question.
> I tested Random class>>theItsCompletelyBrokenTest to test my system.
> The comment of the method says that my system would be horrible if the
> result is not these values:
> #(0.149243269650845 0.331633021743797 0.75619644800024 0.393701540023881
> 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512
> 0.696074432551896 0.922987899707159)
>
> but my result was more precious:
> #(0.1492432696508445 0.331633021743797 0.756196448000239 0.3937015400238808
> 0.941783181364547 0.549929193942775 0.659962596213428 0.991354559078512
> 0.696074432551895 0.922987899707159)
>
> Is it because my system has errors or the comment is obsolete or incorrect?
>
>
>
>
>