Float Question

R. A. Harmon harmonra at webname.com
Fri Feb 5 21:34:31 UTC 1999

At 10:54 AM 2/4/99 -0600, you wrote:
>>I got most of the Float representation figured out but the following still
>>puzzles me as something special seems to be going on with small floats:
>>            testPrintOn:  Sign    Exponent bits               Mantissa bits
>>    ---     ------------  ----    --------------------------  -------------
>>    2.0     2e1           +       1 (16r400 2r10000000000)    16r0
>>    4.0     4e1           +       2 (16r401 2r10000000001)    16r0
>>    8.0     8e1           +       3 (16r402 2r10000000010)    16r0

Oops!  I thought there was some special value coded in the Exponent bits
because I was looking only at the hexadecimal and binary values.  I should
have noticed that the decimal integer just to the left that indicates it's
regular old Float representation.

>>    (1 - (self radix raisedTo: self precision negated))
>>        * (self radix raisedTo: self emax)                <- added parens
>>I never fully understood how this calculation worked.  I think it produces
>>the maximum fraction multiplied by the maximum exponent.  How it produces
>>the maximum fraction has me stumped.
>Yes, this is what it does (or attempts to do, anyway): "raisedTo:" is 
>somewhat imprecise, and the final result is off by a few bits.

I think I stumbled across this while looking at intermediate values when I
was trying to understand what it was doing.

>Also, looking at the calculation more closely, it's not designed very well.  
>(2.0 raisedToInteger: 1024) produces Infinity which ruins the rest of the 
>calculation.  I think the best way to do this would be:
>(2.0 - (self radix raisedToInteger: (self precision - 1) negated))
>     * (self radix raisedToInteger: self emax)
>[where emax == 1023, not 1024]
>This calculation is "overflow proof", and returns the correct value, down 
>to the lsb.  It works by multiplying the largest significand (1.99999...) 
>by the largest exponent (2 raisedToInteger: 1023).

You might ought to do like Allen Wirfs-Brock suggested in response to my
ANSI question on c.l.s:

        "While I think this is a great forum for implementors to discuss
         issues related to the ANSI Smalltalk standard I also recommend
        that issues like this be brought to the direct attention of the
        J20 (ANSI Smalltalk) committee so that they might be clarified in
        a future revision of the standard.

        I believe that a mailing list is still maintained at  x3j20 at qks.com.
        Alternatively, you could direct issues to Glenn Krasner, the current
        J20 chair at krasner at objectshare.com."

I'm going to send in a couple of problems I found with the proposed ANSI
standard doc. (a specified invariant that doesn't hold, etc.) just as soon
as I figure out how to subscribe to the list (keep getting qks.com server
down) or to the chair if I get tired of messing with the list.

I don't feel qualified to send in the safer calculation above.

>>I thought it might be a good idea to include the following description of
>>Float representation under an "Implementation" heading in the Float class
>>comment.  Let me know if you disagree, or have suggestions to improve to
>>format, or any other comments.
>I think that simply specifying that the representation complies with 
>IEEE-754 is sufficient: people who are interested in the implementation 
>details likely know about 754 anyway (which is documented in many places 
>on the web), and if all the details are listed, someone might think that 
>it is done so because there is some sort of difference between that and 

Good point about the possible confusion.

How about adding a note that this is a simplified overview and that one
ought look up the full 754 and comments about it for a full description?

I'm concerned about the person who doesn't have access to the web.  I didn't
until a year ago, and may not be able to afford it in the future.

Also it's a real pain in the butt if you have dial up access to get
connected and go rooting around the web just for a short answer.

I don't want to include all the three gazillion web pages in a Squeak ReadMe
or .doc file, or load them into the image as part of class comments, but
maybe a bit more than the current comment might be a happier medium?

Not a good point:

        "people who are interested in the implementation details
        likely know about 754 anyway"

You should maybe add a parenthetical note: 

        "people (other than those boneheads that try to add ANSI float stuff)
         who are . . . ."

Thanks for help.

Richard A. Harmon          "The only good zombie is a dead zombie"
harmonra at webname.com           E. G. McCarthy

More information about the Squeak-dev mailing list