<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Book Antiqua";
panose-1:2 4 6 2 5 3 5 3 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Book Antiqua",serif;
color:#943634;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-IE link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>Sorry for being out of synch (its Saturday and after 10pm in Ireland), I was replying (verbosely) to an earlier message in this thread when these replies arrive (USA is awake and alive); but in response to the comment below, I agree 100% with Richard’s observation that this is a problem. But what is really needed is that we need to teach programmers to use ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><cmath></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ and not ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><math.h></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ in their C++ programs, and the ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>std::</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ names not the ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>::</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ names, not that we make ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><math.h></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ more cuddly - it’s the programmer’s problem if they are not writing their code properly, not the compiler or its libraries.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>If anything, this is a programmer pattern aberration that the static analysers should look for and diagnose (perhaps they do already?). And with this moving closer to becoming a standard part of the LLVM/CLang offering, I think that it would be a good place to put such precision and performances concerns. <o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>From a performance perspective (which the Standard does not speak of), overloading means that the implementation can choose the most optimal algorithm suited to the data type - this is WHY I love C++ - and it also why the committee chose to overload the C Standard names, though within its own namespace so as not to interfere with the understood and expected semantics of C programmers. Every time I have won-over a C programmer to doing things the C++ way, it is because I have been able to demonstrate a performance advantage to doing so. Using ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>std::fabs</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ etc. after including ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><cmath></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ versus including ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><math.h></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ proves this to them; but from the perspective of semantics, I do not think that it was ever the intent of the C++ Standards committee to alter the semantic meaning of naively using C headers in a C++ program, even if that meant they suffered silent problems such as precision. It was intended that such programs would do exactly what they would have done in C. If they adapt their program to use C++ properly, these things don’t’ happen and they can reap the advantages of adapting their code to being C++ and not C. Bjarne Stroustrup famously stated a very long time ago “C++, as close to C as possible, but no closer”.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>The headers ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><iostream></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><cstdio></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ and ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'><stdio.h></span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ really show how the committee tried very hard to maintain semantic compatibility between C and C++, right down to details such as “tied streams” and automatic flushing of ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>stdout</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ (implied, not stated). This was hard to word, but for the most part the committee got it right.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>Another example is ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>isnan</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’. It is not even semantically valid to attempt to convert a ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>float</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ NaN to a ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>double</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ NaN in order to call ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>bool isnan(double)</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, hence the use of implementation defined MACROS (ugh) in C and overloaded functions in C++.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>And Richard, you are absolutely right - that is “what the words” in the Standard say, but I genuinely believe that this is a bug in the Standard and not its intent. We need to temper the implementations with the intent, and get the Standard (C++’17) to fix the words.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>Please ignore ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>__fp16</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, it is not really relevant since it is not a Standard data type, though I would love to see ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>short float</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ someday, and have it incorporated as a first class citizen into the rules for “Usual Arithmetic Conversions”, “Standard Conversions” and “Overloading”. It’s not there yet, but it’s importance is growing. I would have liked to have used ‘</span><span style='font-family:"Courier New",serif;color:black;mso-fareast-language:EN-US'>int</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ in my example, but the bug in the new headers did not make this ambiguous, it just quietly chose a different function.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'> MartinO<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'> metafoo@gmail.com [mailto:metafoo@gmail.com] <b>On Behalf Of </b>Richard Smith<br><b>Sent:</b> 23 January 2016 21:23<br><b>To:</b> Howard Hinnant <howard.hinnant@gmail.com><br><b>Cc:</b> Martin J. O'Riordan <Martin.ORiordan@movidius.com>; Marshall Clow <mclow.lists@gmail.com>; Clang Dev <cfe-dev@lists.llvm.org>; Eric Fiselier <eric@efcs.ca><br><b>Subject:</b> Re: [cfe-dev] LibC++ v3.8 - Problems with ISO C wrapper headers<o:p></o:p></span></p><p>We have evidence from the field that the lack of overloads of ::fabs causes (usually hard to detect precision loss) bugs. This thread concerns a nonstandard extension that I would imagine is only used by a small minority of libc++ users, and we can handle it by supporting that extension directly in libc++. (Doing so would fix a couple of other issues: wrong return type, no support for __fp16 in std::fabs.)<o:p></o:p></p></div></body></html>