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.

When Double Precision Is Not Enough

147 pointsby leonryabout 3 years ago

18 comments

vlmutoloabout 3 years ago
An interesting tool to help preserve floating point precision is Herbie (<a href="https:&#x2F;&#x2F;herbie.uwplse.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;herbie.uwplse.org&#x2F;</a>), which takes an expression as input and outputs an optimized version of it that will retain precision.<p>The example they give on their site is:<p><pre><code> sqrt(x+1) - sqrt(x) =&gt; 1&#x2F;(sqrt(x+1) + sqrt(x))</code></pre>
评论 #30737320 未加载
评论 #30736984 未加载
评论 #30740331 未加载
评论 #30736874 未加载
评论 #30743224 未加载
jandrewrogersabout 3 years ago
There are a few edge cases in geospatial computational geometry that require greater than quad precision to correctly compute a double precision result. This fact is sometimes used as a litmus test for implementation correctness. Many implementations don&#x27;t have a conditional escape for these edge cases that switches to arbitrary precision algorithms in their double precision algorithms, which is easy to verify.
评论 #30737044 未加载
评论 #30737809 未加载
评论 #30738952 未加载
评论 #30743253 未加载
评论 #30736966 未加载
vHMtsdfabout 3 years ago
I remember a class I had where we were shown a methods for exact PC arithmetic with integers, rationals (e.g., 1&#x2F;2) and algebraic numbers (e.g., sqrt(2)). Only thing it couldn&#x27;t deal with were transcendental numbers (e.g., pi)<p>I think it worked by representing the numbers by integer matrices, all operations were then matrix operations. Unfortunately, the matrices were gaining dimension when new algebraic numbers got involved, so it probably wasn&#x27;t useful for anything :-).<p>Anyway, it it blew me away anyway at the time, one of the few things that sticked with me from school.
评论 #30737301 未加载
willis936about 3 years ago
If anyone ever runs out of precision using IIR filters: convert to second-order section (SOS). I stumbled upon this trick a few years ago and it&#x27;s a game changer. No need for FIR.
评论 #30739374 未加载
评论 #30739794 未加载
mizzaoabout 3 years ago
Came here expecting an article about Kahan summation, left having learned about a multiple-precision Python library...
dekhnabout 3 years ago
IIUC most people instead precondition their matrices and stick to double precision instead of quad or deep precision.
评论 #30736437 未加载
magicalhippoabout 3 years ago
This reminded me of Posits[1] and Unums[2]. I dabbled with my own implementation some years ago, but nothing serious.<p>Anyone tried them out? I see there&#x27;s some FPGA implementations and a RISC-V extension idea[3], would be fun to try it on a softcore.<p>[1]: <a href="https:&#x2F;&#x2F;posithub.org&#x2F;docs&#x2F;posit_standard.pdf" rel="nofollow">https:&#x2F;&#x2F;posithub.org&#x2F;docs&#x2F;posit_standard.pdf</a><p>[2]: <a href="http:&#x2F;&#x2F;johngustafson.net&#x2F;unums.html" rel="nofollow">http:&#x2F;&#x2F;johngustafson.net&#x2F;unums.html</a><p>[3]: <a href="https:&#x2F;&#x2F;www.posithub.org&#x2F;khub_doc" rel="nofollow">https:&#x2F;&#x2F;www.posithub.org&#x2F;khub_doc</a>
评论 #30738124 未加载
评论 #30737347 未加载
frozenportabout 3 years ago
&gt;&gt; Numerically stable algorithms exist for such problems, but these occasionally fail leaving us to brute force the calculation with higher precision to minimize floating point rounding errors.<p>Do algorithm authors really implement two code paths?<p>One that uses a cost function iterative algorithm to solve the matrix (this is what everybody does), and a second algorithm using the brute force approach the author showed (known not to work).
评论 #30737814 未加载
kkylinabout 3 years ago
First thought: the curve in that first plot reflects the pseudospectrum? (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pseudospectrum" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pseudospectrum</a>) Spectra of nonnormal matrices can be very hard to calculate accurately.
peter303about 3 years ago
The are algorithms taught in numerical analysis class for re-ordering calculations to maximize precision. Computing in order you wrote on paper or the way you were initially taught may not be the best.
bluetwoabout 3 years ago
I&#x27;ll admit being lost in some of the math here but I wonder perhaps naively, if a language like Julia, which does fractions as fractions, would handle it better.
评论 #30738190 未加载
midjjiabout 3 years ago
Thankfully someone figured out that quad should be in C++ a while back, unfortunately they didnt figure out that the next few dozen should be too... the arbitrary precision stuff is an alternative in theory, and would be if any of the hundreds of half completed projects to convert unintelligeble, and unmaintainable, unclear, etc, C to the in this specific case extremely much better C++ interfaces was complete.
layer8about 3 years ago
There is a whole field about that, called numerical analysis: <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Numerical_analysis" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Numerical_analysis</a>
charlieyu1about 3 years ago
Sounds like bad algorithm.
ogogmadabout 3 years ago
Obligatory reference to computable analysis: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Computable_analysis" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Computable_analysis</a><p>This shows that you <i>can</i> do exact real arithmetic without worrying about round-off errors. But it&#x27;s expensive.<p>If you want something more practical (but dodgy), you can use arbitrary-precision arithmetic instead of exact real arithmetic. To that end, there&#x27;s the Decimal module in the Python standard lib. There&#x27;s also the BC programming language which is part of POSIX. If you want to do matrix arithmetic, you can use mpmath for Python like they did in this blog post, or Eigen3 for C++ with an arbitrary-precision type. This is dodgy of course because the arithmetic remains inexact, albeit with smaller rounding errors than double-precision floats.
a-dubabout 3 years ago
also worth noting that you can ask the fpu to trap to catch some types of precision loss or fp underflows.
评论 #30737590 未加载
akimballabout 3 years ago
Rational arithmetic needs better matrix libraries. No loss of precision then.
评论 #30737048 未加载
评论 #30737055 未加载
mistrial9about 3 years ago
use 80 bits? <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Standard_Apple_Numerics_Environment" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Standard_Apple_Numerics_Enviro...</a>
评论 #30737395 未加载
评论 #30736932 未加载
评论 #30737004 未加载