[Cfp-interest 3146] thoughts on linear interpolations
David Hough CFP
pcfp at oakapple.net
Thu Jul 18 13:37:00 PDT 2024
Following
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0811r3.html
the problem is to compute, correctly rounded
(1-t)*a + t*b OR a + t*(b-a)
if t is in [0.5,2]
then 1-t is exact ; compute (1-t)*a + t*b as 2 dprods and an addtosingle
a + t * (b-a)
if a/b is in [0.5,2] (determined conservatively as same signs,
exponents differ by 0 or 1)
then b-a is exact ; compute a + t * (b-a) as 2 dprods and addtosingle
otherwise triple addition of a - t*a + t*b - as 2 dprods and add3tosingle
To be clear, dprod(x,y) returns x*y in a precision higher enough to always hold that product exactly, probably double precision
addtosingle(x,y) for x and y in that higher precision, returns x+y rounded once
to the original precision of a and b
add3tosingle(x,y,z) for x, y, and z in that higher precision, returns their
sum rounded once to the original precision. That's a tall order for the
hardware department and resistance is to be expected.
And all the
conditionals impede performance, even with the hardware suppport.
It's hard to imagine
an application that could make use of a very slow correctly-rounded software
implementation.
So from my point of view, that argues against standardization in general
purpose languages. A language could specify an algorithm rather than
explicit properties of results, with the risk that somebody cleverer might
come up later with an algorithm that is faster and more correct.
More information about the Cfp-interest
mailing list