TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How Java’s Floating-Point Hurts Everyone Everywhere (1998) [pdf]

57 pointsby llambdaover 11 years ago

10 comments

pcwaltonover 11 years ago
This is a rant we came across in the early design of Rust and eventually decided was pretty misguided. Very few languages actually address these complaints.<p>The biggest complaint here is that, in Java, when you perform arithmetic on 32-bit floats you perform 32-bit arithmetic with 32-bit intermediate results. Java&#x27;s behavior is, in other words, what you&#x27;d expect. In C, though, if you perform arithmetic on 32-bit floats you&#x27;re actually performing 64-bit arithmetic on 64-bit intermediate results (at least most of the time; it&#x27;s been a while since I consulted the rules). Java&#x27;s behavior (which basically amounts to doing what you asked to do) infuriated the author, so he gave a bunch of examples of scientific calculations that need 64 bits of precision. But that&#x27;s totally unconvincing to me: if you want 64-bit floating point precision, use doubles. C&#x27;s implicit conversions in general have caused more harm than good and what the author is complaining about is having to tell the compiler to do 64-bit arithmetic on 32-bit values instead of having it follow complex promotion rules that few programmers even know about.
评论 #6587053 未加载
评论 #6586741 未加载
评论 #6586738 未加载
评论 #6586696 未加载
评论 #6587173 未加载
评论 #6589686 未加载
unwindover 11 years ago
This was just tweeted by John Carmack (<a href="https://twitter.com/ID_AA_Carmack/status/392298557631254528" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;ID_AA_Carmack&#x2F;status&#x2F;392298557631254528</a>) which is probably why it was submitted.<p>It&#x27;s pretty old, it should have a [1998] tag in the title in my opinion.<p>It&#x27;s also pretty funny. :)
评论 #6586164 未加载
betterunixover 11 years ago
If 95% of programmers have misconceptions about floating point arithmetic, <i>we should stop using it as the default rational &#x2F; real number type</i>. Floating point is a great optimization, but in a lot of situations it would be a lot better to have arbitrary-precision rational number types, continued fractions representations, or something else that better approximates what programmers expect.
评论 #6587397 未加载
dekhnover 11 years ago
I dunno, given what Javascript foisted on a generation of programmers, we should be thankful Java is only as bad as it is.<p>Go Kahan!
acjohnson55over 11 years ago
I browsed to page 10, but didn&#x27;t learn what the big problem was, and then gave up.
评论 #6586185 未加载
japagetover 11 years ago
What I found most interesting about the article was some of the mathematical techniques presented. See page 44 for an accurate formula for angular distances and page 48 ff. for an alternative formalism for the vector cross product.
saejoxover 11 years ago
Cyrix. That&#x27;s a word i didn&#x27;t hear in at least a decade.
Aardwolfover 11 years ago
Fully agree on the operator overloading complaint. It really is a LOT easier when working with matrices, vectors and scalars to be able to type their math expressions naturally rather than with functions like add(multiply(.....))
评论 #6588033 未加载
PaulHouleover 11 years ago
Many of the problems they point out aren&#x27;t just Java problems, they&#x27;re FORTRAN problems too.
peterashfordover 11 years ago
Another &quot;everything Java does is evil&quot; rant. No wonder HN is all over it. This is tiresome.<p>If you want 64 bit precision - use doubles. That&#x27;s not hard, is it?