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 :(
In reply to Re^2: [OT] C++ mystery.
by BrowserUk
in thread [OT] C++ mystery.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |