Float equality? (was: [BUG] Float NaN's)

Lex Spoon lex at cc.gatech.edu
Fri Sep 17 19:39:47 UTC 2004


"Richard A. O'Keefe" <ok at cs.otago.ac.nz> wrote:
> Many financial calculations *MAY* be done safely using floating point.

Yes, but of course you need to count in cents, shillings, ore, or
whatnot, which defeats the purpose most people have of using floating
point to begin with: to get free support for things after the decimal
point.

So, I think you would agree that people doing financial calculations
should still default to using integers, even if their language has
floating point numbers just begging to be used.  Such people *can* use
floating point, but it is unlikely to help them, and it has gotchas
involved.



> As I said before, there are more than a few calculations where
> the use of floating point will give the auditors and lawyers nothing
> to complain of.  Their concern is that you should keep accurate records
> of *actual* sums of money which have passed through your hands.  However,
> projections, forecasts, statistical analyses, data mining, all that kind
> of stuff may legitimately use approximations.

Heheh, reminds me of my favorite exception to the rule "just don't use
floating point": graphics.  The generalization is: "if you don't really
care what the answer comes out to, then floating point is fine."



Stephan Rudlof <sr at evolgo.de> wrote:
> > My choice, if I was given one, would be to get rid of floating point
> > entirely and replace it with some form of unlimited-precision scaled
> > decimal.
> 
> In which precision (10, 100 or ? digits) would you represent e.g. pi?
> And what about sqrt(2)? Symbolic maths?

I would pick 10 digits or so as the default.  Then, newbies who are just
screwing around will get what they expect.  People who want IEEE
floating-point should have to do something a little different.

"Float pi" is a disturbing example at first: should it return
pi-for-newbies or pi-as-float ?  (Assuming, of course, that a symbolic
pi-as-pi is not available.....)  But it's not so bad on second thought,
because you give them the "pi" corresponding to whatever comes on the
left.  If Float's are 10-digit ScaledDecimal by default, then [Float pi]
should give you 10 decimal digits of precision, while [IEEEFloat pi]
should give you the binary floating-point version.  No problem--the
message-sending formulation has automatically led us to the solution.


"Jarvis, Robert P. (Bob) (Contingent)" <bob.jarvis at timken.com> wrote:
> Thank you!  Great paper.  Google found several references, including
> 
> 	http://docs.sun.com/source/806-3568/ncg_goldberg.html
	
It is cool, and I'm reading it, but at a glance it leaves out the most
important material: what a *programmer* should know about floating
point.  For example, when should you use it?  And what gotchas are
there?  This paper is mostly for systems people, and so there is room
for another short guiding paper for the larger number of people who
write programs.  Remember, everyone, it is still legal to practice
floating point without a license.

-Lex



More information about the Squeak-dev mailing list