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 :(


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

In reply to Re^2: [OT] C++ mystery. by BrowserUk
in thread [OT] C++ mystery. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.