in reply to Re: [OT] C++ mystery.
in thread [OT] C++ mystery.
It looks like it's just ensuring that the return value is coerced into a double
But every variable in the entire subroutine is already a double?
I don't know anything about doubledouble, so perhaps it's using an extended floating point type (like long double)?
No. The doubledouble class provides greater precision by using pairs of doubles (hi & lo) to hold different parts of the higher precision value.
This routine adds two doubledoubles together, by extracting any 'carry' from the lo+lo and adding it into the hi+hi calculation.
I'm beginning (after reading a dozen or so papers and banging my head till it hurts) to understand how it achieves that; but the one bit that has me baffled is:
why does it need to cast the subtraction of one double from another double; to a double, before adding it to another double?
That; along with a couple of the other calculations don't appear to make any difference to the outcome no matter what values I've tried.
Normally, I might just conclude they were artifacts of time; or minor over-engineering; but the routine is attributed (copyrighted) by W. Kahan
And is (apparently) an implementation of the Kahan summation algorithm.
So, I'm loathed to simplify; but I'm bugged that I cannot find any reason why they are there :(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [OT] C++ mystery.
by Anonymous Monk on Jun 19, 2015 at 19:48 UTC | |
by BrowserUk (Patriarch) on Jun 19, 2015 at 20:35 UTC | |
by bitingduck (Deacon) on Jun 20, 2015 at 00:46 UTC | |
by BrowserUk (Patriarch) on Jun 20, 2015 at 01:15 UTC | |
by bitingduck (Deacon) on Jun 20, 2015 at 03:39 UTC | |
by BrowserUk (Patriarch) on Jun 20, 2015 at 13:45 UTC |